ensure rays don’t propagate backwards

This commit is contained in:
numzero 2025-11-20 13:23:04 +03:00
parent 91473f08ae
commit 93c8652116

View File

@ -120,10 +120,12 @@ pub struct Hit {
impl Scene { impl Scene {
pub fn trace_ray(&self, ray: Ray) -> Option<Hit> { pub fn trace_ray(&self, ray: Ray) -> Option<Hit> {
const EPS: f32 = -1e-3;
let hit = self let hit = self
.objects .objects
.iter() .iter()
.filter_map(|obj| obj.trace_ray(ray)) .filter_map(|obj| obj.trace_ray(ray))
.filter(|h| h.dist >= EPS)
.min_by(|a, b| f32::total_cmp(&a.dist, &b.dist))?; .min_by(|a, b| f32::total_cmp(&a.dist, &b.dist))?;
Some(Hit { Some(Hit {
incident: Ray { incident: Ray {