raytracingoptix

Is there a way to traverse an OptiX 7 acceleration structure to find the geometry closest to a given point?


I know this isn't the primary goal of OptiX but it is relevant when ray marching (sphere marching) signed distance fields so I figured I'd try. I created my own BVH for this originally but I was hoping to benefit from all the recent ray tracing work and RTX acceleration.

I will assume some basic familiarity with the OptiX 7 API.

My initial attempt involved setting the optixTrace ray direction to {0, 0, 0} but this only triggers intersections for shapes where the ray origin is inside the AABB (makes sense). I then set the ray direction to {inf, inf, inf} which seemed to trigger intersection calls for every primitive regardless of AABB distances or reported tMax values.

I played around with a few other combinations of ray directions and tMax/tMin values and I considered the various OPTIX_RAY_FLAGS but nothing seemed like it might work.

Ideally, it would be nice to query only bounding boxes that are within tMax distance from the ray origin. This is obviously a different check than a ray-aabb intersection but I was curious if there might be some API flags/masks/functionality I'm missing that would allow for this. Direct access to the acceleration structure hierarchy could help here too but I didn't see anything about that in the programming guide.


Solution

  • Hopefully one of us answered this on the OptiX forum, but just to address the question here:

    It would be nice, and this is a common question, but unfortunately no, there is not currently a way to do a single nearest neighbor query or a single k nearest neighbors (KNN) query using the OptiX 7 geometry acceleration structures. These structures are currently limited to finite directional ray queries.

    There is a paper that explores using OptiX to do a radius search using multiple ray samples: https://abasilak.github.io/papers/journals/jcgt2021/paper.pdf