How to record hits while traversing a mesh?

Hi,


[ figure 1 ]

My intention is to achieve figure1.
I want to find the indices of other triangles that are visible from within a triangle. (single object)

Initially, I thought that only one ray per pair of triangles would be sufficient.
It seems that there might be situations where triangles cannot be accurately identified.

I need advice on how to handle the following scenario:

==========================================


[ figure 2 ]

condition: TraceDepth is 1 and using only closest hit.

  1. Emit a ray from the centroid of (a) to (b).
    1-1) (a) → (b): hit

  2. Emit a ray from the centroid of (a) to (c).
    2-1) (b) is hit first.
    2-3) Since TraceDepth is 1, tracing terminates.
    2-4) (a) → (c): miss

  3. Emit a ray from the centroid of (a) to (d).
    3-1) (a) → (d): hit

  4. Emit a ray from the centroid of (a) to (e).
    4-1) (d) is hit first.
    4-2) Since TraceDepth is 1, tracing terminates.
    4-4) (a) → (e): miss
    ==========================================

In the scenario above, I want 2-4) to be recorded as a miss ( (c) is obscured by (b) )
and 4-4) to be recorded as a hit ( (e) is not obscured by (d) ).
To achieve this, it seems that using only one ray per pair of triangles won’t be sufficient.
I would like to ask for advice on this.

It seems that I’ll need the barycentroids and positions of each triangle to set the ray origin and direction in the raygen function.
Can I pass this information as “launch parameters”? If so, I’m considering passing an array of triangle centroids and indices.

The orientation of the triangles is not of interest.
I’m assuming that the scene is convex in shape.

The number of triangles in the scene could increase, potentially reaching 100k or more.
Therefore, I might need to execute optixLaunch multiple times, as you suggested.
Can I use a loop statement to run optixLaunch multiple times?

Your responses have been immensely helpful to me.
Thank you.