#2011·warp

BVH ray queries miss boxes when rays run along a face

Author: shi-ericCreated Sep 30, 2026Updated Sep 30, 2026
Labelsbug

wp.bvh_query_ray() and wp.tile_bvh_query_ray() can miss an AABB when a ray runs exactly along one of its faces. The ray enters the box at a positive distance, but the query reports no hit. The behavior occurs on CPU and CUDA.

A single box reproduces the scalar query failure:

python
import warp as wp


@wp.kernel
def query_ray(bvh_id: wp.uint64, origin: wp.vec3, direction: wp.vec3, hits: wp.array[int]):
    query = wp.bvh_query_ray(bvh_id, origin, direction)
    index = int(0)
    while wp.bvh_query_next(query, index):
        hits[index] = 1


wp.init()
lower = wp.array([(0.5, -1.0, -1.0)], dtype=wp.vec3, device="cpu")
upper = wp.array([(1.0, 1.0, 1.0)], dtype=wp.vec3, device="cpu")
bvh = wp.Bvh(lower, upper)
hits = wp.zeros(1, dtype=int, device="cpu")

for y in (-1.0, 0.0, 1.0):
    hits.zero_()
    wp.launch(
        query_ray,
        dim=1,
        inputs=[bvh.id, wp.vec3(0.0, y, 0.0), wp.vec3(1.0, 0.0, 0.0), hits],
        device="cpu",
    )
    print(f"y={y}: {hits.numpy()[0]}")

All three rays intersect the box, so each should print 1. On current main, the lower and upper face rays print 0; only the interior ray prints 1. The tiled query has the same boundary failure, as reported in this comment on MuJoCo Warp issue #1698.

The failure is partly longstanding. Warp v1.13.0 missed the lower face but reported the upper face. After commit c2a435f, first included in v1.14.0, the upper face also began to fail.