Skip to main content
3 of 3
Various gramatical erros and code formatting
Gustavo Maciel
  • 5.2k
  • 3
  • 26
  • 42

Optimized linear to sRGB GLSL

I'm currently using a simple implementation of linear to sRGB transform:

float sRGB(float x) {
    if (x <= 0.00031308)
        return 12.92 * x;
    else
        return 1.055*pow(x,(1.0 / 2.4) ) - 0.055;
}
vec3 sRGB_v3(vec3 c) {
    return vec3(sRGB(c.x),sRGB(c.y),sRGB(c.z));
}

Possibly, that the correction for small values (x <= 0.00031308) will not matter in practice.

I considered to just let ´pow(x, 1.0 / 2.4) but I'm not sure how much impact it will have.

Is there any way to optimize it? Can be vectorization help? Can some polynomal fitting be better?