在 OpenGL 中调整整个场景的亮度/伽玛 [英] Tweak the brightness/gamma of the whole scene in OpenGL

查看:72
本文介绍了在 OpenGL 中调整整个场景的亮度/伽玛的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道我如何在 OpenGL 中实现以下效果:

Does anyone know how I can achieve the following effect in OpenGL:

  • 改变渲染场景的亮度
  • 或者在 OpenGL 中实现 Gamma 设置

我曾尝试更改灯光的环境参数和灯光类型(定向和全向),但结果并不统一.TIA.

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.

感谢您的帮助,补充一些信息:* 我不能使用任何 Windows 特定 API.* 伽马设置不应影响整个窗口,因为我必须为不同的视图设置不同的伽马.

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.

推荐答案

在 win32 上,您可以使用 SetDeviceGammaRamp 来调整整体亮度/伽玛.但是,这会影响整个显示,因此除非您的应用是全屏的,否则这不是一个好主意.

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.

便携式替代方案是将整个场景绘制得更亮或更暗(这很麻烦),或者在整个场景上拍打全屏 alpha 混合四边形以根据需要使其变亮或变暗.这些方法都不能影响伽马曲线,只能影响整体亮度;要调整伽马,您需要将整个场景抓取到纹理中,然后通过像素着色器将其渲染回屏幕,该像素着色器通过伽马函数运行每个纹素.

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();

这篇关于在 OpenGL 中调整整个场景的亮度/伽玛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆