MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / intersect_aabb

Function intersect_aabb

tools/bloom-reference/src/main.rs:708–720  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

706/// intersects the box in front of the origin; used by the BVH walk to
707/// decide which children to descend into.
708fn 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

Callers 1

intersect_bvhFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected