Changes

Jump to: navigation, search

Howto:Shader programming in FlightGear

798 bytes added, 16:41, 27 March 2010
m
Vertex Shaders
Note: Loading a vertex shader turns off parts of the OpenGL pipeline (vertex shaders fully replace the "Texturing & Lighting unit")
 
Objects in a computer graphics scene are usually meshes that are made up of polygons. The corner of each of those polygons is called a "vertex".
A vertex shader receives input in the form of per-vertex variables called "attribute variables", and per-polygon variables called "uniform variables".
The vertex shader must specify the coordinates of the vertex in question. This way, the geometry of the object can be modified.
Vertex shaders operate on each vertex, the vertex shader is executed for every vertex related OpenGL call (e.g. glVertex* or glDrawArrays).
* gl_Position is an special output variable for the transformed vertex coordinate
A vertex shader can also set other variables which are called "varying variables".
The values of these variables are passed on to the second kind of shader, the "fragment shader".
The fragment shader is run for every pixel on the screen where the polygons of the mesh appear.The fragment shader is responsible for setting the final color of that little piece of the mesh
Common tasks for a vertex shader include:
 
* Vertex position transformation
* Per vertex lighting
The vertex shader runs from start to end for each and every vertex that's passed into the graphics card - the fragment process does the same thing at the pixel level. In most scenes there are a heck of a lot more pixel fragments than there are vertices - so the performance of the fragment shader is vastly more important and any work we can do in the vertex shader, we probably should.
A minum vertex shader example may look like looks this:
void main(void)
2,561
edits

Navigation menu