Raspberry Pi friendly CRT shader

[QUOTE=dave j;38908] @dankcussions The crt-pi-mask was to help people create overlays but since you can get the same functionality by loading the 240p test suite with the crt-pi shader I consider it redundant. Similarly with the crt-pi-barrel shader. It does curved screens but without any extra processing so you get aliasing. The crt-pi shader can be configured to do curved screen without scanlines but with anti-aliasing (described in this post). Unless anybody is particularly keen on them, I can see no reason not to remove them.[/QUOTE]

great work! tested and works great.

my only thought is that maybe it’s better to have a separate version of the shader that has the barrel turned on, to make it an obvious option to users. would you be averse to me doing the edit to turn on the barrel, and storing that as a separate crt-pi-barrel.glslp in the retropie shader repo? maybe a crt-pi-barrel-vertical.glslp as well I suppose!

EDIT: also, as a thought - should any potential barrel/curvature version also have the multisample param uncommented, to cut down the aliasing? or is curve + multisample + scanlines too much for the pi? i tried it just with curvature + scanlines and it looked fine, albeit obvious jaggies around the edge.

Thanks Dave J for such an awesome shader, love it! All my RetroPie Libretro cores are using it. So these new changes will make it to the RetroPie Repo? I would second the shaders be broken out as I wouldn’t mind the extra files in the subdirectory vs. tweaking.

Hi !

Out of curiosity, owning a Pi 3, I enabled the hi resolution mode for the libretro-pcsx-rearmed by following those instructions : https://github.com/retropie/retropie-setup/wiki/playstation-1 and made tests along with the crt-pi shader.

It gives a great improvement to 3D objects. However it doesn’t play along well with 2D objects ; which is understandable as the shader is not applied to the 2D objects in their original resolution. 2D objects look better with the lowres mode + your shader than the highres mode + your shader.

What do you think ? Can something be tweaked especially for the PSX ?

Thanks again for you work on the shader. It makes such a difference !

[QUOTE=bidinou;40216]It gives a great improvement to 3D objects. However it doesn’t play along well with 2D objects ; which is understandable as the shader is not applied to the 2D objects in their original resolution. 2D objects look better with the lowres mode + your shader than the highres mode + your shader.

What do you think ? Can something be tweaked especially for the PSX ?[/QUOTE] Doing that would require figuring out whether each pixel being drawn is part of a 3D object or a 2D one and that is a hard problem to do reliably. Hyllian did something similar with upscaling shaders for 2D stuff - see Filtering games with 2D and 3D elements.

It’s way beyond what is practical for the Pi’s GPU to do.

Indeed ! Couldn’t pcsx just apply bilinear filtering to 2D textures ? It would help. Anyway, I’m off topic :slight_smile:

I believe bilinear filtering is available in the latest versions of mednafen/beetle-psx and generally looks terrible. There’s also n64-style 3-point bilinear, which looks better in some cases.

May I ask a very last semi-off-topic question regarding pcsx & crt-pi ?

Some PSX games look amazing in low-res + crt-pi shaders. (pure 2D ones) Some half 2D half 3D look OK in both low-res + crt-pi and high-res (neon enhanced) + crt-pi.

But pure 3D games look much better in hi-res (neon enhanced). I played a little with my daughter some 3D titles in low-res. My eyeballs hurt :slight_smile:

However, the neon enhancement switch apparently cannot be specified in the game config file : it is located in the “core” retroarch options config file.

Is there a way to enable / disable it on a per game basis ?

Yes, in recent builds of RetroArch, you can set up per-game core options automatically through the GUI (settings > configuration > use per-game core options if available ON)

Hmm, if someone could give me an example… I tried to tweak my retroarch config to add this option (through the gui and also by hand) but for some reason it always ended destroying my cfg file (retroarch would quit instantly) and also I don’t know the naming scheme of the per-game core options :slight_smile: I googled and search quite a bit, really :slight_smile:

Just go to settings > configuration and turn on ‘user per-game core options if available’. Then, load up some content, go into the quick menu, go down to ‘options,’ and then the first option should say “Create game-options file” with the name of the game off to the right. Press ‘accept’ (retropad-A by default) and it will create the structure and everything for you in your config directory.

Thanks ! It’s supposed to retain all my previously tweaked options from the config file ? The only drawback is that it loses all the comments in the config file, which are pretty handy, but there’s a backup for reference anyway. Thanks again !

Yeah, it’ll save whatever the current options are, which should include whatever your normal options would be.

I have my retropie all setup. All is working great, how do I add this shader and how do I add the retroarch to my emulator options? Sorry I’m a noob but learning. Thanks

Retropie is mostly RetroArch plus EmulationStation. Any time you’re using lr-something in Retropie, it’s using RetroArch.

You should be able to download the shader from RetroArch’s online updater. If that’s not available for whatever reason, you can download it from my repo:

Once you have it, go to the menu, go to shader options and then ‘load shader preset’ and navigate to crt/crt-pi.glslp. You can also enable it in your retroarch.cfg by changing these lines: video_shader_enable = “true” video_shader = /path/to/crt-pi.glslp

[QUOTE=hunterk;41425]Retropie is mostly RetroArch plus EmulationStation. Any time you’re using lr-something in Retropie, it’s using RetroArch.

You should be able to download the shader from RetroArch’s online updater. If that’s not available for whatever reason, you can download it from my repo:

Once you have it, go to the menu, go to shader options and then ‘load shader preset’ and navigate to crt/crt-pi.glslp. You can also enable it in your retroarch.cfg by changing these lines: video_shader_enable = “true” video_shader = /path/to/crt-pi.glslp[/QUOTE]

Thank you for clearing that up for me, I really appreciate it!

If you have RetroPie installed, you can just select the shader (its already installed) using the configuration editor.

You can see in the screenshots there to enable the shader.

How do I achieve perfect image quality like OP’s screenshots? The scanlines doesn’t look right on my 1080p TV (I’m using Retropie 4.0 with a Pi 3b). It’s like there’s a darker/wider line every 4 or 5…

You need to enable integer scaling in the video settings. This leaves small black borders on the top and bottom but it’s the only way to get perfectly even scanlines.

I also don’t think nearest neighbor is enabled by default on that shader so things are bit blurry. Maybe set linear to false by default? Or would that take up to much GPU? Maybe it is just my personal preference. :slight_smile:

This shader requires linear filtering to work properly. With nearest filtering you get different pixel widths and line heights - although the latter is largely hidden by the scan line effect. Try turning curvature on and looking at adjacent horizontal lies of contrasting colours. With nearest filtering you also get very square ends to pixels rather than more rounded ends like you do with a real CRT display.

Technical explanation (because I know some of you like reading about this sort of thing).

With non integer scaling, nearest filtering will result in varying pixel widths and line heights. Most shaders get round this by reading multiple pixels and blending them together. Most CRT shaders seem to read four pixels along a scan line and blend them together to get even pixel widths. To get even line heights, they do the same for the the scan line below and then merge the two results together. This takes a lot of processing in the shader which the Pi’s GPU can’t spare.

To avoid this but still get a similar effect, instead of reading multiple pixels and blending them together in the shader, crt-pi alters the texture coordinates (which is fast) and reads a single pixel - relying on hardware linear filtering (which is very fast) to blend the values together. By default, it doesn’t alter the horizontal coordinate so you get a simple linear blend (which is relatively blurry). If you enable sharper in the shader it alters the horizontal coordinate in a similar way to the way it does the vertical coordinate. The later gives a sharper transition (it looks similar to that in screenshots of a BVM monitor) but the additional calculations are just enough to cause dropped frames. Pi3s, and earlier Pis with overclocked GPUs, can probably run with sharper without dropping frames but I haven’t tried it.