2D shader - water reflection, Godot 3.3

A mini project for the game engine - Godot 3.3. For the 2D scene from the previous project "Aliens Vs Zombies" was added a water reflection effect using a shader.

Here is the video of the process:

More information about shaders in Godot you can find on the official website here.

Shader code:

shader_type canvas_item;

uniform float scale_y;
uniform float zoom_y;

uniform sampler2D noise;
uniform vec2 distortion_scale;
uniform float distortion_intencity;
uniform float distortion_speed;

uniform float wave_amplitude;
uniform float wave_speed;
uniform float wave_period;

uniform vec4 water_color : hint_color;

void fragment() {
	float waves = UV.y + sin(UV.x / wave_period + TIME * wave_speed) * cos(0.2* UV.x / wave_period + TIME * wave_speed) * wave_amplitude - wave_amplitude;
	float uv_height = SCREEN_PIXEL_SIZE.y / TEXTURE_PIXEL_SIZE.y;
	float distortion = (textureLod(noise, UV * distortion_scale + TIME * distortion_speed, 0.0).x -0.5) * distortion_intencity;
	vec2 reflection_screen_uv = vec2(SCREEN_UV.x - distortion, SCREEN_UV.y + uv_height * UV.y * scale_y * zoom_y);
	vec4 reflection = textureLod(SCREEN_TEXTURE, reflection_screen_uv, 0.0);
	COLOR.rgb = mix(reflection.rgb, water_color.rgb, water_color.a);
	COLOR.a = smoothstep(0.1, 0.13, waves);
}

Download the project you can here.

Login to post a comment.
Place Holder Image

admin

Replied to admin on: 09/17/2022

Test

Test


Place Holder Image

admin

Posted on: 08/29/2021

Test