Question about reflection at ray surface

Hi all,

I have a question about starting a new ray after reflection.

Right now, in the first run, I will save the coordinates of the hit points and pass the hit points back to CPU program through “params”. After some calculations to get the directions after reflection, then I will use the hit points as new origins and launch the second run.

My question is, in this case, the hit points are exactly on the surface. Is it possible this will cause numerical error, so the ray will be started under the surface instead of on top of the surface?

How should I handle the reflection correctly?

Hi @Z.Jiang,

Because we are working with 32 bit floats, it’s quite rare for a hit point to be “exactly” on a surface. You can imagine that near a surface there is a 3D grid of points where 32 bit floating point numbers can exist, and your hit point will always be rounded to one of them. This means that most of the time your hit point is just slightly inside the surface, or just slightly outside the surface.

There are multiple ways to handle secondary rays and avoid what’s called a “self-intersection”. You can move the new ray origin so that it’s close to the hit point, but outside the surface. You can also use a non-zero “t-min” value to prevent rays intersecting at t=0. If you are writing a custom intersection program, you can also keep track of the primitive ID you hit with your primary ray, and write code to skip over that primitive when tracing a secondary ray. (But this method isn’t available with hardware accelerated triangles.)

Please have a look at the Ray Tracing Gems article “A Fast and Robust Method for Avoiding Self-Intersection”, by Carsten Wächter and Nikolaus Binder.


Thank you very much! This is a very clear explanation.

1 Like