hhirtz / mpv-retro-shaders

mpv ports of some libretro shaders for use with native-resolution encodes of Tool Assisted Speedruns
Other
34 stars 2 forks source link

Artifacting with `crt-guest-advanced-ntsc.glsl` #1

Closed ghost closed 8 months ago

ghost commented 9 months ago

First of all, thank you for sharing these shader ports! Being able to use libretro shaders in mpv natively is extremely convenient.

When using crt-guest-advanced-ntsc.glsl, I'm encountering artifacting during playback. It's also important to note that I'm on Windows and --gpu-api=d3d11 doesn't seem to work without --vo=gpu-next since it can't configure to a rgb8 format on vo_gpu. I can still reproduce these artifacts on opengl and vulkan regardless of vo though. Changing LUT size in the shader params also doesn't seem to help (if anything, it makes the issue worse).

Sample I used: https://tasvideos.org/2894M mpv ver: v0.37.0-147-g41259db9 mpv log file (if it's helpful): mpv.log

Screenshots and commands

mpv --no-config --vo=gpu-next --gpu-api=vulkan --profile=fast --window-scale=3

mpv-shot0002

mpv --no-config --vo=gpu-next --gpu-api=vulkan --profile=fast --glsl-shaders="C:\path\to\my\shaders\crt-guest-advanced-ntsc.glsl" --window-scale=3

mpv-shot0001

hhirtz commented 9 months ago

That's weird. There's no artifacts on linux+intel uhd graphics and the command-line you provided.

Does it work if you launch mpv with intel graphics/power saving mode? (seeing from your mpv.log that mpv uses amd radeon graphics) Maybe there's a bug in the shader port that triggers this issue for some drivers or something.

ghost commented 9 months ago

I have access to a system with an Intel iGPU (Xe architecture) and it still exhibits similar artifacting. Assuming all other variables are eliminated (mpv version, libplacebo version etc.) then it's likely something Windows related?

If it is Windows related, I obviously don't expect you to upheave your entire system to diagnose the problem, so feel free to close this issue. Unfortunate, but it is what it is. The lottes port works just fine for my usecase.

amlib commented 8 months ago

I'm on linux with amdgpu and I have the same issue. The crt-lottes shader works fine.

hhirtz commented 8 months ago

Ok, actually libretro feeds shaders linear RGB while mpv uses sRGB, so we need to linearize MAIN and then delinearize the shader output. I pushed a fix on master: https://github.com/hhirtz/mpv-retro-shaders/commit/72e3ce87d5427132f047b1a99aa8d46add3a451a

Feel free to reopen the issue persists

amlib commented 8 months ago

Hey, I was about to post a workaround where increasing or decreasing the gamma on mpv "fixed" the issue. Anyway, disregarding that, I went to try the new version and now the guest shader does not seems to have any effect at all. I've triple checked everything. Crt-lottes still works fine, not sure what it could be.

Also, since we are communicating here I would like to point out a config adjustment that may improve video quality. Since most videos are encoded with chroma sub sampling you do not want to feed that into the shader. It is very important to force converting to a non subsampled pixel format before sending it to the shader. This is specially useful if you are decimating 240p video encoded in standard 1080p video (like youtube). If you don't convert to a 444 or rgb format you will get severe chroma spillage everywhere.

There are tons of pix formats you can list with mpv --vf=format=fmt=help, but I've chosen to use rgba or yuv444p.

You can then covert to an appropriate pixel format with this parameter:

#PIX_FORMAT="rgba"
PIX_FORMAT="yuv444p"
'--vf=format=convert=yes:fmt='"$PIX_FORMAT"

And here is how I decimate the input video for the sweet 240p pixels. Finding the exact values is a bit convoluted and involves pixel counting, finding ratios, taking into account the vertical overscan and the empty horizontal area left in a 16:9 video embedding 4:3 stuff. It will be different on every video, so, this is just a baseline:

#PIX_FORMAT="rgba"
PIX_FORMAT="yuv444p"
H_SCALE="342"
V_SCALE="224"
'--vf=format=convert=yes:fmt='"$PIX_FORMAT"',lavfi="scale='"$H_SCALE"':'"$V_SCALE"':flags=neighbor"'
hhirtz commented 8 months ago

That's neat, thank you for the tip! I will add this to the readme. Really cool to be able to watch videos directly from youtube with the shaders.

Anyway, disregarding that, I went to try the new version and now the guest shader does not seems to have any effect at all.

Best guess would be you need to add crt-guest-advanced-ntsc-textures.glsl to the shader list. I split it off in a later commit because syntax highlighting takes 100% cpu otherwise, and github's ui could not open the file.

If you're on a shell:

mpv --glsl-shader=path/to/shaders/crt-guest-advanced-ntsc{,-textures}.glsl
amlib commented 8 months ago

I've found a workaround to the issue by setting --vo to gpu. Previously I was using gpu-next, seems like there is some incompatibility specifically with crt-guest as lottes works ok on both. It may be a bug in mpv so I don't think it's is worth it to look into it.