X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=gamma_expansion_effect.frag;h=359b026450c916f52d9f486bac11c2f6dcff3b71;hp=473365627011a4a265922a0dd0fd863b2bd7f7a4;hb=9a00101dbb6f98d21c6b8ce4d33200af840ea908;hpb=b61cd4cf5535ecfd76d5c923ea7421a8282bf98b;ds=sidebyside diff --git a/gamma_expansion_effect.frag b/gamma_expansion_effect.frag index 4733656..359b026 100644 --- a/gamma_expansion_effect.frag +++ b/gamma_expansion_effect.frag @@ -1,11 +1,19 @@ // Expand gamma curve. +uniform float PREFIX(linear_scale); +uniform float PREFIX(c0), PREFIX(c1), PREFIX(c2), PREFIX(c3), PREFIX(c4); +uniform float PREFIX(beta); + vec4 FUNCNAME(vec2 tc) { vec4 x = INPUT(tc); - 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 a = x.rgb * PREFIX(linear_scale); + + // Fourth-order polynomial approximation to pow(). See the .cpp file for details. + vec3 b = PREFIX(c0) + (PREFIX(c1) + (PREFIX(c2) + (PREFIX(c3) + PREFIX(c4) * x.rgb) * x.rgb) * x.rgb) * x.rgb; + + vec3 f = vec3(greaterThan(x.rgb, vec3(PREFIX(beta)))); + x = vec4(mix(a, b, f), x.a); return x; }