Tweak the brightness/gamma of the whole scene in OpenGL

后端 未结 2 700
谎友^
谎友^ 2021-01-06 13:43

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 Open
相关标签:
2条回答
  • 2021-01-06 14:43

    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();
    
    0 讨论(0)
  • 2021-01-06 14:48

    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

    0 讨论(0)
提交回复
热议问题