game: make some changes to water shader

This commit is contained in:
2025-08-22 10:19:55 +02:00
parent 950d177936
commit d57a59e9fe

View File

@@ -3,19 +3,28 @@ uniform vec4 water_color : source_color = vec4(0.0, 0.0, 1.0, 1.0);
uniform sampler2D noise_tex; // noise texture uniform sampler2D noise_tex; // noise texture
uniform vec2 noise_speed = vec2(0.05, 0.01); uniform vec2 noise_speed = vec2(0.05, 0.01);
uniform float noise_strength = 0.2; // how much to lighten/darken uniform float noise_strength = 0.2; // how much to lighten/darken
uniform float pixel_size = 0.005;
void fragment() { void fragment() {
vec2 uv = UV; vec2 uv = UV;
vec4 base_tex = texture(TEXTURE, uv); vec4 base_tex = texture(TEXTURE, uv);
float is_water = step(0.8, 1.0 - distance(base_tex.rgb, water_color.rgb)); float is_water = step(0.8, 1.0 - distance(base_tex.rgb, water_color.rgb));
vec2 snapped_uv = floor(SCREEN_UV / pixel_size) * pixel_size;
// Scroll UVs for noise animation // Scroll UVs for noise animation
vec2 noise_uv = SCREEN_UV + noise_speed * TIME; //vec2 noise_uv = SCREEN_UV + noise_speed * TIME;
vec2 noise_uv = snapped_uv + noise_speed * TIME;
vec4 noise_sample = texture(noise_tex, fract(noise_uv)); vec4 noise_sample = texture(noise_tex, fract(noise_uv));
float n = noise_sample.r;
n = pow(n, 3.0) * 4.0;
n = clamp(n,0.0, 1.0);
vec4 noisy_color = water_color.rgba;
noisy_color += vec4(0.1* (noise_sample.r - 0.5), 0.05 * (noise_sample.r - 0.5), 0.0, 1.0);
// Use noise (0..1) to brighten/darken the water color // Use noise (0..1) to brighten/darken the water color
float brightness = (noise_sample.r - 0.5) * 2.0 * noise_strength; float brightness = (n - 0.5) * 4.0 * noise_strength;
vec4 animated_water = water_color + vec4(vec3(brightness), 0.0); vec4 animated_water = noisy_color + vec4(vec3(brightness), 0.0);
COLOR = mix(base_tex, animated_water, is_water); COLOR = mix(base_tex, animated_water, is_water);