Vertex shader vs Fragment Shader

adivasile picture adivasile · Dec 12, 2010 · Viewed 86.1k times · Source

I've read some tutorials regarding Cg, yet one thing is not quite clear to me. What exactly is the difference between vertex and fragment shaders? And for what situations is one better suited than the other?

Answer

The Surrican picture The Surrican · Dec 12, 2010

A fragment shader is the same as pixel shader.

One main difference is that a vertex shader can manipulate the attributes of vertices. which are the corner points of your polygons.

The fragment shader on the other hand takes care of how the pixels between the vertices look. They are interpolated between the defined vertices following specific rules.

For example: if you want your polygon to be completely red, you would define all vertices red. If you want for specific effects like a gradient between the vertices, you have to do that in the fragment shader.

Put another way:

The vertex shader is part of the early steps in the graphic pipeline, somewhere between model coordinate transformation and polygon clipping I think. At that point, nothing is really done yet.

However, the fragment/pixel shader is part of the rasterization step, where the image is calculated and the pixels between the vertices are filled in or "coloured".

Just read about the graphics pipeline here and everything will reveal itself: http://en.wikipedia.org/wiki/Graphics_pipeline