fix(shadow): read directional light direction from position_dir, not dir_angle
For directional lights dir_angle is Vec4::ZERO, so the old code built the shadow light_view_proj from dir=(0,0,0), making eye==target and look_at_mat4 degenerate -> NaN light_view_proj -> compute_shadow -> fully black frame. Directional direction lives in position_dir.xyz (surface->light); the shadow camera looks along the light's travel direction (light->scene), i.e. the negation, matching the DRAFT spec.
This commit is contained in:
@@ -336,9 +336,18 @@ impl Renderer {
|
||||
let light = lights.get(index)?;
|
||||
// Directional and spot lights carry a direction; point lights would need a 6-face cubemap
|
||||
// shadow, which is out of scope (D6), so we reject them.
|
||||
// Directional lights carry their direction in `position_dir.xyz` (from the surface toward
|
||||
// the light, see `directional_light`/shader); `dir_angle` is zero for them. Spot lights
|
||||
// carry the cone axis (from the light toward the scene) in `dir_angle.xyz`. The shadow
|
||||
// camera must look along the light's **travel direction** (light → scene), i.e. the negation
|
||||
// of the surface→light vector for directional lights.
|
||||
let dir = match light.light_type() {
|
||||
crate::resources::LightType::Directional
|
||||
| crate::resources::LightType::Spot { .. } => Vec3::new(
|
||||
crate::resources::LightType::Directional => Vec3::new(
|
||||
-light.position_dir.x,
|
||||
-light.position_dir.y,
|
||||
-light.position_dir.z,
|
||||
),
|
||||
crate::resources::LightType::Spot { .. } => Vec3::new(
|
||||
light.dir_angle.x,
|
||||
light.dir_angle.y,
|
||||
light.dir_angle.z,
|
||||
|
||||
Reference in New Issue
Block a user