Confusion about `optixIgnoreIntersection()`

Hello!

In my program, I launch multiple rays, each of which may intersect with multile triangles. In order to realize that, I use the optixIgnoreIntersection() function. Now I want to count the number of miss by adding a counter in miss-program, and I find that it is equal to the number of rays. Does optixIgnoreIntersection() clear the intersection information of ray so that the miss-program is always called?

Thanks.

If you always call optixIgnoreIntersection inside your anyhit program on every invocation, the ray will never intersect with anything, means it will never reach the closesthit program, and will always reach the miss program.

See here: https://raytracing-docs.nvidia.com/optix8/guide/index.html#device_side_functions#reporting-intersections-and-attribute-access
and here: https://raytracing-docs.nvidia.com/optix8/api/group__optix__device__api.html#ga9938b9d8bc8a025c137524933c96e76f

Only if the anyhit program doesn’t call optixIgnoreIntersection on some code path, or if it calls optixTerminateRay, the potential intersection is accepted and will shrink the tmax and the closesthit progam can be reached.

Note that optixIgnoreIntersection and optixTerminateRay will immediately return! If you want to update any payload data etc. inside the anyhit program invocation you must do that before these calls.

Also note that the AS builders are splitting by default so you can reach the anyhit program multiple times for the same primitive which breaks algorithms which count anyhit program invocations.
To prevent that, you must build the acceleration structure with the OPTIX_GEOMETRY_FLAG_REQUIRE_SINGLE_ANYHIT_CALL flag!
See here: https://raytracing-docs.nvidia.com/optix8/guide/index.html#acceleration_structures#6101

Search this OptiX forum for that to find other threads which describe how to find all intersections along a ray.