From bdbb662f69bdb76a9587e83d8b10da0bfde8f3af Mon Sep 17 00:00:00 2001 From: Antonio Noack Date: Mon, 8 Jul 2024 08:13:56 +0200 Subject: [PATCH 1/2] 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; From 7dbcf2e4c691807cb3aace862c86cf3ac31832df Mon Sep 17 00:00:00 2001 From: Paris DOUADY Date: Thu, 11 Jul 2024 10:54:18 +0200 Subject: [PATCH 2/2] update defines before invalidating pipelines related to MSAA --- engine/src/gfx.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/engine/src/gfx.rs b/engine/src/gfx.rs index e2c31a02..699384bd 100644 --- a/engine/src/gfx.rs +++ b/engine/src/gfx.rs @@ -619,13 +619,6 @@ impl GfxContext { false => 1, }; - if self.samples != samples { - self.samples = samples; - self.pipelines.write().unwrap().invalidate_all(); - self.fbos = Self::create_textures(&self.device, &self.sc_desc, samples); - self.update_simplelit_bg(); - } - self.set_define_flag("FOG", settings.fog); self.set_define_flag("SSAO", settings.ssao); self.set_define_flag("TERRAIN_GRID", settings.terrain_grid); @@ -634,6 +627,13 @@ impl GfxContext { self.set_define_flag("PBR_ENABLED", settings.pbr_enabled); self.set_define_flag("MSAA", settings.msaa); + if self.samples != samples { + self.samples = samples; + self.pipelines.write().unwrap().invalidate_all(); + self.fbos = Self::create_textures(&self.device, &self.sc_desc, samples); + self.update_simplelit_bg(); + } + self.settings = Some(settings); }