本文介绍了伽玛校正看起来没有正确校正,这是线性的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对我的OpenGL照明实现伽玛校正,但是应用了伽玛校正后,我的结果看起来根本就不是线性的.

I want to implement gamma correction to my OpenGL lighting, but with gamma correction applied, my results do not seem linear at all.

我还发现 OpenGL:经伽玛校正的图像似乎不是线性的与我的问题非常相似,但尚未得到答案,也没有讨论实际的漫射光.

I also found OpenGL: Gamma corrected image doesn't appear linear which is very similar to my issue, but hasn't yet received an answer nor discussed actual diffuse lights.

作为说明,我在线性空间中定义了以下4种浅色:

As an illustration, I have the following 4 light colors defined in linear space:

glm::vec3 lightColors[] = {
    glm::vec3(0.25),
    glm::vec3(0.50),
    glm::vec3(0.75),
    glm::vec3(1.00)
};

在分离每个光源并将基本线性衰减应用于漫射照明方程式的情况下,我得到以下结果:

With each light source seperated and a basic linear attenuation applied to a diffuse lighting equation I get the following results:

这是片段着色器:

void main()
{
    vec3 lighting = vec3(0.0);
    for(int i = 0; i < 4; ++i)
        lighting += Diffuse(normalize(fs_in.Normal), fs_in.FragPos, lightPositions[i], lightColors[i]);
    // lighting = pow(lighting, vec3(1.0/2.2));
    FragColor = vec4(lighting, 1.0f);
}

通过伽玛校正后的光,我几乎看不到任何亮度差异,而且伽玛校正也使衰减失真.据我所知,所有计算(包括衰减)都是在线性空间中完成的,并且通过校正伽玛,监视器应该正确显示它(因为它再次将其校正为输出).仅根据照明颜色,最右边的圆圈应该是左边圆圈的4倍,是第二个圆圈的两倍,这似乎并非如此.

Not only do I barely see any difference in brightness with the gamma corrected lights, the attenuation is also distorted by the gamma correction. As far as my understanding goes, all calculations (including attenuation) are done in linear space and by correcting the gamma the monitor should display it correctly (as it uncorrects it again as output). Based on just the lighting colors, the right-most circle should be 4 times as bright as the left circle and twice as bright as the second circle which doesn't really seem to be the case.

仅仅是因为我不够灵敏,无法感知正确的亮度差异,还是出了点问题?

Is it just that I'm not sensitive enough to perceive the correct brightness differences or is something wrong?

我尝试过的其他事情就是简单地将确切的浅色输出到默认的帧缓冲区中,而无需进行伽玛校正.

Something else I tried is simply output the exact light colors onto the default framebuffer without and with gamma correction.

左为未校正,右为伽马校正;红色数字表示Photoshop拾色器中的RGB强度.我知道Photoshop RGB值不能代表最终的输出图像(因为photoshop不会将RGB值作为监视器输出读取).从直观上看,左图像看起来更好,但是基于RGB强度值,我想说最右图像的确是由我的片段着色器正确地进行了伽玛校正的.因为这些强度中的每一个都会通过监视器,并以正确的强度进入我的眼睛.例如,作为监视器的输出,经过0.88伽玛校正的0.75强度变为0.88 ^ 2.2 = 0.75.

Left is uncorrected, right is with gamma correction; with the red numbers indicating the RGB intensity from Photoshop's color picker. I know that Photoshop RGB values do not represent the final output image (as photoshop doens't read the RGB values as monitor outputs). The left image intuitively seems better, but based on the RGB intensity values I'd say the right-most image is indeed correctly gamma-corrected by my fragment shader; as each of these intensities will pass through the monitor and enter my eye with the correct intensity. For instance, the 0.75 intensity as 0.88 gamma corrected becomes 0.88^2.2 = 0.75 as output of the monitor.

正确的图像确实正确吗?而且,与其他图像相比,实际的照明效果如何?

Is the right image indeed correct? And also, how comes the actual lighting is so off compared to the other images?

推荐答案

所得到的结果就是预期的结果.

The results you are getting is what is to be expected.

您似乎将显示器产生的物理辐射辐射与人类的感知到的亮度混淆了.后者是非线性的,简单的伽马模型是一种近似的方法.基本上,监视器会反转人眼的非线性变换,以便可以线性感知标准(非线性)RGB空间-使用RGB强度0.5时,亮度大约是1.0的一半,因此上.

You seem to confuse the physical radiometric radiance created by the display with the perceived brightness of a human. The latter is nonlinear, and the simple gamma model is a way to approximate that. Basically, the monitor is inverting the nonlinear transformation of the human eye, so that the standard (nonlinear) RGB space is perceived linearily - using RGB intensity 0.5 is perceived as roughly half as bright as 1.0, and so on.

如果在显示经过伽马校正的灰度级时在显示器上放置比色计或分光光度计,则实际上您会看到0.73步长将显示坎德拉/m ^ 2的白色级亮度的大约50%(假设您的显示与sRGB模型没有太大的偏差,即不使用gamma 2.2,而是线性段与gamma 2.4结合使用,则2.2仅是另一个近似值.

If you would put a colorimeter or spectrophotomer at youe display when displaying your gamma-corrected grayscale levels, you would actually see that the 0.73 step would show roughly 50% of the luminance of the white level in candela/m^2 (assuming you display does not deviate too much from an sRGB model which is btw. not using gamma 2.2, but a linear segment in combination with gamma 2.4 for the rest, the 2.2 is only another approximation).

现在的问题是:您到底想实现什么?如果要进行物理上准确的计算,通常需要在线性颜色空间中进行操作.但是,如果另一种光源的亮度达到另一种光源的亮度的50%,那么它对人的亮度就不会达到后者的一半,而您得到的结果基本上是正确的.

Now the question is: what exactly do you want to achieve? Working in linear color space typically is required if you want to do physically accurate calculations. But then, a light source with 50% of the luminance of another one does not apper as half as bright to the human, and the result you got basically is correct.

如果您只想拥有在感知亮度上呈线性的色彩空间,则可以完全跳过伽玛校正,因为sRGB确实已经尝试提供这种色彩空间.如果要获得准确的结果,您可能只需要进行一些颜色校准或较小的伽玛调整即可校正显示器引起的偏差.

If you want just to have a a color space which is linear in percepted brightness, you can completely skip the gamma correction, as sRGB is exaclty trying to provide that already. You might just need some color calibration or small gamma adjustment to correct for deviations introduced by your display, if you want exact results.

这篇关于伽玛校正看起来没有正确校正,这是线性的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 04:51