]> git.tdb.fi Git - libs/gl.git/blob - shaderlib/colorcurve.glsl
Move postprocessor shaders to the builtin shaderlib
[libs/gl.git] / shaderlib / colorcurve.glsl
1 import postprocess;
2
3 uniform sampler1D curve;
4 uniform ToneMapping
5 {
6         float peak;
7         float brightness;
8 };
9
10 ////// fragment
11 void main()
12 {
13         vec4 sample = texture(source, texcoord);
14         float maxc = max(sample.r, max(sample.g, sample.b));
15         if(maxc>1.0-peak)
16         {
17                 vec3 saturated = sample.rgb/maxc;
18                 if(maxc>1.0+peak)
19                 {
20                         sample.rgb = mix(vec3(1.0), saturated, 1.0/pow(brightness, maxc-1.0-peak));
21                 }
22                 else
23                 {
24                         float x = (1.0+peak-maxc)/(2.0*peak);
25                         sample.rgb = saturated.rgb*(1.0-peak+(1.0-x*x)*peak);
26                 }
27         }
28         frag_color = vec4(texture(curve, sample.r).r, texture(curve, sample.g).r, texture(curve, sample.b).r, sample.a);
29 }