is raycasting slower if there's no hit?

I’m using optix prime (5.1) to raycast against a mesh (RTP_QUERY_TYPE_CLOSEST). I’m running some experiments and I’m seeing it run a lot slower that usual. I have a hunch that it’s because I might be creating a lot more rays that do not hit the mesh. Am I correct? Or is the raycasting time completely independent of whether the ray is going to hit something or not?

If my hunch is correct, is there a way to configure Optix to “give up” after some raycasting distance and consider there’s no hit? Worst case I can add a boundary to my world so that all rays will hit something reasonably close and then filter those out in post processing.

Hi brice,

Trace time definitely depends on how many triangles the ray comes close to, the time is not independent of the scene geometry. Rays that almost hit a lot of triangles without actually hitting any will be slower than rays that hit something nearby, and slower than rays that aim away from your scene into empty space.

To configure OptiX Prime to give up after some distance, you can set the t_min and t_max value of your rays, which will perform traversal only within that interval, and it will stop checking for intersections beyond the t_max distance value. For that to help with your trace times, it would mean that you successfully prevent some intersection tests, which may mean that you’ll miss geometry you care about. It won’t help anything to set t_max to be slightly larger than your scene bounds.

I can’t tell if your hunch is correct without a lot more info, but I can give you some generic suggestions. Check how many rays you’re casting, and check what percentage of them are misses. You could also check to see if a lot of rays are being cast near some dense geometry. Lastly I would recommend stepping back and double-checking that all your data is valid. If some NaNs or INFs or unintended zeros snuck into your ray data or your scene data, that could end up causing noticeable slowdowns.


David.

Hi David

Setting t_max to a small value seems to be the solution I needed, thank you.

From what I gathered online, it seems to me that if t_max is equal to 10, and there’s a triangle in the ray’s path at a distance of 11, then the ray will return “no hit”. Furthermore, the engine won’t search any further, thus speeding up the query. Can you confirm?

Also, I found RT_DEFAULT_MAX = 1.e27f but this doesn’t seem to be accessible from optix_prime… Is there a way?

That’s correct, if a triangle is in the ray path, but further away than t_max, then OptiX will limit traversal to only bounds & primitives that match your t interval. In your example the query will speed up. Remember to imagine a hierarchy of boxes with your triangles living in the leaf boxes. OptiX ray queries are testing boxes from the top box down, as long as your ray intersects the box AND the ray-box intersection lands within the interval [t_min, t_max]. The triangle’s exact distance doesn’t matter so much as the box containing the triangle.

RT_DEFAULT_MAX belongs to OptiX and not OptiX Prime, so you won’t be able to include the header file. I don’t know why it’s 1e27, since you can have larger valid float values, but the only thing that matters is having a default value that’s larger than anything you’re going to trace. I recommend using the existing C or C++ constants for a maximum floating point value, e.g., either FLT_MAX from float.h or std::numeric_limits::max().


David.