Skip to content

Commit

Permalink
tune lighting
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Aug 17, 2023
1 parent 490f8b5 commit c50de96
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
8 changes: 7 additions & 1 deletion assets/shaders/atmosphere.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ fn atmosphere(r: vec3<f32>, pSun: vec3<f32>) -> vec3<f32> {
iTime += iStepSize;
}

let backgroundLight: vec3<f32> = 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);
}
8 changes: 5 additions & 3 deletions assets/shaders/pbr/render.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,12 @@ fn render(sun: vec3<f32>,
var dkD: vec3<f32> = 1.0 - dkS;
dkD *= 1.0 - vec3(metallic);

let ambient: vec3<f32> = (0.2 * dkD * (0.15 + irradiance_diffuse) * albedo + specular) * ssao;
var color: vec3<f32> = ambient + Lo * 4.0;
let ambient: vec3<f32> = (0.2 * dkD * (0.04 + irradiance_diffuse) * albedo + specular) * ssao;
var color: vec3<f32> = 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);

Expand Down
2 changes: 1 addition & 1 deletion native_app/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<CameraHandler3D>();
params.cam_pos = camera.camera.eye();
params.cam_dir = -camera.camera.dir();
Expand Down

0 comments on commit c50de96

Please sign in to comment.