X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=lift_gamma_gain_effect.frag;h=7342d7505eb53da6e66167b4921138ef2f5a68dc;hp=80e04d0659d52969bc287ffa3d96dca4010e129d;hb=f216b7bef5a968c89f6fc78e83cc26a91e504a8a;hpb=d4542f76df5d26843c68b1467e76722cffd801a1 diff --git a/lift_gamma_gain_effect.frag b/lift_gamma_gain_effect.frag index 80e04d0..7342d75 100644 --- a/lift_gamma_gain_effect.frag +++ b/lift_gamma_gain_effect.frag @@ -1,21 +1,22 @@ -// Standard lift/gamma/gain color correction tools. +// Implicit uniforms: // -// We do lift in a nonlinear (gamma-2.2) space since that looks a lot better -// than in linear (blacks stay a lot closer to black). The two others don't -// really care; they are (sans some constants) commutative with the x^2.2 -// operation. - // These are calculated in the host code to save some arithmetic. -uniform vec3 PREFIX(gain_pow_inv_gamma); // gain^(1/gamma). -uniform vec3 PREFIX(inv_gamma_22); // 2.2 / gamma. +// uniform vec3 PREFIX(gain_pow_inv_gamma); // gain^(1/gamma). +// uniform vec3 PREFIX(inv_gamma_22); // 2.2 / gamma. vec4 FUNCNAME(vec2 tc) { - vec4 x = LAST_INPUT(tc); + vec4 x = INPUT(tc); + + x.rgb /= x.aaa; + + // pow() of negative numbers is undefined, so clip out-of-gamut values. + x.rgb = max(x.rgb, 0.0); x.rgb = pow(x.rgb, vec3(1.0/2.2)); x.rgb += PREFIX(lift) * (vec3(1) - x.rgb); x.rgb = pow(x.rgb, PREFIX(inv_gamma_22)); x.rgb *= PREFIX(gain_pow_inv_gamma); + x.rgb *= x.aaa; return x; }