Improve lighting
- No specular on surfaces facing away from the light source - Transform the light direction to view space to ensure that all lighting calculations happen in a consistent coordinate space. - Other lighting tweaks
This commit is contained in:
parent
a51aeb23bd
commit
71e991db77
3 changed files with 28 additions and 15 deletions
|
|
@ -59,7 +59,11 @@ impl RenderingSystem for BasicMeshRenderingSystem {
|
|||
};
|
||||
|
||||
// Use HDR-derived environment light direction if provided, otherwise default to downward
|
||||
let light_dir: Vec3 = if ctx.env_light_dir.length_squared() > 0.0 { ctx.env_light_dir.normalize() } else { Vec3::new(0.0, -1.0, 0.0) };
|
||||
let light_dir_world: Vec3 = if ctx.env_light_dir.length_squared() > 0.0 { ctx.env_light_dir.normalize() } else { Vec3::new(0.0, -1.0, 0.0) };
|
||||
|
||||
// Transform light direction to view space (normals/positions are in view space)
|
||||
let view_mat3 = glam::Mat3::from_mat4(cam.view());
|
||||
let light_dir_view = (view_mat3 * light_dir_world).normalize();
|
||||
|
||||
let asset_manager = ctx.asset_manager.borrow();
|
||||
|
||||
|
|
@ -90,7 +94,7 @@ impl RenderingSystem for BasicMeshRenderingSystem {
|
|||
model: tr.matrix().to_cols_array_2d(),
|
||||
view: cam.view().to_cols_array_2d(),
|
||||
projection: cam.projection().to_cols_array_2d(),
|
||||
u_light: [light_dir.x, light_dir.y, light_dir.z],
|
||||
u_light: [light_dir_view.x, light_dir_view.y, light_dir_view.z],
|
||||
tex: sampler,
|
||||
color: [c[0], c[1], c[2]],
|
||||
uv_offset: [mat.uv_offset.x, mat.uv_offset.y],
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ impl RenderingSystem for SkyboxRenderingSystem {
|
|||
|
||||
// Load EXR from assets/exr
|
||||
let manifest_dir = env!("CARGO_MANIFEST_DIR");
|
||||
let path = std::path::Path::new(manifest_dir).join("../assets/exr/qwantani_sunset_puresky_2k.exr");
|
||||
let path = std::path::Path::new(manifest_dir).join("../assets/exr/citrus_orchard_road_puresky_4k.exr");
|
||||
let (equirect_srgb, light_dir) = Self::load_hdr_equirect_and_analyze(display, &path);
|
||||
Self { program, quad_vb, quad_ib, equirect_srgb, light_dir }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue