]> git.sesse.net Git - movit/blob - lift_gamma_gain_effect.glsl
7804f85a57e8f85621f417d09e9463ee6bd36596
[movit] / lift_gamma_gain_effect.glsl
1 // Standard lift/gamma/gain color correction tools.
2 //
3 // We do lift in a nonlinear (gamma-2.2) space since that looks a lot better
4 // than in linear (blacks stay a lot closer to black). The two others don't
5 // really care; they are (sans some constants) commutative with the x^2.2
6 // operation.
7
8 // These are calculated in the host code to save some arithmetic.
9 uniform vec3 PREFIX(gain_pow_inv_gamma);  // gain^(1/gamma).
10 uniform vec3 PREFIX(inv_gamma_22);  // 2.2 / gamma.
11
12 vec4 FUNCNAME(vec2 tc) {
13         vec4 x = LAST_INPUT(tc);
14
15         // do lift in nonlinear space (the others don't care)
16         x.rgb = pow(x.rgb, vec3(1.0/2.2));
17         x.rgb += PREFIX(lift) * (vec3(1) - x.rgb);
18         x.rgb = pow(x.rgb, PREFIX(inv_gamma_22));
19         x.rgb *= PREFIX(gain_pow_inv_gamma);
20
21         return x;
22 }