How to get all primitives intersected with a ray in OptiX

Hi all,

Given a scene containing N triangles, I shoot one ray into the scene and I want to get all triangles that intersect with the ray, is there any OptiX API to do this? (I know I can get all hit point of this ray, but currently I want to get all primitives that intersect with the ray).

Hi @794906124,

The OptiX API for collecting either all primitives or all hit points along a ray is the any-hit shader program. I’m not sure I understand your exact question about hit points vs primitives. In the case of triangles, since a triangle can only have a single hit point, the set of hit points and the set of triangle primitives intersected along a ray should have a 1:1 correspondence.

If you wanted a list of object ids or something where an object may be comprised of multiple triangles, and your ray could hit the object multiple times, then you can build a triangle-to-object id table, lookup and collect the object id for every hit (first call optixGetPrimitiveIndex(), then use the primitive index to lookup the object id in your table), and then sort and deduplicate the object ID list in raygen after your ray returns from optixTrace().

What I just described isn’t a great idea – just collecting a dynamic length list of either hit points or IDs is of course prone to being very slow, and sorting them could be worse. Depending on what you’re doing, there might be other ways to achieve what you need without having to collect all the hits using an any-hit shader. Are you perhaps interested in discussing your high level goals and structure, and exploring whether there are alternative approaches?


David.

1 Like