Godot Version
4.3
Question
Hi, I need a water shader, I found 2D water effect - Godot Shaders
but it’s not for Godot 4. x
I replaced SCREEN_TEXTURE
with uniform sampler2D
to fix the error and everything is fine but the effect is not the same as the preview
Did you use hint_screen_texture
?
1 Like
yes, my underwater texture (Godot logo) just moves left and right without twist (wave)
I turned it into a visual shader for fun, and then just copied the code out for you. Hope this works for you.
shader_type canvas_item;
render_mode blend_mix;
uniform float WaveSpeed = 2;
uniform float WaveFrequency = 10;
uniform float WaveWidth = 1;
uniform sampler2D screen_tex_frg_14 : hint_screen_texture;
void fragment() {
// Input:5
vec2 n_out5p0 = SCREEN_UV;
// VectorDecompose:17
float n_out17p0 = n_out5p0.x;
float n_out17p1 = n_out5p0.y;
// Input:7
float n_out7p0 = TIME;
// FloatParameter:2
float n_out2p0 = WaveSpeed;
// FloatOp:16
float n_out16p0 = n_out7p0 * n_out2p0;
// FloatOp:18
float n_out18p0 = n_out17p0 + n_out16p0;
// FloatParameter:3
float n_out3p0 = WaveFrequency;
// FloatConstant:11
float n_out11p0 = 2.000000;
// FloatOp:19
float n_out19p0 = n_out3p0 * n_out11p0;
// FloatOp:20
float n_out20p0 = n_out17p1 * n_out19p0;
// FloatOp:21
float n_out21p0 = n_out18p0 + n_out20p0;
// FloatFunc:22
float n_out22p0 = cos(n_out21p0);
// FloatParameter:4
float n_out4p0 = WaveWidth;
// FloatConstant:12
float n_out12p0 = 0.010000;
// FloatOp:23
float n_out23p0 = n_out4p0 * n_out12p0;
// FloatOp:24
float n_out24p0 = n_out22p0 * n_out23p0;
// VectorOp:15
vec2 n_out15p0 = n_out5p0 + vec2(n_out24p0);
vec4 n_out14p0;
// Texture2D:14
n_out14p0 = texture(screen_tex_frg_14, n_out15p0);
// Output:0
COLOR.rgb = vec3(n_out14p0.xyz);
}
how can I remove the black waves (just color, not effect)?

What does your node tree look like? Mine looks like this:

And I am not seeing the lines your are talking about:


When reconstructing the project, I found that I needed a CanvasLayer (UnderwaterEffectLayer) at the very bottom, and then a ColorRect (UnderwaterEffect) underneath that with a shader material applied to it, and the shader applied to the shader material.
Your shader needs to be the child of a CanvasLayer, and it needs to be the lowest thing in the node tree. The way it is in my screenshot.
I forked GrythmO’s original GitHub project and added in the visual shader I made. I disabled their other shaders in the project, as I did not recreate them - but it’s working without the grey background. Hopefully this will help you figure it out.