]> git.sesse.net Git - movit/blobdiff - gamma_compression_effect_srgb.glsl
Squash linear gamma back into the sRGB curve at the end.
[movit] / gamma_compression_effect_srgb.glsl
diff --git a/gamma_compression_effect_srgb.glsl b/gamma_compression_effect_srgb.glsl
new file mode 100644 (file)
index 0000000..2d53e08
--- /dev/null
@@ -0,0 +1,31 @@
+// Compress to sRGB gamma curve.
+
+#if 0
+
+// if we have the lut
+uniform sampler1D PREFIX(srgb_tex);
+
+vec4 FUNCNAME(vec2 tc) {
+       vec4 x = LAST_INPUT(tc);
+
+       x.r = texture1D(PREFIX(srgb_tex), x.r).x;
+       x.g = texture1D(PREFIX(srgb_tex), x.g).x;
+       x.b = texture1D(PREFIX(srgb_tex), x.b).x;
+
+       return x;
+}
+
+#else
+
+// use arithmetic (slow)
+vec4 FUNCNAME(vec2 tc) {
+       vec4 x = LAST_INPUT(tc);
+
+       vec3 a = vec3(12.92) * x.rgb;
+       vec3 b = vec3(1.055) * pow(x.rgb, vec3(1.0/2.4)) - vec3(0.055);
+       vec3 f = vec3(greaterThan(x.rgb, vec3(0.0031308)));
+
+       return vec4(mix(a, b, f), x.a); 
+}
+#endif