Page 29 of 33

Re: Share a Shader!

Posted: Sun Feb 28, 2016 1:52 am
by farzher
binaryeye wrote:This may be the wrong thread because I don't know if this shader actually works.

I'm trying to convert a CRT shader found on Shadertoy to LÖVE. It runs without errors, but I get a black screen. I don't know if this is because the shader isn't working or because my system doesn't support it. I'm not exactly sure what I should be passing to the iChannel variable (it seems to want an image, so I'm drawing to a buffer and passing that), nor what the first variable should be in iResolution, so those could also be problems.

I've attached a .love. If anyone could run it and let me know what happens, I'd appreciate it. There should be a white circle in the center of the screen. Thanks!

Funny, I spent a few hours getting that exact shader working the other day. We ended up not using it though because it makes things look too blurry and dark. If anyone finds a nice CRT shader PLEASE LET ME KNOW! <3
The shaders on retroarch look awesome, but I don't know how to convert them.

I attached a working version of the shader, (although it still splits the image in 3 sections)

Re: Share a Shader!

Posted: Sun Feb 28, 2016 8:17 am
by bobbyjones
I think shine has a CRT shader.

Re: Share a Shader!

Posted: Sun Feb 28, 2016 10:44 am
by Jack5500
bobbyjones wrote:I think shine has a CRT shader.
yes, shine has a CRT shader:

https://github.com/vrld/shine/blob/master/crt.lua

Re: Share a Shader!

Posted: Sun Feb 28, 2016 1:07 pm
by binaryeye
farzher wrote:I attached a working version of the shader, (although it still splits the image in 3 sections)
Thanks for that. I would have never tried defining iResolution as a vec2.

I modified it to work full screen and you're right; it's generally too blurry and dark. It can be sharpened up but at the cost of losing the shadow mask effect, which is mainly what I'm after in a CRT shader.

Re: Share a Shader!

Posted: Sun Feb 28, 2016 8:15 pm
by monolifed
I wish this was sticky

Re: Share a Shader!

Posted: Sun Apr 10, 2016 9:28 am
by kbmonkey
I got curious about adding reflective water in my games (specifically for 2D platform or point-and-click adventure perspectives). I implemented such a mirror via ImageData manipulation and was aghast yet unsurprised at the performance hit. So I had my hand at writing my first shader.

Very simple and likely an eyesore to those of you with more experience creating shaders :ehem:

Code: Select all

vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords )
        {
        
            // n represents where the source of the mirror pixels start.
            // 1.0 mirrors from the very top of the screen.
            // 0.5 mirrors from half-way up the screen.
            number n = 0.5;
            
            // Alter reflection with a slight blue tint
            vec4 overlayColor = vec4(0.1, 0.3, 0.6, 1.0);
        
            // Its a kind fo magic pink
            vec4 texcolor = Texel(texture, texture_coords);
            if (texcolor.r == 1.0 && texcolor.g == 0.0 && texcolor.b == 1.0)
            {
                // Mirror mirror on the wall
                vec2 mirrorpoint = vec2(
                    texture_coords.x,
                    1.0 - (texture_coords.y * n)
                    );
                
                return Texel(texture, mirrorpoint) * overlayColor;
                
            }
            else 
            {
                return texcolor * color;
            }
        }
    ]]

Re: Share a Shader!

Posted: Mon Jun 06, 2016 9:51 pm
by GhostAction
I am using the Mari0 CRT.frag shader for my project and for some reason I'm getting this result where the player is basically duplicated I guess: https://gyazo.com/ef7d97e62c1a6da9a5cd49e36fce8b0a

Anybody know whats going on?

Re: Share a Shader!

Posted: Mon Jun 06, 2016 10:03 pm
by rmcode
GhostAction wrote:I am using the Mari0 CRT.frag shader for my project and for some reason I'm getting this result where the player is basically duplicated I guess: https://gyazo.com/ef7d97e62c1a6da9a5cd49e36fce8b0a

Anybody know whats going on?
All you need to do is clearing the canvas before drawing to it again:

Code: Select all

function love.draw()
	love.graphics.setCanvas(canvas)
	love.graphics.clear()
	love.graphics.setColor(155, 155, 155)
	love.graphics.rectangle("fill", 0, 400, 800, 200)
	...

Re: Share a Shader!

Posted: Mon Jun 06, 2016 10:15 pm
by GhostAction
@rmcode Thanks a lot!

Does anyone know how I could make the colors like stay the same as the game without shaders (ex. https://gyazo.com/3ab99d33a99f4d19bf2753f36d0dddb9)?

Re: Share a Shader!

Posted: Thu Jun 09, 2016 9:43 pm
by 4aiman
It may be a little off-topic, but this thread has so many people sharing their shaders...

So, the question is: is there a way to somehow grab what was drawn so far and apply a shader to that?
I've tried using shine (and it worked ok) but failed to understand how to make it respect all my scale() and transform().