I am working on a project in which I place a set of triangles on a straight line and emit a ray from one end to traverse all the triangles. I hope to record the index of all triangles in the intersection program. What should I do? There is my intersection program code:
extern "C" __global__ void __intersection__is(){
const unsigned int ix=optixGetLaunchIndex().x;
const unsigned int primitive_id=optixGetPrimitiveIndex();
unsigned int point_count=optixGetPayload_0();
params.intersection_id[++point_count]=params.map_id[primitive_id];
optixSetPayload_0(point_count);
printf("IS: primiive id = %u\n",primitive_id);
printf("IS: point id = %u\n",params.map_id[primitive_id]);
}
But i found this program was not called. Thank you!
For performance reasons, you should not use a custom intersection program for triangles.
OptiX 7 supports built-in triangle primitives and intersections with them are fully hardware accelerated on RTX boards.
Intersection programs are part of the hit record inside the Shader Binding Table (SBT).
The hit record can have an intersection, anyhit, and closesthit program.
Built-in triangles have their own implicit intersection program, you never set that inside the SBT hit record.
Built-in curves and spheres must use one of the built-in intersection programs fetched with optixBuiltinISModuleGet.
Only custom primitives allow implementing own intersection programs which need to be set on the SBT’s hit record for those primitives or they can’t be hit.
Your intersection program would currently not intersect with triangle primitives themselves but with the full AABB around them.
Note that the intersection and anyhit programs are not called in the ray direction order but in the BVH acceleration structure traversal order which is ray dependent.
If you need the intersections in ray direction order, it would be simpler to just implement an iterative path tracer which uses the same ray origin and direction with different (t_min, t_max) intervals or different ray origins defined by the previous hit until there is no more hit, as described in some of the threads of the above sub-forum search results.