From d6ee569963d3e1ab005e6852f44e4175fd518b8e Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 25 Apr 2016 23:52:33 -0400 Subject: [PATCH] Add sRGB conversions to shaders. --- libraries/gpu/src/gpu/Color.slh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libraries/gpu/src/gpu/Color.slh b/libraries/gpu/src/gpu/Color.slh index d4d9ba7b81..4330b34b90 100644 --- a/libraries/gpu/src/gpu/Color.slh +++ b/libraries/gpu/src/gpu/Color.slh @@ -11,9 +11,14 @@ <@if not GPU_COLOR_SLH@> <@def GPU_COLOR_SLH@> +float sRGBFloatToLinear(float value) { + const float SRGB_ELBOW = 0.04045; + + return (value <= SRGB_ELBOW) ? value / 12.92 : pow((value + 0.055) / 1.055, 2.4); +} + vec3 colorToLinearRGB(vec3 srgb) { - const float GAMMA_22 = 2.2; - return pow(srgb, vec3(GAMMA_22)); + return vec3(sRGBFloatToLinear(srgb.r), sRGBFloatToLinear(srgb.g), sRGBFloatToLinear(srgb.b)); } vec4 colorToLinearRGBA(vec4 srgba) {