From 8c1518f25902a8874efc62afdede194358051a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Tue, 17 Feb 2015 16:26:10 -0800 Subject: [PATCH] Added toLinear/GammaAccurate shader functions. --- examples/common/shaderlib.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/examples/common/shaderlib.sh b/examples/common/shaderlib.sh index 8f1d30eb..b8915d16 100644 --- a/examples/common/shaderlib.sh +++ b/examples/common/shaderlib.sh @@ -183,6 +183,19 @@ vec4 toLinear(vec4 _rgba) return vec4(toLinear(_rgba.xyz), _rgba.w); } +vec3 toLinearAccurate(vec3 _rgb) +{ + vec3 lo = _rgb / 12.92; + vec3 hi = pow( (_rgb + 0.055) / 1.055, vec3_splat(2.4) ); + vec3 rgb = mix(hi, lo, vec3(lessThanEqual(_rgb, vec3_splat(0.04045) ) ) ); + return rgb; +} + +vec4 toLinearAccurate(vec4 _rgba) +{ + return vec4(toLinearAccurate(_rgba.xyz), _rgba.w); +} + float toGamma(float _r) { return pow(abs(_r), 1.0/2.2); @@ -198,6 +211,19 @@ vec4 toGamma(vec4 _rgba) return vec4(toGamma(_rgba.xyz), _rgba.w); } +vec3 toGammaAccurate(vec3 _rgb) +{ + vec3 lo = _rgb * 12.92; + vec3 hi = pow(abs(_rgb), vec3_splat(1.0/2.4) ) * 1.055 - 0.055; + vec3 rgb = mix(hi, lo, vec3(lessThanEqual(_rgb, vec3_splat(0.0031308) ) ) ); + return rgb; +} + +vec4 toGammaAccurate(vec4 _rgba) +{ + return vec4(toGammaAccurate(_rgba.xyz), _rgba.w); +} + vec3 toReinhard(vec3 _rgb) { return toGamma(_rgb/(_rgb+vec3_splat(1.0) ) );