From c50de96acf58288d04673800a401a84207ce4a4e Mon Sep 17 00:00:00 2001 From: Paris DOUADY Date: Thu, 17 Aug 2023 12:53:42 +0200 Subject: [PATCH] tune lighting --- assets/shaders/atmosphere.wgsl | 8 +++++++- assets/shaders/pbr/render.wgsl | 8 +++++--- native_app/src/context.rs | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/assets/shaders/atmosphere.wgsl b/assets/shaders/atmosphere.wgsl index 34056827..a2d2a958 100644 --- a/assets/shaders/atmosphere.wgsl +++ b/assets/shaders/atmosphere.wgsl @@ -113,6 +113,12 @@ fn atmosphere(r: vec3, pSun: vec3) -> vec3 { iTime += iStepSize; } + let backgroundLight: vec3 = mix(vec3(0.0116, 0.027, 0.0423), // light blue (horizon) + vec3(0.0036, 0.013, 0.0194), // dark blue + saturate(2.0 * sqrt(r.z))) // gradient + * 0.4 // power + * smoothstep(-0.3, 0.1, r.z); // black at bottom + // Calculate and return the final color. - return iSun * (pRlh * kRlh * totalRlh + pMie * kMie * totalMie); + return backgroundLight + iSun * (pRlh * kRlh * totalRlh + pMie * kMie * totalMie); } diff --git a/assets/shaders/pbr/render.wgsl b/assets/shaders/pbr/render.wgsl index 8d672e59..6e1699c0 100644 --- a/assets/shaders/pbr/render.wgsl +++ b/assets/shaders/pbr/render.wgsl @@ -158,10 +158,12 @@ fn render(sun: vec3, var dkD: vec3 = 1.0 - dkS; dkD *= 1.0 - vec3(metallic); - let ambient: vec3 = (0.2 * dkD * (0.15 + irradiance_diffuse) * albedo + specular) * ssao; - var color: vec3 = ambient + Lo * 4.0; + let ambient: vec3 = (0.2 * dkD * (0.04 + irradiance_diffuse) * albedo + specular) * ssao; + var color: vec3 = ambient + Lo; - color = tonemap(color); + let autoexposure = 1.0 + smoothstep(0.0, 0.1, -sun.z) * 5.0; + + color = tonemap(autoexposure * color); color += dither(position); diff --git a/native_app/src/context.rs b/native_app/src/context.rs index ed58c1c1..e45ab8fe 100644 --- a/native_app/src/context.rs +++ b/native_app/src/context.rs @@ -134,7 +134,7 @@ impl Context { let params = self.gfx.render_params.value_mut(); params.time_always = (params.time_always + self.delta) % 3600.0; - params.sun_col = sun.z.max(0.0).sqrt().sqrt() * LinearColor::new(1.0, 0.95 + sun.z * 0.05, 0.95 + sun.z * 0.05, 1.0); + params.sun_col = 4.0 * sun.z.max(0.0).sqrt().sqrt() * LinearColor::new(1.0, 0.95 + sun.z * 0.05, 0.95 + sun.z * 0.05, 1.0); let camera = state.uiw.read::(); params.cam_pos = camera.camera.eye(); params.cam_dir = -camera.camera.dir();