Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ray tracer artifacts with reflection

Tags:

raytracing

So I am trying to build a retracer. I followed this tutorial:https://www.youtube.com/watch?v=SMOJGxyd9BE&list=PLHm_I0tE5kKPPWXkTTtOn8fkcwEGZNETh&index=9

So everything works great, except I ran into one problem. I was trying to make the plane under the spheres reflective, but when I did I got this strange effect

http://imgur.com/UuW2nqZ

If you notice there are these dark spots on the reflection on the ground. I have been trying to figure out whats going on, but its strange because the entire plane has the same normal, so the reflections should be correct. Has anyone ever had an experience with this? I checked and it wasn't related to shadows.

like image 639
Luple Avatar asked Oct 29 '25 15:10

Luple


1 Answers

Common Problem

That looks like "surface acne," which occurs when, due to limited precision, the origin of the shadow test ray is (just barely) on the wrong side of the surface you intersected. Thus the surface shadows itself.

For example, you compute the intersection point of a camera ray that hits a sphere at (x, y, z). Since even double precision values have limited precision, chances are that (x, y, z) isn't exactly on the surface of the sphere. Next you create a ray from (x, y, z) toward the light source to see if it's in shadow. If (x, y, z), because of that limited precision, is actually just inside of the sphere, then the shadow test will fail because the sphere shades all points on the inside.

This is usually fixed by nudging (x, y, z) a tiny amount back in the direction of the surface normal at the intersection point. You use the nudged point as the origin for your shadow ray because you know it's on the correct side of the sphere.

Debugging Tip

In your case, the sphere itself doesn't exhibit the acne, but its reflection does. That suggests that the nudge is sometimes smaller than the cumulative loss of precision from the initial ray to the reflection ray to the sphere. Maybe your nudge is too small. Maybe something goes wrong where you compute the reflection ray.

It could also be that the intersection with the plane is sometimes on the wrong side, so your reflection ray heads off below the floor instead of back up.

To debug, I'd hack the "I hit nothing" color to hot pink and the "I'm in the shadow" color to lime green. If you see pink in those spots, then something went wrong computing the reflection ray. If you see lime green, then it's surface acne and you need to ensure you don't have a systematic precision loss and that your nudge factor is sufficient.

Advanced Nudging

I recently read that pbrt handles the precision problem more carefully than the simple nudging I described. It's explained in great detail, but the basic idea has two parts.

First, the computed point of intersection is (for most shapes) re-projected to the surface to give a more precise estimate of the actual hit point.

Second, it propagates an estimate of the error throughout the calculation. When it needs the origin for a reflection or shadow ray, it nudges the (improved estimate of the) point of intersection by just enough to ensure it's outside the box determined by the intersection point and its uncertainty. This guarantees that it's on the correct side of the surface, while requiring a much smaller nudge.

like image 166
Adrian McCarthy Avatar answered Oct 31 '25 12:10

Adrian McCarthy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!