Help with water shader

Godot Version

Godot v 4.4.stable

Question

I built a water shader using this tutorial. I also built a wrapper to control it, it only has getters and setters.

It works fine for the typical usecases. My issue is that I want to built waterfalls eg water nodes that are in different layers. When putting one of the water nodes in a lower layer everything seems to break.

I want it to look more or less like this

but if I put the “horizontal” water in a negative order this happens (the player is behind the waterfall)

I’ changing the layer on the “pool” node but both of them change. I have set everything I can to resource => local to scene

This is the shader

shader_type canvas_item;

uniform sampler2D noise1 : repeat_enable;
uniform sampler2D noise2 : repeat_enable;

uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;

uniform vec2 scroll1 = vec2(0.05,0.05);
uniform vec2 scroll2 = vec2(0.05,0.05);

uniform float distortion_strength : hint_range(-1,1) = 0.2;
uniform vec4 tone_color : source_color;

uniform vec4 top_color : source_color;
uniform float light_start : hint_range(0.0, 1.0) = 0.275;
uniform float light_end : hint_range(0.0, 1.0) = 0.4;



void fragment() {
	float depth = texture(noise1, UV + scroll1 * TIME).r * texture(noise2, UV + scroll2 * TIME).r;
	//vec4 noise_color  = texture(noise, UV + scroll * TIME);
	vec4 screen_color = texture(SCREEN_TEXTURE,SCREEN_UV + distortion_strength * vec2(depth).rr);
	vec4 top_light = smoothstep(light_start, light_end, depth) * top_color;
	COLOR = screen_color * tone_color + top_light;
	COLOR.a = 1.0;
}

Use a BackBufferCopy node.

1 Like

Thanks. It was that simple. I just needed someone to point the way :blush:

2 Likes