Is there a way to know which ray hit which triangle?

I have succeeded in getting ray hits on triangles for both the CPU and GPU on a few simple meshes. I am looking at the supported HitBuffer formats and I don’t see one that would tell me which ray hit my triangle. In the application I have in mind it is crucial to know the ray that hit the triangle. Any ideas?

Are you using OptiX Prime? You might need to use OptiX, which will give you the freedom to write your own HitBuffer format.

I am using OptiX Prime. I initially thought the hitBuffer only recorded hits of rays, but instead it actually records all ray casts and you know hits based on the hit “t” being positive or negative. That is, I think there is an explicit assumption here about the rayBuffer and the hitBuffer I did not catch at first glance. It appears the hitBuffer count and rayBuffer count are always the same - a one-to-one correspondence between hitBuffer index (i) and rayBuffer index (i). Is this true? If so, then when I walk the hitBuffer indices I can know the ray that caused the intersection due to the one-to-one correspondence.

“It appears the hitBuffer count and rayBuffer count are always the same - a one-to-one correspondence between hitBuffer index (i) and rayBuffer index (i). Is this true?”

Exactly.

See some other posts with answers to OptiX Prime questions:
https://devtalk.nvidia.com/default/topic/793335/?comment=4602958
https://devtalk.nvidia.com/default/topic/747089/?comment=4226320
https://devtalk.nvidia.com/default/topic/766372/?comment=4284299