]> git.tdb.fi Git - libs/gl.git/blobdiff - shaderlib/colorcurve.glsl
Move postprocessor shaders to the builtin shaderlib
[libs/gl.git] / shaderlib / colorcurve.glsl
diff --git a/shaderlib/colorcurve.glsl b/shaderlib/colorcurve.glsl
new file mode 100644 (file)
index 0000000..fa3ba51
--- /dev/null
@@ -0,0 +1,29 @@
+import postprocess;
+
+uniform sampler1D curve;
+uniform ToneMapping
+{
+       float peak;
+       float brightness;
+};
+
+////// fragment
+void main()
+{
+       vec4 sample = texture(source, texcoord);
+       float maxc = max(sample.r, max(sample.g, sample.b));
+       if(maxc>1.0-peak)
+       {
+               vec3 saturated = sample.rgb/maxc;
+               if(maxc>1.0+peak)
+               {
+                       sample.rgb = mix(vec3(1.0), saturated, 1.0/pow(brightness, maxc-1.0-peak));
+               }
+               else
+               {
+                       float x = (1.0+peak-maxc)/(2.0*peak);
+                       sample.rgb = saturated.rgb*(1.0-peak+(1.0-x*x)*peak);
+               }
+       }
+       frag_color = vec4(texture(curve, sample.r).r, texture(curve, sample.g).r, texture(curve, sample.b).r, sample.a);
+}