Godot Version
4.2
(2D)
tutorial: https://www.youtube.com/watch?v=32jdNLTJ3zY
I followed the tutorial on the reflection of water, only the problem is that the position y of the camera in certain cases creates a bug…
SCREENSHOOT:
good:
BUG:
tool script: (water node with shader)
@tool
extends Sprite2D
func _process(delta):
_zoom_changed()
pass
func _zoom_changed():
material.set_shader_parameter(“y_zoom”, get_viewport_transform().get_scale().y)
pass
func _on_item_rect_changed():
material.set_shader_parameter(“scale”,scale)
pass
shader script: (node water )
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
uniform float scale_y;
uniform float y_zoom;
void fragment() {
float uv_height = SCREEN_PIXEL_SIZE.y / TEXTURE_PIXEL_SIZE.y;
vec2 reflected_uv = vec2(SCREEN_UV.x, SCREEN_UV.y + uv_height * UV.y * scale_y * y_zoom);
vec4 reflection = textureLod(SCREEN_TEXTURE, reflected_uv, 0.0);
COLOR = reflection;
}

