mikejsavage.co.uk / blog

RSS feed

29 Oct 2017 / GL_FRAMEBUFFER_SRGB sucks

I replaced GL_FRAMEBUFFER_SRGB with explicit linear-to-sRGB conversions in my shaders.

It's a little bit more code but having the extra control is worth it. The big wins are a UI that looks like it does in image editors, and being able to easily turn off sRGB for certain debug visualisations.

Some GLSL for myself to copy paste into future projects:

float linear_to_srgb( float linear ) {
        if( linear <= 0.0031308 )
                return 12.92 * linear;
        return 1.055 * pow( linear, 1.0 / 2.4 ) - 0.055;
}

vec3 linear_to_srgb( vec3 linear ) {
        return vec3( linear_to_srgb( linear.r ), linear_to_srgb( linear.g ), linear_to_srgb( linear.b ) );
}

vec4 linear_to_srgb( vec4 linear ) {
        return vec4( linear_to_srgb( linear.rgb ), linear.a );
}