diff --git a/crates/victory-shader/src/emit/intersect.rs b/crates/victory-shader/src/emit/intersect.rs index b32afa8..66665ef 100644 --- a/crates/victory-shader/src/emit/intersect.rs +++ b/crates/victory-shader/src/emit/intersect.rs @@ -59,6 +59,14 @@ struct Ray { inverse: [V; 3], } +/// LOCAL (from our wt5): `VICTORY_BVH_MISS=1` (off by default): the node test +/// misses every node. While the structure builder is off the structures are +/// never built, and a walk of what lies in their memory is not the console's. +fn bvh_miss() -> bool { + static ON: std::sync::OnceLock = std::sync::OnceLock::new(); + *ON.get_or_init(|| std::env::var_os("VICTORY_BVH_MISS").is_some_and(|v| v == "1")) +} + impl<'a> Lower<'a> { /// `image_bvh_intersect_ray` and `image_bvh64_intersect_ray`. pub(super) fn bvh(&mut self, inst: &Inst, b: usize, i: usize) -> Result<(), Why> { @@ -191,11 +199,22 @@ impl<'a> Lower<'a> { .m .terminate(leaf_block, Term::CondBr(is_triangle, triangle_block, join)); self.cur = box_block; - let boxes = self.bvh_boxes(at, kind, &ray, sort); + // LOCAL (from our wt5): with `VICTORY_BVH_MISS=1` every node is missed + // without being read: a box returns no child and a triangle the + // triangle miss, so a walk ends at its first node. + let boxes = if bvh_miss() { + [self.s.m.i32(bvh::NONE); 4] + } else { + self.bvh_boxes(at, kind, &ray, sort) + }; let box_end = self.cur; self.s.m.terminate(box_end, Term::Br(join)); self.cur = triangle_block; - let triangle = self.bvh_triangle(at, kind, &ray); + let triangle = if bvh_miss() { + bvh::MISS.map(|f| self.s.m.i32(f.to_bits())) + } else { + self.bvh_triangle(at, kind, &ray) + }; let triangle_end = self.cur; self.s.m.terminate(triangle_end, Term::Br(join)); self.cur = join;