Shader Coding - Best Practices

From FlightGear wiki
Jump to navigation Jump to search
WIP.png Work in progress
This article or section will be worked on in the upcoming hours or days.
Note: Will be based on: http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg35934.html
See history for the latest developments.

Vertex Shaders

Note  For testing purposes, you can use a simple pass-through vertex shader:
#version 120
void main(void) {
        gl_Position = ftransform();
}


Fragment Shaders

Note  To check if your shader is working, add this as the last line, it should turn all pixels black:
gl_FragColor = vec4 (0.0,0.0,0.0,1.0);
Note  If the fragment isn't running, there should be an error message in the log file (I wish they'd still be written to the console). Might be that the texture isn't defined in the supporting framework for instance - the shader assumed that it is available, but you need to declare it in the matching C++ code/effect file first.
Note  This is how you can make a pixel darker:
gl_FragColor = color * 0.5;