色彩空间。好了,大家都知道RGB了:在[0.0,1.0]范围内归一化的三个值,分别代表颜色分量Red Green Blue的强度;这种强度是线性的,不是吗?
伽玛。据我所知,伽玛是将RGB颜色分量映射到另一个值的函数。谷歌搜索,我看到了线性函数和非线性函数......线性函数似乎可以缩放 RGB 分量,所以它似乎可以调整图像亮度;非线性函数似乎可以“解压缩”较暗/较亮的组件。
现在,我开始实现一个图像查看器,它将不同的图像格式显示为纹理。我想修改这些图像的伽玛,所以我应该建立一个片段着色器并在纹理四边形上运行。很好,但我如何确定正确的伽马校正?
OpenGL 使用线性 RGB 颜色空间,使用浮点组件。实际上,我可以从这些值开始计算伽马校正值(具有特殊的浮点精度),因此它们在钳位伽马校正值后显示。
首先,我将确定伽马斜坡。我怎么能确定呢?(分析或使用查找表)
然后,我开始研究 OpenGL 扩展 EXT_framebuffer_sRGB,这似乎与扩展EXT_texture_sRGB非常相关。
EXT_texture_sRGB 引入了一种新的纹理格式,用于将文本值线性化到 RGB 线性空间中。(脚注1)通过这种方式,我知道sRGB色彩空间并将其用作线性RGB色彩空间。
相反,EXT_framebuffer_sRGB 扩展允许我将线性 RGB 值编码到 sRGB 帧缓冲区,而不用担心它。
...
等等,所有这些信息是为了什么?如果我可以使用 sRGB 帧缓冲区并加载 sRGB 纹理,则无需 sRGB 转换即可处理该纹理……我为什么要更正伽玛?
也许即使在 sRGB 缓冲区上,我也可以同样校正伽玛?或者我最好不要?以及亮度和对比度:它们应该在伽马校正之前还是之后应用?
信息量很大,我现在很困惑。希望你们中的某个人能更多地向我解释所有这些概念!谢谢你。
...
还有一个问题。如果设备伽玛不同于“标准”2.2,我如何“累积”不同的伽玛校正?我不知道是否清楚:如果图像 RGB 值已经针对伽马值为 2.2 的显示器进行了校正,但显示器的伽马值为 2.8,我该如何校正伽马?
(1) 这里有一些摘录来强调我的意思:
sRGB 色彩空间基于昏暗办公室中预期的典型(非线性)显示器特性。它已被国际电工委员会 (IEC) 标准化为 IEC 61966-2-1。sRGB 颜色空间大致对应于 2.2 伽马校正。
此扩展是否提供任何类型的 sRGB 帧缓冲区格式或保证使用 sRGB 纹理渲染的图像在输出到支持 sRGB 颜色空间的设备时“看起来不错”?
RESOLVED: No. Whether the displayed framebuffer is displayed to a monitor that faithfully reproduces the sRGB color space is beyond the scope of this extension. This involves the gamma correction and color calibration of the physical display device. With this extension, artists can author content in an sRGB color space and provide that sRGB content for use as texture imagery that can be properly converted to linear RGB and filtered as part of texturing in a way that preserves the sRGB distribution of precision, but that does NOT mean sRGB pixels are output to the framebuffer. Indeed, this extension provides texture formats that convert sRGB to linear RGB as part of filtering. With programmable shading, an application could perform a linear RGB to sRGB conversion just prior to emitting color values from the shader. Even so, OpenGL blending (other than simple modulation) will perform linear math operations on values stored in a non-linear space which is technically incorrect for sRGB-encoded colors. One way to think about these sRGB texture formats is that they simply provide color components with a distribution of values distributed to favor precision towards 0 rather than evenly distributing the precision with conventional non-sRGB formats such as GL_RGB8.