OpenGL gamma correction with GL_FRAMEBUFFER_SRGB

时间:2018-09-18 19:39:28

标签: opengl gamma srgb phong

I am writing a Blinn Phong (LearnOpenGL tutorial) lighting and trying to get gamma corrected colors as final result.

Before i start digging about gamma correction, my lighting looks like this:

image 1

Then i spend all day reading about sRgb colorspace, and what is its meaning. I came up to conclusion that having gamma corrected colors results in better lighing quality.

I dont wanna bother myself with manually adjusting gamma in fragment shader. I can let opengl do it with enabling GL_FRAMEBUFFER_SRGB, and requesting sRgb capable framebufer.(?)

This is with enabled GL_FRAMEBUFFER_SRGB and textures loaded in GL_RGB format:

image 2

This is expected results. Colors a more brighter, because sampled textures are color corrected twice.(?)

This is with enabled GL_FRAMEBUFFER_SRGB and textures loaded in GL_SRGB format:

image 3 This is unexpected results. Everything is too dark, and no diffuse color visible, only specular.

My question is:

To let opengl do gamma correction on its own (according to LearnOpenGL tutorial), i need to:

• have a framebuffer with SRGB support;

• load textures with SRGB flag;

What im doing wrong, or maby i miss something important?

Update: diffuse texture loaded with GL_SRGB format, while specular in GL_RGB. In last image it seems like diffuse color is totally attenuated(?), while specular sampled as expected. My attenuation function is:

float attenuation = max(1.0 - distance / light.radius, 0.0);

0 个答案:

没有答案