Opengl 什么是正确的伽马校正函数?
目前,我使用以下公式在照明过程后对颜色进行gamma校正(将颜色从RGB转换为sRGB颜色空间):Opengl 什么是正确的伽马校正函数?,opengl,colors,rendering,srgb,Opengl,Colors,Rendering,Srgb,目前,我使用以下公式在照明过程后对颜色进行gamma校正(将颜色从RGB转换为sRGB颜色空间): output = pow(color, vec3(1.0/2.2)); 这个公式是伽马校正的正确公式吗?我问这个问题是因为我遇到一些人说它不是,正确的公式更复杂,与幂2.4有关,而不是2.2。我还听说三色R、G和B应该有不同的权重(比如0.2126、0.7152、0.0722) 我也很好奇,当启用GL\u FRAMEBUFFER\u SRGB时,OpenGL使用哪个函数 编辑: 这是盖伊·戴维森
output = pow(color, vec3(1.0/2.2));
这个公式是伽马校正的正确公式吗?我问这个问题是因为我遇到一些人说它不是,正确的公式更复杂,与幂2.4有关,而不是2.2。我还听说三色R、G和B应该有不同的权重(比如0.2126、0.7152、0.0722)
我也很好奇,当启用GL\u FRAMEBUFFER\u SRGB
时,OpenGL使用哪个函数
编辑:
这是盖伊·戴维森(Guy Davidson)演讲“你所知道的关于颜色的一切都是错误的”中涉及的许多话题之一。gamma校正函数已包含在内,但整个讨论都与颜色空间有关,包括sRGB和gamma校正。gamma校正可能有任何值,但考虑到线性RGB/非线性sRGB转换,2.2是一个近似值,因此您的公式可能被认为是错误和正确的: 实际sRGB传递函数基于2.4伽马系数,在暗值下具有不连续性,如下所示:
float Convert\u sRGB\u from linear(浮点线性值){
返回线性值谢谢。这正是我要找的。线性化后,当您将通道相加以创建亮度Y(例如创建图像灰度)时,将应用0.2126、0.7152、0.0722的sRGB权重。如果您只是从线性化开始或从线性化开始,通常不会应用这些系数RGB到编码的sRGB。
Given a linear RGB component, cl, convert it to an sRGB component, cs, in the range [0,1], with this pseudo-code:
if (isnan(cl)) {
/* Map IEEE-754 Not-a-number to zero. */
cs = 0.0;
} else if (cl > 1.0) {
cs = 1.0;
} else if (cl < 0.0) {
cs = 0.0;
} else if (cl < 0.0031308) {
cs = 12.92 * cl;
} else {
cs = 1.055 * pow(cl, 0.41666) - 0.055;
}
The NaN behavior in the pseudo-code is recommended but not specified in the actual specification language.
sRGB components are typically stored as unsigned 8-bit fixed-point values.
If cs is computed with the above pseudo-code, cs can be converted to a [0,255] integer with this formula:
csi = floor(255.0 * cs + 0.5)