Howto:Shader programming in FlightGear: Difference between revisions

m
Line 97: Line 97:


Note: Loading a vertex shader turns off parts of the OpenGL pipeline (vertex shaders fully replace the "Texturing & Lighting unit")
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).
Vertex shaders operate on each vertex, the vertex shader is executed for every vertex related OpenGL call (e.g. glVertex* or glDrawArrays).
Line 114: Line 118:
* gl_Position is an special output variable for the transformed vertex coordinate
* 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:
Common tasks for a vertex shader include:
* Vertex position transformation
* Vertex position transformation
* Per vertex lighting
* Per vertex lighting
Line 127: Line 135:
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.  
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 this:
A minum vertex shader example may looks this:


  void main(void)
  void main(void)
2,561

edits