Slab-based ray vs AABB. Returns `Some((t_near, t_far))` when the ray intersects the box in front of the origin; used by the BVH walk to decide which children to descend into.
(ray: &Ray, bounds_min: Vec3, bounds_max: Vec3, max_t: f32)
| 706 | /// intersects the box in front of the origin; used by the BVH walk to |
| 707 | /// decide which children to descend into. |
| 708 | fn intersect_aabb(ray: &Ray, bounds_min: Vec3, bounds_max: Vec3, max_t: f32) -> Option<f32> { |
| 709 | let t1 = (bounds_min - ray.origin) * ray.inv_direction; |
| 710 | let t2 = (bounds_max - ray.origin) * ray.inv_direction; |
| 711 | let t_min = t1.min(t2); |
| 712 | let t_max = t1.max(t2); |
| 713 | let near = t_min.x.max(t_min.y).max(t_min.z); |
| 714 | let far = t_max.x.min(t_max.y).min(t_max.z); |
| 715 | if far >= near.max(0.0) && near < max_t { |
| 716 | Some(near.max(0.0)) |
| 717 | } else { |
| 718 | None |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | // ============================================================ |
| 723 | // BVH |