Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, TedMar), 1,031 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Good first few shaders? #42670
03/15/05 12:58
03/15/05 12:58
Joined: Jul 2001
Posts: 1,269
Hopewell Jct, NY
Yulor Offline OP
Senior Developer
Yulor  Offline OP
Senior Developer

Joined: Jul 2001
Posts: 1,269
Hopewell Jct, NY
What would be a few good shaders to try and make at first?
I want to get into shader development.

Re: Good first few shaders? [Re: Yulor] #42671
03/15/05 14:07
03/15/05 14:07
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
The easiest shader to make is something that just does normal textureing. Just write a vertex shader that calculates the vertex position and texture coords, and a pixel shader that simply textures the pixel. This is a pretty useless shader, but once you can get a working shader you can then move on to make things that do something useful. The point is to understand the way shaders work, and how vertex and pixel shaders work together.. very rarely is one used without the other- often the vertex shader drives the pixel shader, because it's much faster to do many calculations per-vertex, rather than per-pixel, and also the vertex knows certain things that the pixel shader can not know unless it is passed to it.

Also decide if you want to learn assembly or start right into HLSL. I would suggest that unless you want to really get into the nitty-gritty to avoid assembly because its difficult to work with(i happen to like asembly, but HLSL is much clearer and flexible)

If you understand all that im saying here, then you can move on to doing more interesting things. First try to doing some sort of multitexturing, like detail mapping. Simply blend the color texture with a detail texture by multiplying the samplers together. Then you can go on to more complex things.

I'd recommend trying to work out vertex lighting, as shown in the WIKI terrain multitextureing shader. Then move on to per-pixel lighting and normal mapping.
But remember with more complex shaders the math theory is what drives the shader.

Re: Good first few shaders? [Re: Matt_Aufderheide] #42672
03/16/05 08:30
03/16/05 08:30
Joined: Sep 2003
Posts: 3,236
San Diego, CA
M
Marco_Grubert Offline
Expert
Marco_Grubert  Offline
Expert
M

Joined: Sep 2003
Posts: 3,236
San Diego, CA
Wolfgang Engel's "Pixel & Vertexshader" book looks quite nice and it has samples in it.

Re: Good first few shaders? [Re: Marco_Grubert] #42673
03/16/05 09:51
03/16/05 09:51
Joined: Jul 2001
Posts: 1,269
Hopewell Jct, NY
Yulor Offline OP
Senior Developer
Yulor  Offline OP
Senior Developer

Joined: Jul 2001
Posts: 1,269
Hopewell Jct, NY
Quote:


Wolfgang Engel's "Pixel & Vertexshader" book looks quite nice and it has samples in it.




I own both the ShaderX^2 books...

Quote:


If you understand all that im saying here, then you can move on to doing more interesting things. First try to doing some sort of multitexturing, like detail mapping. Simply blend the color texture with a detail texture by multiplying the samplers together. Then you can go on to more complex things.





See this is what really keeps me back on shaders, what is a 'detail map' exactly, and what are the 'samplers?'

If all the people in these books didn't just assume I already know how to code shaders, then I may just learn something from them..

Re: Good first few shaders? [Re: Yulor] #42674
03/16/05 10:54
03/16/05 10:54
Joined: Sep 2003
Posts: 3,236
San Diego, CA
M
Marco_Grubert Offline
Expert
Marco_Grubert  Offline
Expert
M

Joined: Sep 2003
Posts: 3,236
San Diego, CA
Quote:

If all the people in these books didn't just assume I already know how to code shaders, then I may just learn something from them..


That's why I recommended the other book. It also has a glossary in the back. Shader X2/3 is for advanced shader programmers.

detail map: texture to be added or multiplied with base olor texture. Often scaled down so that multiple detail texels are combined with one color texel.

Re: Good first few shaders? [Re: Yulor] #42675
03/16/05 11:58
03/16/05 11:58
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
Quote:

See this is what really keeps me back on shaders, what is a 'detail map' exactly, and what are the 'samplers?'




a sampler is a just another way to define a texture ..usually for an HLSL shader..
Bascially you should get a simple example shader-there are plenty availble on this forum- and try to understand what it does and how its structured.

here is a basic HLSL shader:

Code:

//this is the only matrix you need for this shader.. world*view*projection
float4x4 matWorldViewProj;

here is the vertex shader output
struct VS_OUTPUT
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;
};

//simple vertex shader calculates the vertex position and tex coords
VS_OUTPUT mainVS( float4 Pos : POSITION,
float2 Tex : TEXCOORD0 )
{
VS_OUTPUT Out = (VS_OUTPUT) 0;
Out.Pos = mul(Pos,matWorldViewProj );
Out.Tex = Tex;
return Out;
}

texture entSkin1;

//define the sampler for the entity skin
sampler basemap = sampler_state
{
Texture = <entSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = clamp;
AddressV = clamp;
};


// Simple pixel shader samples the entity skin according to Tex.xy coords
float4 mainPS(float2 Tex: TEXCOORD0) : COLOR {

Color = tex2D( basemap, Tex.xy);

return Color;

}

technique blur
{

pass Object
{
alphablendenable=false;
ZENABLE = TRUE;
VertexShader = compile vs_1_1 mainVS();
PixelShader = compile ps_2_0 mainPS();
}

}



the vertex shader just calculates the vertex position according to the projection matrix and passes the texture coords to the pixel shader. the pixel shader just colors the pixel depending on the texture coords and the ent skin.

This is the about the most basic a shader you can get, and will render an unshaded, textured model. But the structure is what's important here.

If you understand this shader.. then you can simply start adding other effects into it, such as a vertex lighting, and detail mapping. To do detail mapping, simply make another skin (and put into entskin2 in MED)like a greyscale texture of metal rust or something and then add anoter sampler like this:

sampler detailmap = sampler_state
{
Texture = <entSkin2>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = wrap; //you want it wrap because it will be scaled smaller
AddressV = wrap;
};

to add detail mapping coords you can either caluculate them in the vertex shader and pass a second set of tex coords, or you can just multiply the tex.xy in the pixel shader. For simplicity's sake let's do the latter:

// pixel shader that does detail mapping
float4 mainPS(float2 Tex: TEXCOORD0) : COLOR {

Color =
//sample base color
tex2D( basemap, Tex.xy) *
//multiply with the detail texture and scale the texture coords
tex2D(detailmap,(Tex.xy*5));

return Color;

}

Re: Good first few shaders? [Re: Matt_Aufderheide] #42676
03/17/05 02:05
03/17/05 02:05
Joined: Jul 2002
Posts: 5,181
Austria
Blattsalat Offline
Senior Expert
Blattsalat  Offline
Senior Expert

Joined: Jul 2002
Posts: 5,181
Austria
this is an excellent explenation how shaders work.
thanks a lot, i learned quite a few things from your post.

cheers


Models, Textures and Levels at:
http://www.blattsalat.com/
portfolio:
http://showcase.blattsalat.com/
Re: Good first few shaders? [Re: Blattsalat] #42677
03/17/05 06:47
03/17/05 06:47
Joined: Sep 2003
Posts: 3,236
San Diego, CA
M
Marco_Grubert Offline
Expert
Marco_Grubert  Offline
Expert
M

Joined: Sep 2003
Posts: 3,236
San Diego, CA
Let me copy this example into a sticky...

Re: Good first few shaders? [Re: Marco_Grubert] #42678
03/20/05 06:29
03/20/05 06:29
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline
Serious User
jumpman  Offline
Serious User

Joined: Apr 2002
Posts: 1,246
ny
I know its better to read all the books and such, but if you dont have any of the books, the example you just explained above is EXTREMELY useful if you dont have any shader knowledge. Ive learnt alot from just that example


Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1