PDA

View Full Version : how to remove gamma correction



3DPrgmer
01-19-2017, 02:54 PM
Hi,

This Tutorial (http://www.tomdalling.com/blog/modern-opengl/07-more-lighting-ambient-specular-attenuation-gamma/) says something about gamma correction. And that the image files are already gamma corrected. It is solved by using a different internal format. As you may already know I'm using Qt. And there is no srgb format. So I thought I correct it by my own.

Just one question is the formula I'm using here correct??

https://git.rwth-aachen.de/carstenf/OpenGL/blob/master/QtMeshViewer/Resources/fshader.glsl#L35

Spoops
01-20-2017, 04:22 AM
Yes, this is correct. sRGB -> linear is x^2.2, and linear -> sRGB is x^(1/2.2).

mhagain
01-20-2017, 09:12 AM
Yes, this is correct. sRGB -> linear is x^2.2, and linear -> sRGB is x^(1/2.2).

Not quite. it's an approximation, but it's not the exact transformation. Please see https://en.wikipedia.org/wiki/SRGB#Specification_of_the_transformation

GClements
01-20-2017, 12:29 PM
This Tutorial (http://www.tomdalling.com/blog/modern-opengl/07-more-lighting-ambient-specular-attenuation-gamma/) says something about gamma correction. And that the image files are already gamma corrected. It is solved by using a different internal format. As you may already know I'm using Qt. And there is no srgb format. So I thought I correct it by my own.

You should ideally let OpenGL perform the conversion.

For reading sRGB-encoded textures (or any gamma-corrected texture, which will be much closer to sRGB than to linear), telling OpenGL that the texture is sRGB will result in filtering being performed correctly; interpolating then converting manually will be incorrect. This shouldn't require any support from Qt, just using GL_SRGB8 or GL_SRGB8_ALPHA8 (rather than GL_RGB8 or GL_RGBA8) as the texture's format. Manually converting the result of e.g. texture2D() is only correct when using nearest-neighbour sampling (no interpolation).

Conversion from linear intensity to sRGB-encoded value on output may require support from Qt if you perform the conversion when writing to the default framebuffer. This can safely be done manually.


Just one question is the formula I'm using here correct??
No, but it's close enough unless you're dealing with values very close to black. And it may in fact be correct for some textures; sRGB was a minor adjustment to existing practice, so some "sRGB" textures may in fact just be intensity1/2.2 rather than actual sRGB. The main reason for sRGB's adjustment is that an exponent of less than one results in the graph having a vertical slope at zero, meaning that an encode-decode cycle loses accuracy for values very close to zero.

3DPrgmer
01-21-2017, 06:38 AM
using the srgb format for the qopengltexture changes nothing

john_connor
01-21-2017, 07:02 AM
using the srgb format for the qopengltexture changes nothing

maybe you forgot to call:

glEnable(GL_FRAMEBUFFER_SRGB);
https://www.khronos.org/opengl/wiki/Framebuffer#Colorspace


When GL_FRAMEBUFFER_SRGB is disabled, the system assumes that the color written by the fragment shader is in whatever colorspace the image it is being written to is. Therefore, no colorspace correction is performed.