Created
August 3, 2018 16:52
-
-
Save Reedbeta/e8d3817e3f64bba7104b8fafd62906df to your computer and use it in GitHub Desktop.
Conversion between sRGB and linear color encoding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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