I finally tracked down the black-edge problem. It's actually a really subtle problem that could easily happen in any raytracer. Here's the problem: if you use normal interpolation (aka 'Phong' normals) to smooth out the surfaces of triangles, then the normal vector no longer matches the true geometry of the scene. In certain edge cases (literally...particularly on the edges of objects), this can cause the dot product of the Phong normal and the ray direction to be a different sign than the dot product of the real geometric normal and the ray direction. That means that, if you use the Phong normal, you'll end up incorrectly flipping the sign of the normal (that is, assuming you're flipping normals to make triangles double-sided...if not, then I suppose you won't encounter this problem).
The solution is to keep track of two normals during intersection: the shading normal and the geometric normal. I know that PBRT makes a similar distinction, and now I understand why. The correct thing to do is to check the geometric normal's dot product with the ray direction, but still use the Phong normal for BRDF calculations.
Here's before:
And now, with fixed normals:
Yay for finally ridding myself of that one!


No comments:
Post a Comment