mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
28.34k stars 2.91k forks source link

Squarish artifacts when using antiring with a Polar downscaler. #12375

Closed Isaacx123 closed 1 year ago

Isaacx123 commented 1 year ago

Important Information

Polar filters

Provide following Information:

Reference screenshot downscaled with Mitchell:

reference

Screenshot with artifacts downscaled with EWA_RobidouxSharp plus AR at 0.5 strength:

ewa_robidouxsharp+ar

Screenshot without artifacts downscaled with EWA_RobidouxSharp and no AR:

mpv-shot0001

It also happens with non-Cubic/Mitchell-Netravali filters like EWA_Lanczos:

mpv-shot0002

The artifacts become more evident with a higher AR strength, EWA_RobidouxSharp plus AR at 1.0 strength:

mpv-shot0003

Orthogonal filters like Catmull_Rom or Mitchell don't present any issues, Catmull_Rom plus AR at 0.5 strength:

mpv-shot0004

Reproduction steps

mpv --no-config --vo=gpu-next --gpu-api=vulkan --correct-downscaling=yes --linear-downscaling=yes --dscale=mitchell --autofit=1760x990 --log-file=mpv.log --screenshot-format=png --screenshot-high-bit-depth=no test-clip.mkv

mpv --no-config --vo=gpu-next --gpu-api=vulkan --correct-downscaling=yes --linear-downscaling=yes --dscale=ewa_robidouxsharp --scale-antiring=0.5 --autofit=1760x990 --log-file=mpv.log --screenshot-format=png --screenshot-high-bit-depth=no test-clip.mkv

mpv --no-config --vo=gpu-next --gpu-api=vulkan --correct-downscaling=yes --linear-downscaling=yes --dscale=ewa_lanczos --scale-antiring=0.5 --autofit=1760x990 --log-file=mpv.log --screenshot-format=png --screenshot-high-bit-depth=no test-clip.mkv

mpv --no-config --vo=gpu-next --gpu-api=vulkan --correct-downscaling=yes --linear-downscaling=yes --dscale=ewa_robidouxsharp --scale-antiring=1 --autofit=1760x990 --log-file=mpv.log --screenshot-format=png --screenshot-high-bit-depth=no test-clip.mkv

mpv --no-config --vo=gpu-next --gpu-api=vulkan --correct-downscaling=yes --linear-downscaling=yes --dscale=catmull_rom --scale-antiring=0.5 --autofit=1760x990 --log-file=mpv.log --screenshot-format=png --screenshot-high-bit-depth=no test-clip.mkv

Expected behavior

Downscaling without artifacts while AR is active.

Actual behavior

Dithering like squarish artifacts.

Log file

ewa_robidouxsharp+ar50.log

catmull_rom+ar50.log

Sample files

https://0x0.st/Hffj.mkv

Isaacx123 commented 1 year ago

Forgot to add that the artifacts become bigger or smaller depending on the target resolution:

Bigger artifacts at 1046p: mpv-shot0002

Smaller artifacts at 810p: mpv-shot0001

Artoriuz commented 1 year ago

Can you reproduce it with this shader as well (turn the native AR off if you want to give it a shot)?

Isaacx123 commented 1 year ago

The shader does not exhibit any artifacts when downscaling with a Polar filter:

mpv --no-config --vo=gpu-next --gpu-api=vulkan --correct-downscaling=yes --linear-downscaling=yes --dscale=ewa_robidouxsharp --glsl-shader=PixelClipper.glsl --autofit=1760x990 --log-file=mpv.log --screenshot-format=png --screenshot-high-bit-depth=no test-clip.mkv

mpv-shot0001

mpv.log

bjin commented 1 year ago

The following patch (to libplacebo) fixed the artifacts for me:

diff --git a/src/shaders/sampling.c b/src/shaders/sampling.c
index efa69dd8..53ea52bd 100644
--- a/src/shaders/sampling.c
+++ b/src/shaders/sampling.c
@@ -480,7 +480,7 @@ static void polar_sample(pl_shader sh, pl_filter filter,
             @for (c : comp_mask) {                              \
                 cc = vec2(${float: scale} * c[@c]);             \
                 cc.x = 1.0 - cc.x;                              \
-                ww = cc + vec2(0.07);                           \
+                ww = cc + vec2(0.08);                           \
                 ww = ww * ww;                                   \
                 ww = ww * ww;                                   \
                 ww = ww * ww;                                   \

It seems that 0.07^33 underflows the range of float32 by just a little bit, and this issue becoming even more problematic with --linear-downscaling (sample value much closer to zero).

EDIT: posted a PR at https://code.videolan.org/videolan/libplacebo/-/merge_requests/579

aicynide commented 1 year ago

Thanks bjin