Difference between revisions of "Gamma"

From vegard.wiki
Jump to navigation Jump to search
(→‎See also: add link)
(add link)
Line 31: Line 31:
 
* https://www.cambridgeincolour.com/tutorials/gamma-correction.htm
 
* https://www.cambridgeincolour.com/tutorials/gamma-correction.htm
 
* http://chilliant.blogspot.com/2012/08/srgb-approximations-for-hlsl.html
 
* http://chilliant.blogspot.com/2012/08/srgb-approximations-for-hlsl.html
 +
* https://unlimited3d.wordpress.com/2020/01/08/srgb-color-space-in-opengl/
  
 
[[Category:Graphics programming]]
 
[[Category:Graphics programming]]

Revision as of 07:57, 28 November 2020

Quick rules of thumb, since I can never remember which is which:

  • RGB = linear space
  • sRGB = gamma space
  • most image files store sRGB
  • sRGB is unfit for blending

The corollary is:

  • Image files loaded as textures should be converted from sRGB to RGB (but some decoders do this for you!)
  • Since alpha is linear, alpha premultiplication should happen in linear space, i.e. after converting to RGB [1]
  • The shader responsible for putting the final pixels on the screen should have a gamma correction step doing:
const float gamma = 2.2;

out vec4 color;

void main()
{
    // ...

    color = pow(color, 1. / gamma);
}

Note, however, that OpenGL may also perform this step for you on any on-screen framebuffers (i.e. the default framebuffer) if you do glEnable(GL_FRAMEBUFFER_SRGB).

See also