37 lines
1.3 KiB
Plaintext
37 lines
1.3 KiB
Plaintext
shader_type canvas_item;
|
|
uniform vec4 water_color : source_color = vec4(0.0, 0.0, 1.0, 1.0);
|
|
uniform sampler2D noise_tex; // noise texture
|
|
uniform vec2 noise_speed = vec2(0.05, 0.01);
|
|
uniform float noise_strength = 0.2; // how much to lighten/darken
|
|
uniform float pixel_size = 0.005;
|
|
|
|
void fragment() {
|
|
vec2 uv = UV;
|
|
vec4 base_tex = texture(TEXTURE, uv);
|
|
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
|
|
//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));
|
|
|
|
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
|
|
float brightness = (n - 0.5) * 4.0 * noise_strength;
|
|
vec4 animated_water = noisy_color + vec4(vec3(brightness), 0.0);
|
|
|
|
|
|
COLOR = mix(base_tex, animated_water, is_water);
|
|
}
|
|
|
|
//void light() {
|
|
// // Called for every pixel for every light affecting the material.
|
|
// // Uncomment to replace the default light processing function with this one.
|
|
//}
|