Adding gamma correction to an OpenGL program can be as simple as carrying out the following steps:
- Set up a uniform variable named Gamma and set it to an appropriate value for your system.
- Use the following code or something similar in a fragment shader:
vec3 color = lightingModel( ... ); FragColor = vec4( pow( color, vec3(1.0/Gamma) ), 1.0 );
If your shader involves texture data, care must be taken to make sure that the texture data is not already gamma-corrected so that you don't apply gamma correction twice (refer to the There's more... section of this recipe).