7 replies to this topic

### #1rogerdv

Member

• Members
• 99 posts

Posted 22 August 2003 - 05:39 PM

Can somebody explain me what are shaders?

### #2Snape

New Member

• Members
• 19 posts

Posted 22 August 2003 - 06: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.

### #3davepermen

Senior Member

• Members
• 1306 posts

Posted 24 August 2003 - 11: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);
rastericer.push_back(finalvertex);
}


and

//rastericer:
foreach(pixel p in triangle) {
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; }
}


davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....

### #4baldurk

Senior Member

• Members
• 1057 posts

Posted 24 August 2003 - 05:19 PM

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?
baldurk
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.

### #5davepermen

Senior Member

• Members
• 1306 posts

Posted 24 August 2003 - 05:28 PM

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..)
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....

### #6baldurk

Senior Member

• Members
• 1057 posts

Posted 24 August 2003 - 06: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.
baldurk
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.

### #7Dia

DevMaster Staff

• 1120 posts

Posted 24 August 2003 - 07: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.

### #8davepermen

Senior Member

• Members
• 1306 posts

Posted 25 August 2003 - 12:22 PM

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.

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.
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users