fix(scene): respect t for shadow rays

This commit is contained in:
Jonas Röger 2024-11-20 13:41:18 +01:00
parent af4c4801f3
commit c3d6d80fd7
Signed by: jonas
GPG Key ID: 4000EB35E1AE0F07

View File

@ -94,15 +94,18 @@ impl Scene {
for light in &self.lights { for light in &self.lights {
// Cast Shadow-Ray // Cast Shadow-Ray
let direction = light.position - isect_pt;
let distance = direction.norm();
let direction = direction / distance;
let shadow_ray = Ray { let shadow_ray = Ray {
origin: isect_pt, origin: isect_pt,
direction: (light.position - isect_pt).normalize(), direction,
}; };
if self if self.objects.iter().any(|obj| {
.objects obj.intersect(&shadow_ray)
.iter() .and_then(|(_, _, t, _)| Some(t < distance))
.any(|obj| obj.intersect(&shadow_ray).is_some()) .unwrap_or(false)
{ }) {
continue; continue;
} }