# 伽马校正

Vries [2]，Gritz等[3]，Akenine-Möller[5]都有介绍伽马校正，首先我们要知道伽马的存在，然后在图形渲染，特别是光照计算中，就要留意它可能对呈现出的结果造成的影响。

（2）对于即将输出到显示器的像素颜色，对它进行伽马校正处理。

GL_EXT_framebuffer_sRGB扩展是一种简单粗暴的做法，它把所有即将输入到颜色缓冲区的颜色做伽马系数（绝大部分的显示设备采用的伽马系数）的伽马校正，即幂指数为的函数处理，保证颜色缓冲区中的颜色数据一定是经过伽马校正的结果，调用方法就一行代码：

glEnable(GL_FRAMEBUFFER_SRGB);

void main()
{
// do super fancy lighting
[...]
// apply gamma correction
float gamma = 2.2;
fragColor.rgb = pow(fragColor.rgb, vec3(1.0/gamma));
}

glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);

## 参考

[1] Cambridge In Colour. “UNDERSTANDING GAMMA CORRECTION.” website <http://www.cambridgeincolour.com/tutorials/gamma-correction.htm>.
[2] Joey de Vries. “Gamma Correction.” website <http://learnopengl.com/#!Advanced-Lighting/Gamma-Correction>.
[3] Larry Gritz, and Eugene d’Eon. “The importance of being linear.” GPU Gems, vol.3, col.4, 2008. website<http://http.developer.nvidia.com/GPUGems3/gpugems3_ch24.html>
[4] Wikipedia. “Gamma Correction.” wesite <https://en.wikipedia.org/wiki/Gamma_correction>
[5] Tomas Akenine-Möller, Eric Haines, and Naty Hoffman. Real-time rendering. CRC Press, 2008.
[6] GL Specification. “EXT_framebuffer_sRGB”. website<https://www.opengl.org/registry/specs/EXT/framebuffer_sRGB.txt >.
[7] GL Specification. “EXT_texture_sRGB”. website< https://www.opengl.org/registry/specs/EXT/texture_sRGB.txt>.
[8] Gihub. “LearnOpenGL.” website<https://github.com/JoeyDeVries/LearnOpenGL>.