crt-pi a Pi2 friendly CRT shader

Welcome Page Forums RetroPie Project Video Output on RetroPie crt-pi a Pi2 friendly CRT shader

This topic contains 13 replies, has 8 voices, and was last updated by Profile photo of nitrogenwidget nitrogenwidget 1 year, 2 months ago.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #109836
    Profile photo of davej
    davej
    Participant

    Here is the Pi2 friendly CRT shader I promised in another thread.

    It does:

    Curved screens.
    Scan lines that match the curved screen.
    Multi-sampling to reduce the effects of moire.
    Scan line bloom (brighter lines are wider).

    All while keeping a high frame rate. (I might have been a bit optimistic aiming for 1080P@60Hz but it’s faster that all those shaders that do scan lines and curved screens.)

    I’ve abandoned the two fancy filtering effects I’d been trying. The simple one I had originally planned to use looks just as good and is a bit faster. Turning off the screen curvature and multi-sampling speeds things up a bit too.

    The shader itself is called crt-pi.

    Unzip the file into your shaders/crt directory

    The zip file also includes two bonus shaders:

    crt-pi-barrel is the screen curvature only shader I posted about a month ago updated to allow different levels of distortion horizontally and vertically.

    crt-pi-mask is to help people producing overlays. It ignores the contents of the game screen and displays black pixels where the screen should be and white pixels where the border would be. Take a screen shot of this and it’s the perfect shape to be used a mask for defining the hole for the screen area in an overlay.

    Let me know what you think.

    davej

    Attachments:
    1. crt-pi.zip
    #109841
    Profile photo of Floob
    Floob
    Member

    Really impressive. I like it!

    I’ve put a quick video together here showing it in action

    RetroPie help guides --> https://goo.gl/Yfy8kj
    Please read this before asking for help --> http://goo.gl/eLErnl

    #109854
    Profile photo of stathman
    stathman
    Participant

    Thanks a lot!

    This is by far the most pleasing to my eyes shader and it is not slowing things down.

    Well done!

    Is it possible to skip the screen distortion somehow?

    Thanks again.

    Pi Model: 2 B
    RetroPie Version Used: 3.2.1
    Built From: Binary
    USB Devices connected: jpac, wifi, keyboard

    #109870
    Profile photo of gizmo98
    gizmo98
    Participant

    Thank you davej!
    I have added your zip file to our shader repo. If retroarch is installed/updated from source all new shaders will be fetched. So everyone can test these shaders easily.
    https://github.com/gizmo98/common-shaders/commit/7097eb6b093dc0c7722a988553d741f30b45d4fc

    #109890
    Profile photo of davej
    davej
    Participant

    Is it possible to skip the screen distortion somehow?

    There are some variables set at the top of the shaders/crt-pi.glsl file that can be used to control some aspects of the shader.

    #define MULTISAMPLE
    #define CURVATURE
    #define BARREL_DISTORTION_X 0.15
    #define BARREL_DISTORTION_Y 0.25
    #define MASK_BRIGHTNESS 0.65
    #define SCAN_LINE_WEIGHT 6.0
    #define BLOOM_FACTOR 1.5
    #define INPUT_GAMMA 2.4
    #define OUTPUT_GAMMA 2.2

    You can change the curvature by changing the BARREL_DISTORTION_X and BARREL_DISTORTION_Y values (0.0 will turn it off for that dimension). Better, you can turn if off entirely by commenting out the CURVATURE line (put a double slash // at the start of the line). This will cause it to skip the distortion code and speeds up the shader a bit. The barrel and mask shaders can be similarly controlled but just have the BARREL_DISTORTION_X and BARREL_DISTORTION_Y values.

    You can similarly comment out the MULTISAMPLE line and speed things up a bit by skipping the multi-sample code – at the risk of increasing moire effects.

    MASK_BRIGHTNESS controls how bright the screen will be.

    You’re best leaving the others alone. Altering SCAN_LINE_WEIGHT and BLOOM_FACTOR will likely make moire effects worse. The two GAMMA values affect brightness and should not need changing on a correctly configured monitor (and if you monitor is not correctly configured, fixing that is a far better idea).

    It’s perhaps worth pointing out that the shader is designed to be used with linear filtering. CRT electron beams are not square and the combination of linear filtering with scan lines and bloom makes the edges of bright pixels next to dark pixels rounded which looks a bit more accurate. People are of course free to set filtering to nearest if they prefer.

    I’ll see if I can get the shader parameter editing that works with .cg shaders working with .glsl ones next week. The automatic conversion process normally used strips them out but I don’t know if that’s because they won’t work or just because it’s just a deficiency in the conversion process.

    davej

    #109920
    Profile photo of stathman
    stathman
    Participant

    Thanks for the info davej.

    Pi Model: 2 B
    RetroPie Version Used: 3.2.1
    Built From: Binary
    USB Devices connected: jpac, wifi, keyboard

    #110342
    Profile photo of davej
    davej
    Participant

    I’ve tried the shader configuration editing that CG shaders support with GLSL shaders and it does work, so here’s an updated version of my shaders. You can now edit most of the configuration parameters in RGUI.

    You can stop screen curvature by setting the two curvature values to 0.0 but, as before, commenting out the #define CURVATURE line is better as it runs faster. (It runs less code rather than runs code which has no effect.)

    Multi-sampling is still controlled by editing the shader file to disable code as well for similar reasons.

    I tried it with my early 256Mb Pi1 model B and it works pretty well on that (admittedly overclocked a 900Mhz) so it should be OK on a model A too.

    davej

    Attachments:
    1. crt-pi1.zip
    #110787
    Profile photo of patl
    patl
    Participant

    I recently tested your amazing filters.
    As you have already written, it is a bit too slow in 1080p.
    Only at a resolution of 1360×768 (most HD Ready devices) it’s really smooth, especially for SNES.
    But there is the problem with the colors of the scanlines if the display is curved.
    It is somewhat difficult to describe, so I made a screenshot.
    I’ve Played around with the filter something, to amplifies the effect.
    (but I can not really modify it)
    The effect occurs even at 1080p, due to the higher resolution, you can see it but barely.
    If the screen is not curved, the effect does not occur.
    Maybe you can calculate the scanlines in a different way.
    And it would be good if you could adjust the brightness of the scan lines.

    RetroArch-1127-112659

    Attachments:
    #110828
    Profile photo of davej
    davej
    Participant

    I recently tested your amazing filters.
    As you have already written, it is a bit too slow in 1080p.
    Only at a resolution of 1360×768 (most HD Ready devices) it’s really smooth, especially for SNES.
    But there is the problem with the colors of the scanlines if the display is curved.
    It is somewhat difficult to describe, so I made a screenshot.
    I’ve Played around with the filter something, to amplifies the effect.
    (but I can not really modify it)
    The effect occurs even at 1080p, due to the higher resolution, you can see it but barely.
    If the screen is not curved, the effect does not occur.
    Maybe you can calculate the scanlines in a different way.
    And it would be good if you could adjust the brightness of the scan lines.

    That’s the moire effect that comes from trying to display curved lines on a display with pixels in a straight line. Some displays show it more than others – one of my monitors barely shows it at all, another shows it a bit and on my TV it’s quite noticeable. Unfortunately the best you can do is try to minimize it if you can.

    Some things I did find helped with my TV that you might like to try:

    Don’t let the display do any scaling. i.e. Don’t set the Pi to a 720 screen mode and let the TV upscale to 1080. Run the Pi at the screen’s native resolution and set a viewport in Retroarch for the resolution you want. This will result in borders round screen but will produce a better picture.

    Setting the screen height to be either 3 times (for a 720 screen) or 4.5 times (for 1080) significantly reduced the moire effect. The easiest way for 3 times is to use integer scaling but you lose the 4:3 aspect ratio if you do that. The best way is to set a custom aspect ratio (Options->Video Options->Custom Ratio). 224×3 = 672 so you only lose 1/16th of the screen height on a 720 display (1/8th for 768). 4.5×224 = 1008 and you again lose 1/16th of the screen height on a 1080 display. To maintain a 4:3 aspect ratio you’d want to set custom ratios of 896×672 or 1344×1008.

    Stronger scan lines produce worse moire effects and the value chosen is designed to balance being visible whilst minimizing moire effects. The scan lines are based on those in the crt-geom shader (which seemed to have the best/least moire) and one of the optimizations I did to get my shader going as fast as it does was to simplify the maths around how they are calculated. Doing this lost the bits that allow them to be easily changed in crt-geom.

    #118382
    Profile photo of jamesthomas510
    jamesthomas510
    Participant

    I am new to raspberry pi. I downloaded the file, but I don’t know what to do from there. What file do I put them in and how do I apply those files in retropie?

    #120800
    Profile photo of mydriaze
    mydriaze
    Participant

    Hello,

    First, you have to put this file in the shader directory. You can upload it using FTP as described here: https://github.com/retropie/retropie-setup/wiki/Transferring-Roms

    Then, you simply have to edit the retroarch.cfg file in the \\RETROPIE\configs\all folder by modifying 2 lines. first, tell me if you succeed transferring your roms, then we will do the 2nd part. 🙂

    #120840
    Profile photo of jamesthomas510
    jamesthomas510
    Participant

    Yes, I have my roms transferred, I just need to learn how to have the crt shader to add the curvature to the screen.

    #120978
    Profile photo of mydriaze
    mydriaze
    Participant

    ok, go to your config folder and open retroarch.cfg:

    Look for this and modify false/true:

    # video_shader_enable = true

    # Smoothens picture with bilinear filtering. Should be disabled if using pixel shaders.
    video_smooth = false

      and:

    If you know exactly the shader you want to use for all your system, simply enter the right path :

    # Path to shader. Shader can be either Cg, CGP (Cg preset) or GLSL, GLSLP (GLSL preset)
    # video_shader = “/path/to/shader.{cg,cgp,glsl,glslp}”

    So, it will become:

    # Path to shader. Shader can be either Cg, CGP (Cg preset) or GLSL, GLSLP (GLSL preset)
    # video_shader = “/opt/retropie/emulators/retroarch/shader/crt-pi.glslp”

    If you want a specific shader for an emulator: first open the retroarch.cfg file in the system you want to launch:

    Example, for nes: \\RETROPIE\configs\nes\retroarch.cfg
    add simply this line:

    # Path to shader. Shader can be either Cg, CGP (Cg preset) or GLSL, GLSLP (GLSL preset)
    # video_shader = “/opt/retropie/emulators/retroarch/shader/crt-pi.glslp”

    #122352
    Profile photo of nitrogenwidget
    nitrogenwidget
    Participant

    So i think i’ve done all this.
    but still no shader on lr-mame2003.
    should the # be removed from the begining of the line?
    And should true or false be inside quotes?
    also which config file?
    there are like 3 or 4 config files in multiple folders called retroarch.cfg which one am i editing?

    thanks.

Viewing 14 posts - 1 through 14 (of 14 total)

Forums are currently read only - please visit the new RetroPie forums at https://retropie.org.uk/forums/

Skip to toolbar