Howto:Shader programming in FlightGear: Difference between revisions

m
Line 66: Line 66:
= Shader Types =
= Shader Types =


There are two types of shaders in GLSL: "vertex shaders" and "fragment shaders".
There are two types of shaders in GLSL: "vertex shaders" and "fragment shaders" (with geometry shaders being a part of OpenGL 3.2).
 
These are executed by vertex and fragment processors in the graphics hardware.
These are executed by vertex and fragment processors in the graphics hardware.
Typically, vertex shader files use the file extension ".vert", while fragment shader files use the ".frag" extension. In FlightGear, these files can be found in the "Shaders" subdirectory of the base package, i.e. $FG_ROOT/Shaders
 
* Vertex shaders transform vertices, set up data for fragment shaders
* Fragment shaders operate on fragments generated by rasterization
* Geometry shaders create geometry on the GPU
 
Typically, vertex shader files use the file extension ".vert", while fragment shader files use the ".frag" extension.  
In FlightGear, these files can be found in the "Shaders" subdirectory of the base package, i.e. $FG_ROOT/Shaders
 
For a list of currently available shaders, you may want to take a look at: http://cvs.flightgear.org/viewvc/data/Shaders/
For a list of currently available shaders, you may want to take a look at: http://cvs.flightgear.org/viewvc/data/Shaders/


Line 75: Line 83:
A vertex shader is run once per vertex, while a fragment shader is run once per pixel.
A vertex shader is run once per vertex, while a fragment shader is run once per pixel.
Many such executions can happen in parallel. There is no communication or ordering between
Many such executions can happen in parallel. There is no communication or ordering between
executions.
executions. Vertex shaders are flexible and quick.


Vertex shaders are flexible and quick




Line 101: Line 108:
* Vertex color computation
* Vertex color computation
* Geometry skinning
* Geometry skinning
* Animation
* Setting up data for fragment shaders


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.  
Line 124: Line 133:
Common tasks of fragment shaders include:
Common tasks of fragment shaders include:
* Texturing (even procedural)
* Texturing (even procedural)
* Per pixel lighting
* Per pixel lighting and material application
* ray tracing
* Fragment color computation
* Fragment color computation
* Operations on Interpolated Values
* Doing operations per fragment to make pretty pictures




2,561

edits