From 7c7dcf536eb508fdba8128b9ee79957cfb045fb4 Mon Sep 17 00:00:00 2001 From: Antonio Noack Date: Mon, 8 Jul 2024 08:13:56 +0200 Subject: [PATCH] Lightening the edge of the water --- assets/shaders/water.frag.wgsl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/assets/shaders/water.frag.wgsl b/assets/shaders/water.frag.wgsl index 190302bb..6b94eadd 100644 --- a/assets/shaders/water.frag.wgsl +++ b/assets/shaders/water.frag.wgsl @@ -78,9 +78,14 @@ fn frag(@location(0) _in_tint: vec4, let reflected: vec3 = reflect(-V, normal); let reflected_atmo = atmosphere(reflected, params.sun, 1e38); - let sun_contrib: f32 = clamp(dot(normal, params.sun), 0.0, 1.0); - let base_color: vec3 = 0.03 * vec3(0.262, 0.396, 0.508); + let terrain_depth: f32 = 1.0 / textureLoad(t_depth, vec2(position.xy), 0).x; + let expected_depth: f32 = -dot(cam_to_wpos, params.cam_dir.xyz); + let water_depth = (expected_depth - terrain_depth) * params.cam_dir.z; + let relative_water_depth = clamp(water_depth / 32.0,0.0,1.0); + + let base_factor = mix(0.03, 0.3, pow(1.0-relative_water_depth,4.0)); + let base_color: vec3 = base_factor * vec3(0.262, 0.396, 0.508); let sunpower: f32 = 0.1 * reflect_coeff; var final_rgb: vec3 = base_color + sunpower * reflected_atmo;