I am using OptiX for a specific application where I need to process all intersections along a ray while modifying a payload on every hit. So far, I have been happily using (or perhaps misusing?) any-hit programs that are called for all intersections along a ray in an unspecified order. In the any-hit program, I modify the ray payload and at the end I call rtIgnoreIntersection to make sure OptiX will go find another hit along the same ray.
This works fine and I am happy about it. (This obviously works only because OptiX processes all intersections of a single ray in a single thread, otherwise there would be a race condition when modifying the payloads.)
However, now, I am doing something similar to CSG (constructive solid geometry) and for this purpose, I need to process all the intersections sorted in order, i.e., start with the lowest t and end with the furthest intersection. This is certainly possible with a closest-hit program and calling rtTrace again from the program with t+epsilon. Unfortunately, there is two problems with this approach: 1) the epsilon has to be small enough to catch a close neighboring intersection (e.g., in corners), but big enough not to hit the same intersection again, 2) this slows down OptiX because it has to cast new rays in the same direction instead of reusing the old one it has already computed.
Is there a mechanism that would work like any-hit program, but get called with already sorted intersections?