Shaders

9275cef0ad2f15ec1813d63b0c5b0fad
0
rogerdv 101 Aug 22, 2003 at 17:39

Can somebody explain me what are shaders?

7 Replies

Please log in or register to post a reply.

Cb77b99ef1d7823941f5e0407f1c0117
0
Snape 101 Aug 22, 2003 at 18:20

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.

6ad5f8c742f1e8ec61000e2b0900fc76
0
davepermen 101 Aug 24, 2003 at 11:21

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..

0684f9d33f52fa189aad7ac9e8c87510
0
baldurk 101 Aug 24, 2003 at 17:19

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?

6ad5f8c742f1e8ec61000e2b0900fc76
0
davepermen 101 Aug 24, 2003 at 17:28

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..)

0684f9d33f52fa189aad7ac9e8c87510
0
baldurk 101 Aug 24, 2003 at 18:55

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.

Fdbdc4176840d77fe6a8deca457595ab
0
dk 158 Aug 24, 2003 at 19:31

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.

6ad5f8c742f1e8ec61000e2b0900fc76
0
davepermen 101 Aug 25, 2003 at 12:22

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.