Created
July 28, 2017 12:23
-
-
Save SpineyPete/a1972e2b0e6a310c30ecbf8b9aa65194 to your computer and use it in GitHub Desktop.
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
// sRGB to/from linear-space conversions, by Ian Taylor | |
// source: http://chilliant.blogspot.be/2012/08/srgb-approximations-for-hlsl.html | |
// Alternate LinearToGamma(), without pow(): | |
// srgb = 0.585122381 * sqrt(linear) + | |
// 0.783140355 * sqrt(sqrt(linear)) - | |
// 0.368262736 * sqrt(sqrt(sqrt(linear))); | |
vec3 LinearToGamma(in vec3 linear) { | |
return max(1.055f * pow3(linear, 0.416666667f) - 0.055f, 0); | |
} | |
vec3 GammaToLinear(in vec3 sRGB) { | |
return 0.012522878f * sRGB + | |
0.682171111f * sRGB * sRGB + | |
0.305306011f * sRGB * sRGB * sRGB; | |
} | |
float LinearToGammaF(in float linear) { | |
return max(1.055f * pow(linear, 0.416666667f) - 0.055f, 0); | |
} | |
float GammaToLinearF(in float sRGB) { | |
return 0.012522878f * sRGB + | |
0.682171111f * sRGB * sRGB + | |
0.305306011f * sRGB * sRGB * sRGB; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment