什么时候调用glEnable(GL_FRAMEBUFFER_SRGB)? [英] When to call glEnable(GL_FRAMEBUFFER_SRGB)?

查看:1185
本文介绍了什么时候调用glEnable(GL_FRAMEBUFFER_SRGB)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个渲染系统,我绘制一个FBO与多采样渲染缓冲区,然后blit它到一个纹理的另一个FBO,以解决样本,以读取纹理执行后处理阴影,同时绘制backbuffer(FBO索引0)。

I have a rendering system where I draw to an FBO with a multisampled renderbuffer, then blit it to another FBO with a texture in order to resolve the samples in order to read off the texture to perform post-processing shading while drawing to the backbuffer (FBO index 0).

现在我想得到一些正确的sRGB输出...问题是程序的行为是不一致的,当我在OS X和Windows上运行它并且这也根据机器而变化:在具有Intel HD 3000的Windows上,它不会应用sRGB非线性,而是在我的其他机器上使用Nvidia GTX 670。在英特尔HD 3000在OS X它也将应用它。

Now I'd like to get some correct sRGB output... The problem is the behavior of the program is rather inconsistent between when I run it on OS X and Windows and this also changes depending on the machine: On Windows with the Intel HD 3000 it will not apply the sRGB nonlinearity but on my other machine with a Nvidia GTX 670 it does. On the Intel HD 3000 in OS X it will also apply it.

所以这可能意味着我没有在程序的正确点设置我的 GL_FRAMEBUFFER_SRGB 启用状态。然而,我似乎找不到任何教程,实际告诉我什么时候应该启用它,他们只提到它是死容易,没有性能成本。

So this probably means that I'm not setting my GL_FRAMEBUFFER_SRGB enable state at the right points in the program. However I can't seem to find any tutorials that actually tell me when I ought to enable it, they only ever mention that it's dead easy and comes at no performance cost.

我目前没有加载任何纹理,所以我没有必要处理线性化他们的颜色。

I am currently not loading in any textures so I haven't had a need to deal with linearizing their colors yet.

为了强制程序不直接退出线性颜色值,我试过的只是注释掉我的 glDisable(GL_FRAMEBUFFER_SRGB)行,这实际上意味着这个设置为整个管道启用,我实际上冗余地强制它回到每一帧。

To force the program to not simply spit back out the linear color values, what I have tried is simply comment out my glDisable(GL_FRAMEBUFFER_SRGB) line, which effectively means this setting is enabled for the entire pipeline, and I actually redundantly force it back on every frame.

我不知道这是否正确。它确实应用非线性化的颜色,但我不知道这是否被应用两次(这将是坏)。它可以应用伽马,因为我呈现给我的第一个FBO。它可以做到,当我blit第一个FBO到第二个FBO。为什么不?

I don't know if this is correct or not. It certainly does apply a nonlinearization to the colors but I can't tell if this is getting applied twice (which would be bad). It could apply the gamma as I render to my first FBO. It could do it when I blit the first FBO to the second FBO. Why not?

我已经拍摄了最后一帧的屏幕截图,并将原始像素颜色值与我在程序中设置的颜色进行比较:

I've gone so far as to take screen shots of my final frame and compare raw pixel color values to the colors I set them to in the program:

我将输入颜色设置为RGB(1,2,3),输出为RGB(13,22,28)。

I set the input color to RGB(1,2,3) and the output is RGB(13,22,28).

这似乎在低端有相当多的颜色压缩,并导致我质疑伽马是否被应用多次。

That seems like quite a lot of color compression at the low end and leads me to question if the gamma is getting applied multiple times.

我刚刚经历了sRGB方程,我可以验证转换似乎只应用一次线性1/255,2/255和3 / 255确实使用等式 1.055 * C ^(1 / 2.4)+0.055 映射到sRGB 13/255,22/255和28/255。考虑到这些低色值的扩展是如此之大,如果sRGB颜色变换被不止一次地应用,它真的应该是显而易见的。

I have just now gone through the sRGB equation and I can verify that the conversion seems to be only applied once as linear 1/255, 2/255, and 3/255 do indeed map to sRGB 13/255, 22/255, and 28/255 using the equation 1.055*C^(1/2.4)+0.055. Given that the expansion is so large for these low color values it really should be obvious if the sRGB color transform is getting applied more than once.

所以,我还没有决定什么是正确的事情。 glEnable(GL_FRAMEBUFFER_SRGB)只适用于最后的framebuffer值,在这种情况下,我可以在我的GL初始化例程中设置它,并在以后忘记它?

So, I still haven't determined what the right thing to do is. does glEnable(GL_FRAMEBUFFER_SRGB) only apply to the final framebuffer values, in which case I can just set this during my GL init routine and forget about it hereafter?

推荐答案

当启用 GL_FRAMEBUFFER_SRGB 时,所有写入到 sRGB图像格式将假设输入颜色(正在写入的颜色)在线性颜色空间中。因此,它会将它们转换为sRGB颜色空间。

When GL_FRAMEBUFFER_SRGB is enabled, all writes to an image with an sRGB image format will assume that the input colors (the colors being written) are in a linear colorspace. Therefore, it will convert them to the sRGB colorspace.

任何对sRGB格式的不是图像的写入不应受影响。所以如果你写一个浮点图像,什么都不应该发生。因此,你应该能够把它打开,离开这样; OpenGL将知道什么时候渲染到sRGB帧缓冲区。

Any writes to images that are not in the sRGB format should not be affected. So if you're writing to a floating-point image, nothing should happen. Thus, you should be able to just turn it on and leave it that way; OpenGL will know when you're rendering to an sRGB framebuffer.

一般来说,你想在一个线性的颜色空间工作尽可能长。只有最后的渲染,后处理后,应该涉及sRGB色彩空间。所以你的多采样帧缓冲应该保持线性(虽然你应该给它更高的分辨率为其颜色保持准确性使用 GL_RGB10_A2 GL_R11F_G11F_B10F GL_RGBA16F 作为最后手段)。

In general, you want to work in a linear colorspace for as long as possible. Only your final render, after post-processing, should involve the sRGB colorspace. So your multisampled framebuffer should probably remain linear (though you should give it higher resolution for its colors to preserve accuracy. Use GL_RGB10_A2, GL_R11F_G11F_B10F, or GL_RGBA16F as a last resort).


$ b

As for this:


在使用Intel HD 3000的Windows上,它不会应用sRGB非线性

On Windows with the Intel HD 3000 it will not apply the sRGB nonlinearity

这几乎肯定是由于英特尔在写OpenGL驱动程序。如果在启用 GL_FRAMEBUFFER_SRGB 时没有做正确的事,那是因为英特尔,而不是您的代码。

That is almost certainly due to Intel sucking at writing OpenGL drivers. If it's not doing the right thing when you enable GL_FRAMEBUFFER_SRGB, that's because of Intel, not your code.

当然,也可能是英特尔的驱动程序没有给你一个sRGB图像开始(如果你正在渲染到默认帧缓冲区)。

Of course, it may also be that Intel's drivers didn't give you an sRGB image to begin with (if you're rendering to the default framebuffer).

这篇关于什么时候调用glEnable(GL_FRAMEBUFFER_SRGB)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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