🔒 Locked
Shaders
Advertisement
Original Post
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!
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.
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.
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.
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.
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.
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.
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?
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?
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.,
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.,
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.
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]
Quote:
Original post by superpig
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]
Its not a reference to that. Most hardware (perhaps all) renders 2x2 grids of pixels to compute the gradient calculations for mipmapping. For almost all triangles, this means there are pixels adjacent to the triangle boundary which need to be processed for gradients (using interpolated coordinates which are outside of the triangle domain), but are thrown away. This is why flow control with gradients inside must be so restricted (neihboring pixels can't take different branches)
Of course, this is an implementation detail of the hardware. You can abstract this away to thinking of it as running on every pixel.
Quote:
Original post by Pipo DeClown
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.
This just means that their is a unified shader model - e.g. all shaders shader the same instruction set, which exception to gradient calculations which don't have any meaning in vertex shaders.
There will still be pixel shaders and vertex shaders (and perhaps other shaders ;)) in the future.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement