Skip to content

Instantly share code, notes, and snippets.

@Reedbeta
Created August 3, 2018 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Reedbeta/e8d3817e3f64bba7104b8fafd62906df to your computer and use it in GitHub Desktop.
Save Reedbeta/e8d3817e3f64bba7104b8fafd62906df to your computer and use it in GitHub Desktop.
Conversion between sRGB and linear color encoding
vec3 sRGBToLinear(vec3 rgb)
{
// See https://gamedev.stackexchange.com/questions/92015/optimized-linear-to-srgb-glsl
return mix(pow((rgb + 0.055) * (1.0 / 1.055), vec3(2.4)),
rgb * (1.0/12.92),
lessThanEqual(rgb, vec3(0.04045)));
}
vec3 LinearToSRGB(vec3 rgb)
{
// See https://gamedev.stackexchange.com/questions/92015/optimized-linear-to-srgb-glsl
return mix(1.055 * pow(rgb, vec3(1.0 / 2.4)) - 0.055,
rgb * 12.92,
lessThanEqual(rgb, vec3(0.0031308)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment