1

I'm trying to follow this video but in Godot 3: https://youtu.be/VSwVwIYEypY

attached is an image of my project tree and the ColorRect i want to render the texture to.

enter image description here

i have two shaders, one is attached to the material of the ColorRect (you can follow the video on more details of what it does, but it basically tries to simulate the water flow from moving objects):

shader_type canvas_item;

uniform sampler2D simulation_texture;
uniform sampler2D collision_texture;

uniform float phase = 0.2;
uniform float attenuation = 0.999;
uniform float deltaUV = 3.0;

void fragment() {
    float dv = 1.0 / 514.0;
    float du = 1.0 / 514.0;
    vec3 duv = vec3(du, dv, 0) * deltaUV;

    vec3 c = texture(simulation_texture, UV).rgb;

    float p = (2.0 * c.r - c.g + phase * (
        texture(simulation_texture, UV - duv.zy).r +
        texture(simulation_texture, UV + duv.zy).r +
        texture(simulation_texture, UV - duv.xz).r +
        texture(simulation_texture, UV + duv.xz).r - 4.0 * c.r)) * attenuation;
        
    vec2 col_uv = vec2(UV.x, 1.0 - UV.y);
    float col = texture(collision_texture, col_uv).r;
    float prevCol = texture(simulation_texture, UV).b;
    
    if (col > 0.0 && prevCol == 0.0) {
        p += col * 0.5;
    }
    
    if (prevCol > 0.0 && col == 0.0) {
        p -= prevCol * 0.5;
    }
        
    COLOR = vec4(p, c.r, col, 1);
}

And I rewrote the visual shader in the video into a normal one, it's attached to the Water plane:

shader_type spatial;

uniform sampler2D sim_tex;

void fragment() {
    vec4 input = texture(sim_tex, UV);
    ALBEDO = vec3(input.r, 0.0, 0.0);
}

Sadly, when I run the game, no collision is visible and I have no idea where to start with debugging these shaders. Please LMK if I should ask about this in some other channel or if I should share my entire project. Thanks in advance !!!

here is the shader in play, with the ball colliding with the water plane but no visible changes in the red channel:

enter image description here

Here's the preview of the collision camera, it does register the collision of the ball in the middle of the animation:

enter image description here

  • I could not find the exact reason. But Linked project works with vulkan renderer and does not work with OpenGL renderer (which godot 3 uses). Hope it helps. – unlut Feb 14 '23 at 14:58

0 Answers0