PDA

View Full Version : Small sample in opengl es 3, wrong gamma correction



elect
02-09-2016, 10:55 AM
I have a small sample, es-300-fbo-srgb (https://github.com/elect86/jogl-samples/blob/master/jogl-samples/src/tests/es_300/Es_300_fbo_srgb.java), supposed to showing how to manage gamma correction in opengl es3.


Essentially I have:




a GL_SRGB8_ALPHA8 texture TEXTURE_DIFFUSE
a framebuffer with another GL_SRGB8_ALPHA8 texture on GL_COLOR_ATTACHMENT0 and a GL_DEPTH_COMPONENT24 texture on GL_DEPTH_ATTACHMENT
the back buffer of my default fbo is GL_LINEAR
GL_FRAMEBUFFER_SRGB initially disabled.


I get this (http://i.stack.imgur.com/cgJu3.png) instead of this (http://i.stack.imgur.com/MMJMe.png)

Now, if I recap the display metho, this is what I do:




I render the TEXTURE_DIFFUSE texture on the sRGB fbo and since the source texture is in sRGB space, my fragment shader will read automatically a linear value and write it to the fbo. Fbo should contain now linear values, although it is sRGB, because GL_FRAMEBUFFER_SRGB is disabled, so no linear->sRGB conversion is executed.

I blit the content of the fbo to the default fbo back buffer (through a program). But since the texture of this fbo has the sRGB component, on the read values a wrong gamma operation will be performed because they are assumed in sRGB space when they are not.

a second gamma operation is performed by my monitor when it renders the content of the default fbo


So my image is, if I am right, twice as wrong..


Now, if I glEnable(GL_FRAMEBUFFER_SRGB) just once I get instead this
(http://i.stack.imgur.com/4La9s.png)
The image looks like it have been too many times sRGB corrected..

But if I enable it at the first passage (https://github.com/elect86/jogl-samples/blob/master/jogl-samples/src/tests/es_300/Es_300_fbo_srgb.java#L349) and disable it at the second one (https://github.com/elect86/jogl-samples/blob/master/jogl-samples/src/tests/es_300/Es_300_fbo_srgb.java#L376), then it works, but I don't why...

ideas?