Hit position in Any Hit Program

Hi everyone,

I am building an implementation which needs figure out every intersection ray-geometry. Since in my case all rays never change their directions, an any-hit program might be ideal to handle the calculation. So I wonder if it’s possible to use the “rtIntersectionDistance” in an any hit program to locate the hit position or is there any other corresponding variable. Otherwise, how to determine a hit point in an any-hit program?

Thanks in advance.

yunsong

Hi

Yes, you can use rtIntersectionDistance in any-hit program. But take in account that because of AS, ray traverses not exactly in order with the any-hit. You will have to sort hits if it’s needed. With closest hit program you always get the first intersection along the ray.

thanks a lot, qconst.
I just find it in programming guide.

Now I get another question : For example, I’m tracing 32 rays at the same time. When each ray terminates, a counter as output buffer will +1. Since I need a 32 on output, how to avoid the error that several rays counting at the same time? Cause in this way, the output will be surely inferior to 32. I faced the same problems longtime ago on cuda and totally forgot how to handle it. Do you have any ideas?

thanks.

You need to ensure a serialized access to your counter variable.
You can do this using atomic operations, e.g. atomicInc().
Have a look at the CUDA documentation: http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#atomic-functions

exactly what i need, thanks!
unfortunately my gpu is not powerful enough, i’m considering changing it. :)