optixTrace(), point of intersection and recursion depth limit

To implement light bouncing from object, I need the point at which this closest_hit took place, ie. the value of t such that hitPoint = rayOrigin + t*rayDirection.
I can obtain rayOrigin and rayDirection from optixGetWorldRayOrigin/Direction() functions but not sure about the t.
From reading the reference manual, optixGetRayTime() will not accomplish this.
Since recursion is involved in the emulation of the light bouncing around, there needs to be a way to limit its depth: Is there a built in OptiX mechanism for this or the payload of optixTrace() is used (or maybe a slicker way)?
For custom geometries one can do things in intersection shader but for triangles, which use the built in intersection shader, things seem more limited.

HI there, you can get the “t” by using optixGetRayTmax(). https://raytracing-docs.nvidia.com/optix7/guide/index.html#curves#curves-and-the-hit-program

Note that if you’re using triangles, you can also get the hit point without using “t”. You could use optixGetTriangleBarycentrics() in conjunction with optixGetTriangleVertexData(). This is a little more bandwidth, but the reason to do it this way is if you need better accuracy. Using origin + t * direction can lose precision if t gets very large.

optixGetRayTime() is referring to motion blur time, so is used for a different purpose than reconstructing the hit point.

You can limit recursion depth on your own, even with triangles, several different ways. If you are calling optixTrace() recursively, you can put a depth value in your payload and track the depth and prevent recursive calls when it’s above a threshold. The more common way is to handle ray depth iteratively in your raygen program, and there you can loop over depth and stop when you’ve exceeded your limit. The benefit of iterating in raygen is you avoid using extra stack memory to handle recursion. See the SDK sample called optixPathTracer for a complete demonstration of iterative depth handling for path tracing in a raygen program.


David.

1 Like

Please also look at the sticky posts in this sub-forum which contain additional links to documentation and examples showing this functionality and much more.