OptixPrime, TriangleId... I thought I understood how that works, but I don't

In my app I have 2 different types of meshes and after hitting them I need to know which type I hit.

The Prime Hits take a buffer that includes a triangle Id. So I thought the easiest way to do this would be to first add all vertices and indices from one type of mesh, then from the other, remember the index of the switch and with the triangle Id from the Hit I can work out the position in the index array.

Somehow that doesn’t work.

Or to rephrase… When I get the TriangleId it’s value should be Indices/3, no? (So TriangleId * 3 should be the first index of the triangle?)

Any help would be appreciated. I also read the Programming guide, the documentation and looked through the SDK examples and just can’t work out what I am doing wrong here.

Describe “that doesn’t work”.

“The Prime Hits take a buffer that includes a triangle Id. So I thought the easiest way to do this would be to first add all vertices and indices from one type of mesh, then from the other” …

You mean you combined the twe meshes to one by concatenating the two vertex arrays and then built a new index array by copying all indices of the first mesh, but re-indexed all indices of the second mesh to point to the new vertex locations of the second mesh, (new_index.xyz = old_index.xyz + first_mesh_vertices.size())?

“When I get the TriangleId its value should be Indices/3, no?”

Only when you used indices with individual integer types. Then you would need to multiply the hit triangle ID with 3 to get the host side first integer. When using int3 types, it’s just that same index in the host.

A simpler method would be to place the two different meshes under two instances (identity matrix) and use a hit buffer format with the INSTID field to identify which mesh you hit, like shown inside the OptiX SDK example primeInstancing.

“Doesn’t work” means I can’t get the right triangle back for a given ray.

You mean you combined the twe meshes to one by concatenating the two vertex arrays and then built a new index array by copying all indices of the first mesh, but re-indexed all indices of the second mesh to point to the new vertex locations of the second mesh, (new_index.xyz = old_index.xyz + first_mesh_vertices.size())?

Exactly, it’s also a few thousand meshes, so I thought this would be best performance wise instead of shoveling to the GPU one by one.

And yes, I used the int3 type. Either way, thanks a lot for the explanation!

If I can’t get that to work, then I have a look at instancing. I thought this was only for different versions of the same mesh. Didn’t think of that.

Again thanks a lot!

I don’t know why that wouldn’t work in your case.
Try increasing numbers of small meshes in a minimal repro case and some queries for which you know the expected outcome.
Just in case, there is a limit of about 270 MTriangles per mesh.

Would be helpful to know your system configuration.
OS version, installed GPU(s), VRAM amount, display driver version, OptiX major.minor.micro version, CUDA toolkit version used to generate the input PTX, host compiler version.

If this is not on OptiX 5.1.x or OptiX 6.0.0, please upgrade to the resp. latest major version you want to use.

Currently I am assuming that I made a mistake there somewhere.

“270 MTriangles per mesh” thanks! I was looking for that but couldn’t find it.

Currently running on Windows (17763.476), 32GB Ram and running on an 2080 RTX with, IIRC 8GB.

OptixPrime is 5.1.1.0 (but just tried with 6, same result)

But yeah, I do have a feeling that the problem then is on my end.