X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=dither_effect.frag;h=f271b633c24edea92c54ac38f626cad2d28872a6;hp=b12ecd7cedfd267d8a9935a2372303c9f62e3be9;hb=6bec5fc3abc5f57c6cddec2148626cca9a94bedf;hpb=6bf496a34a84fb14b1b3b6debfd42ba36568b879 diff --git a/dither_effect.frag b/dither_effect.frag index b12ecd7..f271b63 100644 --- a/dither_effect.frag +++ b/dither_effect.frag @@ -3,14 +3,36 @@ // uniform vec2 PREFIX(tc_scale); // uniform float PREFIX(round_fac), PREFIX(inv_round_fac); +#if YCBCR_ALSO_OUTPUT_RGBA + +// There are two values to dither; otherwise, exactly the same as the algorithm below +// (so comments are not duplicated). + +vec4[2] FUNCNAME(vec2 tc) { + vec4[2] result = INPUT(tc); + float d = tex2D(PREFIX(dither_tex), tc * PREFIX(tc_scale)).x; + result[0].rgb += vec3(d); + result[1].rgb += vec3(d); + +#if NEED_EXPLICIT_ROUND + result[0] = round(result[0] * vec4(PREFIX(round_fac))) * vec4(PREFIX(inv_round_fac)); + result[1] = round(result[1] * vec4(PREFIX(round_fac))) * vec4(PREFIX(inv_round_fac)); +#endif + + return result; +} + +#else + vec4 FUNCNAME(vec2 tc) { vec4 result = INPUT(tc); + float d = tex2D(PREFIX(dither_tex), tc * PREFIX(tc_scale)).x; // Don't dither alpha; the case of alpha=255 (1.0) is very important to us, // and if there's any inaccuracy earlier in the chain so that it becomes e.g. // 254.8, it's better to just get it rounded off than to dither and have it // possibly get down to 254. This is not the case for the color components. - result.rgb += tex2D(PREFIX(dither_tex), tc * PREFIX(tc_scale)).xxx; + result.rgb += vec3(d); // NEED_EXPLICIT_ROUND will be #defined to 1 if the GPU has inaccurate // fp32 -> int8 framebuffer rounding, and 0 otherwise. @@ -20,3 +42,5 @@ vec4 FUNCNAME(vec2 tc) { return result; } + +#endif