0 votes

I have a warp shader, it looks like this:

shader_type canvas_item;

uniform vec2 center;
uniform float force : hint_range(0,1, 0.01);
uniform float size : hint_range(0,1,0.01);
uniform float thick : hint_range(0,1,0.01);
uniform float range : hint_range(0,1.0,0.01);

void fragment(){
    vec2 scaledUV = UV;
    float mask = (1.0 - smoothstep(size,size+0.1, length(scaledUV - center)))
     * smoothstep(size-thick-0.01, size-thick+0.4, length(scaledUV-center));
    vec2 disp = normalize(scaledUV - center) * force * mask;// * clamp(range-size,0.0,100.0);
    if(disp == vec2(0.0,0.0)){
        COLOR = texture(SCREEN_TEXTURE, SCREEN_UV);
    }
    else
        COLOR = texture(SCREEN_TEXTURE, SCREEN_UV-disp);
    //COLOR.rgb = vec3(disp,0.0);
    //COLOR.rgb = vec3(mask * clamp(range-size,0.0,100.0));
}

Basically all it does is warp the SCREENUV to create a shockwave effect. I've modified it from tutorials on youtube so that it can work as a standalone sfx at any position in the world (by using a regular UV and SCREENUV in conjunction)

However, I have been finding it difficult to layer two of these together, such as when two instances of the wave are created close to each other. As you can see, I have tried to solve this with an if-else statement, but it doesn't really blend the two waves, but rather overrides certain parts to make the effect less jarring.

Is there a way to blend this?

Godot version 3.4.4-stable
in Engine by (23 points)

1 Answer

0 votes

Overrides ? I imagine it would rather create glitched grotesque effect on waves meeting. Still I think You can achieve your goal with backbuffercopy node. You can apply it to whole screen or just child it to a wave instance. It will allow another shader to use information from SCREEN_UV not yet affected by first shockwave. So whenever any shockwave appears on screen, this place should be covered by new instance of backbuffercopy for the time being.

by (5,659 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.