Howto:Shader programming in FlightGear: Difference between revisions

m
Robot: Cosmetic changes
m (olde cvs to git link)
m (Robot: Cosmetic changes)
Line 98: Line 98:
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".
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".
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.  
The vertex shader must specify the coordinates of the vertex in question. This way, the geometry of the object can be modified.  
Line 119: Line 119:


A vertex shader can also set other variables which are called "varying variables".  
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 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
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


Line 200: Line 200:


== Matrices ==
== Matrices ==
* mat2 2x2 floating point matrix
* mat2 2x2 floating point matrix
* mat3 3x3 floating point matrix
* mat3 3x3 floating point matrix
* mat4 4x4 floating potint matrix
* mat4 4x4 floating potint matrix


Line 230: Line 230:
* const - for declaring non-writable, compile-time constant variables
* const - for declaring non-writable, compile-time constant variables
* attribute - For frequently changing (per vertex) information passed from the application to a vertex shader (no integers, bools, structs, or arrays)
* attribute - For frequently changing (per vertex) information passed from the application to a vertex shader (no integers, bools, structs, or arrays)
* uniform - for infrequently changing (per primitive) information passed from the application to a vertex or fragment shader:constant shader parameters that can be changed between draws (cannot be written to in a shader, do not change per-vertex or per-fragment)
* uniform - for infrequently changing (per primitive) information passed from the application to a vertex or fragment shader:constant shader parameters that can be changed between draws (cannot be written to in a shader, do not change per-vertex or per-fragment)
* varying - for information passed from a vertex shader to a fragment shader, will be interpolated in a perspective-correct manner during rasterization (can write in vertex shader, but only read in fragment shader)
* varying - for information passed from a vertex shader to a fragment shader, will be interpolated in a perspective-correct manner during rasterization (can write in vertex shader, but only read in fragment shader)


Line 254: Line 254:
== Vertex Shader ==
== Vertex Shader ==


* vec4 gl_Position; must be written
* vec4 gl_Position; must be written
* vec4 gl_ClipPosition; may be written
* vec4 gl_ClipPosition; may be written
* float gl_PointSize; may be written
* float gl_PointSize; may be written


== Fragment Shader ==
== Fragment Shader ==
* float gl_FragColor; may be written
* float gl_FragColor; may be written
* float gl_FragDepth; may be read/written
* float gl_FragDepth; may be read/written
* vec4 gl_FragCoord; may be read
* vec4 gl_FragCoord; may be read
* bool gl_FrontFacing; may be read
* bool gl_FrontFacing; may be read


Line 344: Line 344:
   gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
   gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
  }
  }


[[Category:Howto|Shader Programming in FlightGear]]
[[Category:Howto|Shader Programming in FlightGear]]