Ray tracer artifacts with reflection

∥☆過路亽.° 提交于 2019-12-23 18:29:16

问题


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

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.


回答1:


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 as (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.

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.



来源:https://stackoverflow.com/questions/41211892/ray-tracer-artifacts-with-reflection

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!