4

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);

yuris89
  • 63
  • 4
  • 2
    That attenuation looks weird. Why isn't it the inverse quadratic distance? Attenuation is especially affected by gamma correction. You will most likely need other parameters. – Nico Schertler Sep 18 '18 at 20:11
  • 1
    This is very simple attenuation function for point light. I dont use inverse square law because the light contribution never goes to 0.0. I use light "radius" property to be sure that after some distance (radius) there is no fragments, that affected by the light. I guess you are absolutley right about how gamma affect attenuation, but specular lighting is visible and diffuse is not, where attenuation should decrease all contributions.(?) Ill try use correct attenuation and see whats happen – yuris89 Sep 18 '18 at 20:34
  • 1
    @yuris5513: "*the light contribution never goes to 0.0*" That's how reality works; light intensity never goes to zero. So, do you want reality or not? – Nicol Bolas Sep 18 '18 at 20:38
  • No, i dont need too realistic lighting. Main thing i want to see in my point light is that it have solid radius of contribution – yuris89 Sep 18 '18 at 20:40
  • One more qurstion are textures you are loading in srgba space or linear space? If they are in linear space your lighting will break. – Paritosh Kulkarni Sep 19 '18 at 00:39
  • Yes i load them with GL_SRGB internal format – yuris89 Sep 19 '18 at 07:58
  • I have similar problem, i think you talk about this: https://learnopengl.com/Advanced-Lighting/Gamma-Correction ... the green text in the attenuation chapter says "The more advanced attenuation function we discussed in the basic lighting is still useful in gamma corrected scenes as it gives much more control over the exact attenuation (but of course requires different parameters in a gamma corrected scene)." So try to use that equation and give it different parameters ... that's what i am doing currently. – Avi Oct 25 '18 at 21:04
  • It's hard to decipher what you do based on those images. Is that light on on left half of the first one comes from an ambient term or from a diffuse? Why don't you post your shaders code? – Yakov Galka Apr 09 '19 at 00:58

0 Answers0