X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=dither_effect.frag;h=f9c6ad13c443e1919c4506790159c9134106d8a7;hp=9b39553099e314c940fb1401649517346910c6e1;hb=85f9719bf3519b1f1942738d11601584f5d38725;hpb=ff9e68a3f5abb179bd7bf9fb84df48327f148583 diff --git a/dither_effect.frag b/dither_effect.frag index 9b39553..f9c6ad1 100644 --- a/dither_effect.frag +++ b/dither_effect.frag @@ -1,9 +1,18 @@ uniform sampler2D PREFIX(dither_tex); +uniform vec2 PREFIX(tc_scale); +uniform float PREFIX(round_fac), PREFIX(inv_round_fac); vec4 FUNCNAME(vec2 tc) { // We also choose to dither alpha, just in case. // Maybe it should in theory have a separate dither, - // but I doubt it matters much. We currently don't - // really handle alpha in any case. - return INPUT(tc) + texture2D(PREFIX(dither_tex), tc).xxxx; + // but I doubt it matters much. + vec4 result = INPUT(tc) + texture2D(PREFIX(dither_tex), tc * PREFIX(tc_scale)).xxxx; + + // NEED_EXPLICIT_ROUND will be #defined to 1 if the GPU has inaccurate + // fp32 -> int8 framebuffer rounding, and 0 otherwise. +#if NEED_EXPLICIT_ROUND + result = round(result * vec4(PREFIX(round_fac))) * vec4(PREFIX(inv_round_fac)); +#endif + + return result; }