]> git.sesse.net Git - movit/blob - lift_gamma_gain_effect.glsl
Slight cleanup in texture upload format selection.
[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         x.rgb = pow(x.rgb, vec3(1.0/2.2));
16         x.rgb += PREFIX(lift) * (vec3(1) - x.rgb);
17         x.rgb = pow(x.rgb, PREFIX(inv_gamma_22));
18         x.rgb *= PREFIX(gain_pow_inv_gamma);
19
20         return x;
21 }