optixGetTriangleVertexData(..) API is giving (0.0..0.0) data structure for certain rays

Hi Team,
I have boon working with Optix 7.2 for 2-3 weeks now and have been able to solve most of my problems. I believe that I still have to learn or familiarize more with Optix (and CUDA) stack but my solution is working as expected and reporting me correct intersection counts. However, I’m stuck with one problem where optixGetTriangleVertexData(…) API is not returning me expected triangle data. Below is the excerpt from my device side code.
extern “C” global void __closesthit__occlusion()
{
unsigned int triangleIndex = optixGetPrimitiveIndex();
float2 barycentrics = optixGetTriangleBarycentrics();
//if (1.0 < (barycentrics.x + barycentrics.y) || (barycentrics.x + barycentrics.y) < 0.0) {
//optixIgnoreIntersection();
//return;
//}
//params.d_floorLightScores[optixGetPayload_0()] += 0.001;
float3 data[3];
optixGetTriangleVertexData(optixGetGASTraversableHandle(), triangleIndex, optixGetSbtGASIndex(),
0.0f, data);
//for (int i = 0; i < 3; i++) data[i] = optixTransformPointFromObjectToWorldSpace(data[i]);
float3 intersectionP = data[0] * (1.0f - barycentrics.x - barycentrics.y) +
data[1] * barycentrics.x +
data[2] * barycentrics.y;
//intersectionP = optixTransformPointFromObjectToWorldSpace(intersectionP);
params.d_WallIntersections[optixGetPayload_0()] = intersectionP;
}
I’m yet to do a cleanup and optimization of this code once it starts working as I expect, hence, please bear the code if it’s not ideal yet.
Any help will be much appreciated.
Thanks

For optixGetTriangleVertexData() to work the acceleration structure must have been built with the flag OPTIX_BUILD_FLAG_ALLOW_RANDOM_VERTEX_ACCESS.
Please check if that is set in your OptixAccelBuildOptions used in the optixAccelBuild() calls,

https://raytracing-docs.nvidia.com/optix7/guide/index.html#acceleration_structures#build-flags

Take note of the potential drawbacks here:
https://raytracing-docs.nvidia.com/optix7/guide/index.html#device_side_functions#vertex-random-access

Note that it’s not allowed to call optixIgnoreIntersection() inside a closest hit program. That ray already ended there.
Check this device side function table:
https://raytracing-docs.nvidia.com/optix7/guide/index.html#device_side_functions#device-side-functions

Thanks a lot droettger. That straight forward worked. I knew that something like this is missing but being new, I was not able to figure out easily. Apart from this, a lot of code in this snippet above is meaning less (mostly commented out) and is due to be cleaned up once the algorithm is giving the desired result.

Thanks again!