Jump to content
  • Advertisement
Sign in to follow this  
AndreTheGiant

Shaders

This topic is 5449 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I think I have a vague idea of what shaders are, but I'm reading a book on them that is starting to seem slightly over my head. I think it would help a lot if someone could clarify the difference between these shaders that the book mentions: shader pixel shader vertex shader fragment shader In particular, Im really confused about the difference between vertex and fragment shader. Also, assuming thse are different things, does one happen before the others? Or does the order depend on what you are trying to do? Also, I dont know if this is related to the shaders above, but I read something about Doom3 using 'sound shaders'. Is that something completely different or what? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
pixel shader == fragment shader. The term "fragment shader" is slightly more correct, since with antialiasing the shader may run several times per pixel.

vertex shader: produces information about a particular vertex. Executed once for each vertex in the scene. In the fixed-function pipeline, outputs the color for that vertex (to be interpolated with the other vertices across the triangle that the vertex is part of).

fragment shader: executed once per each pixel/fragment in each triangle. The interpolated information from the vertices around that pixel/fragment is passed into the shader.

Share this post


Link to post
Share on other sites
ok so the vertex shader happens before the fragment shader? Do they both always happen, or can just one happen?

What kind of things do you do in the vertex shader?
What kind of things do you do in the fragment shader?

It seems from your description that they both have to do with determining what color things should be.

Share this post


Link to post
Share on other sites
vertex shader: Can perform operations on the actual vertices passed to the rendering pipeline. A simple vertex shader can mimic the fixed function pipeline by applying view and projection matrices, etc... Other operations can be performed on the vertices; various parameters can be given to the vertex shader to modify the passed vertices. The shader can only modify those vertex-assignable attributes: (x,y,z,w,u,v,diffuse color, vertex normal) and so forth. A common trick is to pass a 'matrix palette' representing a skeleton for skinned meshes, and to transform each given vertex based on a secondary 'bone index' parameter which indicates which bone in the skeleton transforms that vertex. The matrix palette is simply a list of matrices that are applied in conjunction with the view and projection matrices before the vertex is output. Other effects include generation of (u,v) texture coordinates based on some function/criteria/parameters. Or you can perform vertex tweening, by passing two sets of (x,y,z) coords for each vertex in the mesh, representing previous and next animation keyframes, and an additional (t) parameter in the range of [0,1], which is used to interpolate between the two. There are all sorts of things you can do with these shaders.

pixel shader: Performs additional, per-pixel operations. For instance, per-pixel lighting. With just a vertex shader, you can calculate lighting values for each vertex in the mesh, which can be smooth-shaded across the entire polygon, but per-pixel level of lighting is not possible since a vertex shader can not touch individual pixels. With a pixel shader, you can perform a lighting calculation for each pixel, thus allowing for cool effects such as Phong shading for specular highlights, normal-mapping, and so forth.

Vertex data is fed first to the vertex shader; vertex shader output is sent to the fragment shader, which is performed for each and every pixel that the passed geometry defines. For instance, when 3 verts of a triangle are received, the fixed-function fragment renderer simply takes transformed on-screen locations, diffuse color, and texture data and draws a triangle. Each pixel's color is calculated based on the standard sets of rules (diffuse color, alpha blending, texture texels, etc...) and rendered. With a programmable shader, it iterates through all the pixels that are drawn and custom, programmable operations can be performed instead of the standard pipeline functions.

Share this post


Link to post
Share on other sites
Ok thanks guys that answeres most of my questions.

One final clarification: VertexNormal, you used both the term pixel shader and fragment shader. Do you agree with Sneftel that they are the same thing, or were you talking about 2 different types of shader?

Share this post


Link to post
Share on other sites
As far as I'm aware:

Pixel Shader is the DirectX term.
Fragment Shader is the OpenGL term.

The term shader is being applied to pretty much any piece of data (including code) that modifies another bit of data, normally for some sort of aesethic improvement.

Doom 3's sound shaders will presumably (I'm not privy to iD's source code) define how Doom3's sound code modifies
sound potentially adding damping, reverb, pitch shifting etc.,

Share this post


Link to post
Share on other sites
Don't worry about it too much, since at some time (Windows Longhorn release?), both shadertypes (vertex & pixel/fragment) will be combined into one supershader.

Share this post


Link to post
Share on other sites
The terminology problem comes from things like multisampling/supersampling, where one 'sample point' (aka 'fragment') is not the same thing as one pixel.

So you can call it a pixel shader if you never use those techniques [grin]

Share this post


Link to post
Share on other sites
Quote:
Original post by AndreTheGiant
Ok thanks guys that answeres most of my questions.

One final clarification: VertexNormal, you used both the term pixel shader and fragment shader. Do you agree with Sneftel that they are the same thing, or were you talking about 2 different types of shader?


Yeah, they're the same thing. Or, in other words, what superpig said. [grin]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!