]> git.sesse.net Git - movit/blob - gamma_compression_effect.frag
Let the application manage PBOs.
[movit] / gamma_compression_effect.frag
1 // Compress gamma curve.
2
3 uniform float PREFIX(linear_scale);
4 uniform float PREFIX(c0), PREFIX(c1), PREFIX(c2), PREFIX(c3), PREFIX(c4);
5 uniform float PREFIX(beta);
6
7 vec4 FUNCNAME(vec2 tc) {
8         vec4 x = INPUT(tc);
9
10         // We could reasonably get values outside (0.0, 1.0), but the formulas below
11         // are not valid outside that range, so clamp before we do anything else.
12         x.rgb = clamp(x.rgb, 0.0, 1.0);
13
14         vec3 a = x.rgb * PREFIX(linear_scale);
15
16         // Fourth-order polynomial approximation to pow(). See the .cpp file for details.
17         vec3 s = sqrt(x.rgb);
18         vec3 b = PREFIX(c0) + (PREFIX(c1) + (PREFIX(c2) + (PREFIX(c3) + PREFIX(c4) * s) * s) * s) * s;
19
20         vec3 f = vec3(greaterThan(x.rgb, vec3(PREFIX(beta))));
21         x = vec4(mix(a, b, f), x.a);
22
23         return x;
24 }