PDA

View Full Version : Shaders


rogerdv
08-22-2003, 11:39 AM
Can somebody explain me what are shaders?

Snape
08-22-2003, 12:20 PM
I'll try it:

In DirectX there are two sorts of Shaders: Vertex and Pixel Shaders. Vertex Shaders can influence everything which is connected with a single vertex, (vertex position, color, texture coordinates, etc.) Pixel Shaders can change the texel-color.
For instance you can use Vertex Shaders to calculate the LxN Vector for each vertex (lighting calculation) and with a Pixel Shader you can modulate the base texture with a bump-map.

Hope this is correct.

davepermen
08-24-2003, 05:21 AM
sounds correct.

when ever you send some vertex with glVertex(), or glDrawElements, or what ever, the vertex gets transformed, lighting with glLight get calculated, texcoords get set/generated (envmap,projected textures, etc..), etc. this part can get replaced by an own coded shader, wich takes care of the transformation, lighting, texcoord generating how ever YOU want.

then, the final generated vertices get send to the rastericer, wich then generates fragments (not exactly the same as pixels in multisampling..). those fragments have the interpolated texcoords, and colors, and that. they then get textured, and for example with multitexturing you do some math on how to combine that, etc. then, it gets drawn onto the screen (if it fits z-test, stencil-test, alpha-test, etc..). this part can get replaced by a pixelshader to make it configurable as you want, again.



in opengl terms they are called vertex and fragmentprograms for now. vertex and fragmentshaders in gl2.

think of it as like this:

glVertex(x,y,z) {
currentvertex.pos = (x,y,z);
finalvertex = vertexshader(&currentvertex);
rastericer.push_back(finalvertex);
}


and


//rastericer:
foreach(pixel p in triangle) {
finalp = pixelshader(p);
if(!ztest(finalp)) continue;
if(!stenciltest(finalp)) continue;
if(!alphatest(finalp)) continue;
if(blending) { screen[p.pos] = blend(screen[p.pos],finalp); }
else { screen[p.pos] = finalp; }
}


about that..

baldurk
08-24-2003, 11:19 AM
Aren't shaders just simple programs that take input (either the vertex or pixel data: colour of pixel, or colour, position, texture co-ord etc of the vertex). Then they perform calculations you program, then output and this is passed onto the rest of the pipeline?

davepermen
08-24-2003, 11:28 AM
a shader is just a buzzword. and yes, they replace parts of the pipeline. i explained wich part got done by a vertexshader and wich part gets done by a pixelshader.

i don't call them programs, i call them functions. why? because they replace the fixed function :D (and they really ARE just functions. they get called per vertex/pixel with some input and return an output..)

baldurk
08-24-2003, 12:55 PM
didn't MS coin the word 'shader'. It's probably just because shader sounds more impressive than program :).

If you replace one part of the pipeline, can you leave others? or do you have to replace all of T&L etc just to add a lighting effect.

Dia Kharrat
08-24-2003, 01:31 PM
I read the other day about the argument ARB members had when they wanted to name the OpenGL "vertex shader" extension. Eventually they called it: "vertex program" since a shader implies fragment level processing.

davepermen
08-25-2003, 06:22 AM
vertex and pixelshaders are individual thinks. most the time, to get a good effect, you need both at the same time, but technically, you can life with one or the other, it just depends.

vertexshaders manipulate the vertices of your object, one at a time.

pixelshaders manipulate the pixels of currently rendering triangle, one at a time.

its really not difficult to grasp.

its one of the reasons why i think everyone should at least one time in his life have coded a softwarerastericer. then he knows that all, how simple it is, how useful it is, how primitive it is.