X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=gamma_expansion_effect.frag;h=b8e3581f53772107880d9b90b68981a95e9f35d9;hp=4a5db9e178d53abbdc0c22a76a3c0c439baab564;hb=f216b7bef5a968c89f6fc78e83cc26a91e504a8a;hpb=2ced784c6599cb0b21427481ee17f4c8f6afdada diff --git a/gamma_expansion_effect.frag b/gamma_expansion_effect.frag index 4a5db9e..b8e3581 100644 --- a/gamma_expansion_effect.frag +++ b/gamma_expansion_effect.frag @@ -1,11 +1,20 @@ -// Expand sRGB gamma curve. +// Expand gamma curve. + +// Implicit uniforms: +// uniform float PREFIX(linear_scale); +// uniform float PREFIX(c)[5]; +// uniform float PREFIX(beta); vec4 FUNCNAME(vec2 tc) { - vec4 x = LAST_INPUT(tc); + vec4 x = INPUT(tc); + + vec3 a = x.rgb * PREFIX(linear_scale); + + // Fourth-order polynomial approximation to pow(). See the .cpp file for details. + vec3 b = PREFIX(c[0]) + (PREFIX(c[1]) + (PREFIX(c[2]) + (PREFIX(c[3]) + PREFIX(c[4]) * x.rgb) * x.rgb) * x.rgb) * x.rgb; - x.r = texture1D(PREFIX(expansion_curve_tex), x.r).x; - x.g = texture1D(PREFIX(expansion_curve_tex), x.g).x; - x.b = texture1D(PREFIX(expansion_curve_tex), x.b).x; + vec3 f = vec3(greaterThan(x.rgb, vec3(PREFIX(beta)))); + x = vec4(mix(a, b, f), x.a); return x; }