Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lightening the edge of the water #116

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions assets/shaders/water.frag.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,14 @@ fn frag(@location(0) _in_tint: vec4<f32>,
let reflected: vec3<f32> = 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<f32> = 0.03 * vec3<f32>(0.262, 0.396, 0.508);
let terrain_depth: f32 = 1.0 / textureLoad(t_depth, vec2<i32>(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<f32> = base_factor * vec3<f32>(0.262, 0.396, 0.508);
let sunpower: f32 = 0.1 * reflect_coeff;

var final_rgb: vec3<f32> = base_color + sunpower * reflected_atmo;
Expand Down
14 changes: 7 additions & 7 deletions engine/src/gfx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down
Loading