]> git.sesse.net Git - movit/blob - dither_effect.frag
Properly ignore the sign bit when comparing NaNs.
[movit] / dither_effect.frag
1 uniform sampler2D PREFIX(dither_tex);
2 uniform vec2 PREFIX(tc_scale);
3 uniform float PREFIX(round_fac), PREFIX(inv_round_fac);
4
5 vec4 FUNCNAME(vec2 tc) {
6         vec4 result = INPUT(tc);
7
8         // Don't dither alpha; the case of alpha=255 (1.0) is very important to us,
9         // and if there's any inaccuracy earlier in the chain so that it becomes e.g.
10         // 254.8, it's better to just get it rounded off than to dither and have it
11         // possibly get down to 254. This is not the case for the color components.
12         result.rgb += texture2D(PREFIX(dither_tex), tc * PREFIX(tc_scale)).xxx;
13
14         // NEED_EXPLICIT_ROUND will be #defined to 1 if the GPU has inaccurate
15         // fp32 -> int8 framebuffer rounding, and 0 otherwise.
16 #if NEED_EXPLICIT_ROUND
17         result = round(result * vec4(PREFIX(round_fac))) * vec4(PREFIX(inv_round_fac));
18 #endif
19
20         return result;
21 }