Does anyone know how I can achieve the following effect in OpenGL:
- Change the brightness of the rendered scene
- Or implementing a Gamma setting in OpenGL
I have tried by changing the ambient parameter of the light and the type of light (directional and omnidirectional) but the result was not uniform. TIA.
Thanks for your help, some additional information: * I can't use any windows specifics API. * The gamma setting should not affect the whole window as I must have different gamma for different views.
On win32 you can use SetDeviceGammaRamp to adjust the overall brightness / gamma. However, this affects the entire display so it's not a good idea unless your app is fullscreen.
The portable alternative is to either draw the entire scene brighter or dimmer (which is a hassle), or to slap a fullscreen alpha-blended quad over the whole scene to brighten or darken it as desired. Neither of these approaches can affect the gamma-curve, only the overall brightness; to adjust the gamma you need grab the entire scene into a texture and then render it back to the screen via a pixel-shader that runs each texel through a gamma function.
Ok, having read the updated question, what you need is a quad with blending set up to darken or brighten everything underneath it. Eg.
if( brightness > 1 )
{
glBlendFunc( GL_DEST_COLOR, GL_ONE );
glColor3f( brightness-1, brightness-1, brightness-1 );
}
else
{
glBlendFunc( GL_ZERO, GL_SRC_COLOR );
glColor3f( brightness, brightness, brightness );
}
glEnable( GL_BLEND );
draw_quad();
http://www.gamedev.net/community/forums/topic.asp?topic_id=435400 might be an answer to your question otherwise you could probably implement a gamma correction as a pixel shader
来源:https://stackoverflow.com/questions/139012/tweak-the-brightness-gamma-of-the-whole-scene-in-opengl