CRT Shader?

This topic contains 39 replies, has 9 voices, and was last updated by  therevills 1 year, 4 months ago.

Viewing 15 posts - 16 through 30 (of 40 total)
  • Author
    Posts
  • #11887

    Hezkore
    Participant

    Now we need it in real time 🙂

    My example above is real-time

    You must have copied the shader incorrectly, cause it’s the exact same shader as nr 7. which you got an error on (that error is btw fixed by writing ‘1.0 -‘ instead of just ‘1 -‘, fixed in my version), but mine has two name changes.
    Make sure you get the first line copied which defines the renderpasses.

    And as I said, all you have to do is replace the ‘sharp’ and ‘blur’ texture with ‘m_ImageTexture0’ and pass the image to a canvas (so that the canvas draws to the image), then there’s no need to pass a texture to the shader, M2 does that for you.

    So if you really can’t get my example working, do ^ those things. 🙂

    #11913

    therevills
    Participant

    Strange when I copy and paste the shaders from here I get the “Can’t find ‘//@renderpasses’ tag” error…

    I now get:

    Edit:
    Got it to work now… no idea what was going on…

    #11934

    PixelPaladin
    Participant

    If there is interest I could write a crt shader module for monkeyX2.

    #11935

    Anatol
    Participant

    therevills, I had a similar error before

    > Invalid uniform type 0 expecting 1

    In my case I didn’t set the uniform from outside the shader. I thought I did but that piece of code never got executed and so the shader couldn’t find it.

    #11940

    therevills
    Participant

    @pixelpaladin – that would be great!

    @anatol – I really dont have any idea what I’m doing with shaders at the moment, never played with them in the past 🙂

    #11954

    PixelPaladin
    Participant

    Okay, I wrote a small crt module.

    Get it here:
    https://www.dropbox.com/s/pvv6l8hqwsth2vm/crt.zip?dl=0

    Some example code:

    (only resolutions between 128×64 and 800×600 are allowed)

    #11966

    Ethernaut
    Participant

    Thanks for sharing! 😀

    I also updated my shader tests repository with my latest CRT shader. Still needs some tweaks, but it’s very customizable, and is already working pretty well for an “arcade monitor” style image. It has features like variable width scanlines, soft glow, color correction and image filtering on a single axis.

    arcade crt shader

    There’s also a “useful functions” .glsl file in the shaders folder, with functions I found while googling around, with credits for each one.

    https://github.com/DoctorWhoof/Mojo-Shader-Tests

    Cheers.

    #11974

    PixelPaladin
    Participant

    @ethernaut: That looks nice! I like the glow effect. How did you implement it?

    I changed some parameters. The image is now less distorted (but in the corners some pixels are not visible anymore). It is now also possible to set the intensity for rgb splitting (the vertical lines) as well as the intensity of the scan lines (the horizontal lines):

    Attachments:
    #11977

    Ethernaut
    Participant

    The glow was a pain, took me something like 2 or 3 nights fiddling with the code and the parameters to get it to look right. This is what I got in the end:

    The number of X and Y samples increases automatically when the glow size is larger, so it gets very expensive very quick. 2.0 seems like a good amount for an Ok looking glow with a reasonable performance (runs on a 2880×1800 image at 60fps on a laptop with intel graphics).

    But the trick that actually helped a lot was to “pre-mix” the glow with the main color using “max( color, glowColor * 1.5 )” before doing the additive mix. This “fills” the dark spaces between pixels more, and makes the glow more visible without making the image much brighter. Have a look at the full glsl code here:

    https://github.com/DoctorWhoof/Mojo-Shader-Tests/blob/master/shaders/test07_CRT.glsl

    It’s kinda messy, I don’t really know what I”m doing!
    Cheers!

    #11979

    therevills
    Participant

    @pixelpaladin – I cant get your code to work. When I try to compile I get:

    So I changed this line:

    to

    So it now compiles but crashes at runtime:

    Full code:

    #11980

    PixelPaladin
    Participant

    So you used a single-pass approach. Multi-pass would be faster, but if you get 60 fps on Intel graphics it should be absolutely okay (I wanted to implement it but I was too lazy 🙂 )

    Somehow my biggest problem with monkey2’s mojo is that I cannot pass values to shaders. I really don’t like that. The only possibility to pass values to a shader seems to be encoding them into a hidden area of the source image … which seems odd to me.

    #11981

    therevills
    Participant

    @pixelpaladin – did you see my post just before yours?

    #11984

    Ethernaut
    Participant

    I’m actually getting the same errors as @therevills on MacOS. Maybe it’s because I’m using the latest dev branch?

    So you used a single-pass approach. Multi-pass would be faster

    Baby steps! Until a couple weeks ago I wouldn’t even know where to start if someone asked me how a shader works… :-)… Multi-pass here would actually be ideal, since the glow should happen on the image after the scanlines and shadow mask are applied. Any pointers on how exactly I’d make it happen? For instance, where do you store each pass resulting texture, and how do you use it on the next pass? Is it just updated on the m_ImageTexture0 itself?

    Somehow my biggest problem with monkey2’s mojo is that I cannot pass values to shaders

    I didn’t get that part. Can’t you pass values using methods like Image.Material.SetFloat?

    Cheers.

    #11988

    PixelPaladin
    Participant

    Any pointers on how exactly I’d make it happen?

    The idea behind the multi pass approach is to blur in one direction first (let’s say in x direction) and in the next pass blur in the other direction (y). This reduces running time from O(n²) to O(n). In mojo you could render into different images using multiple canvases (I am not sure how efficient this is – maybe there is a better solution to this). To get a soft blur a gauss kernel is often used. It can be statically included into the shader as an array or it can be passed to the shader as a texture. However I cannot figure out how pass stuff to the shader in monkey2’s mojo (everything I tried just crashed my program).

    I didn’t get that part. Can’t you pass values using methods like Image.Material.SetFloat?

    That was what I thought – but I have no idea how to do this. Is there any documentation or a tutorial to this? Let’s say I have a uniform float foo in my shader. What do I need to do to set the value of foo in my monkey source?

    Edit: I figured out, how it works … fixing everything right now.

    #11990

    PixelPaladin
    Participant

    @therevills: no, sorry. I updated my monkey2 to the newest version and now my code crashes, too. I will try to fix that. Seems like the shader stuff has changed a lot in the last months …

Viewing 15 posts - 16 through 30 (of 40 total)

You must be logged in to reply to this topic.