OpenGL:经Gamma校正的图像看起来不是线性的 [英] OpenGL: Gamma corrected image doesn't appear linear

查看:157
本文介绍了OpenGL:经Gamma校正的图像看起来不是线性的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OpenGL进行渲染,当我将线性值写入默认帧缓冲区(不进行任何伽马校正)时,它们在监视器上显示为线性.这违反了我以为我知道的有关伽玛校正的所有信息(如下所述: http://gamedevelopment.tutsplus.com/articles/gamma-correction-and-why-it-matters-gamedev-14466 ).如果不进行伽玛校正,则我的显示器将看到中间范围的颜色非线性地变暗.

I'm using OpenGL for rendering, and when I write linear values to the default framebuffer (without any gamma correction) they appear linear on my monitor. This goes against everything I thought I knew about gamma correction (as explained here: http://gamedevelopment.tutsplus.com/articles/gamma-correction-and-why-it-matters--gamedev-14466 ). Without gamma correction, I would expect to see mid-range colors darkened non-linearly by my monitor.

但这是我实际看到的;首先我没有进行伽马校正,然后进行了伽马校正:

But here is what I actually see; first with no gamma correction on my part, then with gamma correction:

这是我的没有gamma校正的片段着色器(在全屏四边形上绘制到默认帧缓冲区).这将导致左侧的线性图像:

Here's my fragment shader without gamma correction (drawn on a fullscreen quad to the default framebuffer). This results in the linear image on the left:

out vec4 fsOut0;

void main( void )
{
    // split the screen into 10 discrete color bands
    float yResolution = 768.0;
    int intVal = int(gl_FragCoord.y / yResolution * 10.0);
    fsOut0.rgb = vec3( float(intVal) / 10.0 );

    fsOut0.a = 1.0;
}

这是添加了伽玛校正(从线性空间到sRGB)的着色器.这样会在右侧产生比线性明亮的图像:

And here's the shader with added gamma correction (from linear space to sRGB). This results in the brighter-than-linear image on the right:

out vec4 fsOut0;

void main( void )
{
    // split the screen into 10 discrete color bands
    float yResolution = 768.0;
    int intVal = int(gl_FragCoord.y / yResolution * 10.0);
    fsOut0.rgb = vec3( float(intVal) / 10.0 );

    // gamma correction
    fsOut0.rgb = pow( fsOut0.rgb, vec3(1.0/2.2) );

    fsOut0.a = 1.0;
}

我正在检查颜色是否是线性的,只需查看它们,并使用Photoshop中的颜色选择器并查看色带之间RGB值的差异.对于线性图片,每种颜色之间的差异(通常)是恒定的.

I'm verifying whether or not the colors are linear just by looking at them, and by using the color picker in Photoshop and looking at the differences in RGB values between color bands. For the linear-looking image the difference between each color is (mostly) constant.

我也尝试过请求支持sRGB的默认帧缓冲区.在这种情况下,写没有伽马校正的线性值看起来就像第二幅图像(非线性).

I have also tried requesting an sRGB-capable default framebuffer. In this case, writing linear values with no gamma correction looks like the second image (non-linear).

我做错了什么?还是我的两个显示器都校准不正确,并且Photoshop不在线性空间中拾取颜色?还是我的非线性"图像实际上是正确的线性结果,但是在我眼中看起来似乎不是线性的?

What am I doing wrong? Or could it be that my two monitors are both miscalibrated AND that Photoshop does not pick colors in linear space? Or is my "non-linear" image actually the correct linear result, but it just doesn't seem linear to my eyes?

我的问题有点类似:

My question is sort of a duplicate of this: Do I need to gamma correct the final color output on a modern computer/monitor Unfortunately the accepted answer is extremely confusing and the parts of it I was able to follow seem contradictory, or at least not fully explained for someone less knowledgeable than the answerer.

推荐答案

好吧,您的左右图片均符合预期.他们很好,是的,我知道我的东西.

Well, both your left and right pictures are as is to be expected. They are perfectly fine, and yes, I know my stuff.

这仅仅是因为我们的眼睛也不是很线性,所以例如线性强度(发光强度)的1/5被认为是白色的一半".这就是您在右侧附近的校正图像中看到的结果.

It's just that our eyes are not very linear either, so e.g. 1/5th of linear intensity (luminous intensity) is perceived as "half as bright as white". This is what you see on the right, in the corrected image, near the bottom.

这是首先出现伽玛的原因-通过模仿眼睛的响应来帮助编码. IOW,伽玛使非线性斜坡看起来是线性的.

This is the reason for gamma being there in the first place - to help encoding by mimicking the eye's response. IOW, gamma makes the non-linear ramp look linear.

但是,物理上线性的斜坡(如右图)因此与被认为是线性的相反.请记住,现实世界具有很大的动态范围(就发光强度而言),而我们的眼睛对此做出了补偿.这让您感到困惑,但与许多其他人不同,您实际上是正确的数字.

However, a physically linear ramp (as on the right) is therefore quite counter to being perceived as linear. Remember that the real world has a quite large dynamic range (in terms of luminous intensity), and our eyes are compensating for that. This is confusing you, but unlike many others, you actually got the numbers right.

这篇关于OpenGL:经Gamma校正的图像看起来不是线性的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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