# Sampling against geometry normals

I am writing a basic raytracer and have implemented normal maps. However, when using normal maps, sometimes the rays generated are opposite to the surface's geometry normal, so that the rays are reaching light sources behind the object. If I kill the ray, the shading results looked faceted and the surface normals are apparent. If I don't kill the ray, the ray reaches light sources on the opposite side of the geometry.

How is this handled normally?

• How often and how much are they in the opposite direction? It could be a math precision error if they are only occasionally inside, by not very much. If they are often the wrong way, it could be that your tangent and bitangent vectors or math is wrong. If it's almost always wrong, it could be due to mixing left and right handedness maybe. Commented Dec 12, 2016 at 4:26
• Are you able to share your code? Commented Dec 12, 2016 at 23:13

## 2 Answers

That is, to my knowledge, a problem without a proper solution. You're seeing the discrepancy between shading normal and geometry normal and it becomes obvious, that the shading normal is just a trick. PBRT has a paragraph on this, their solution is to look at the geometric normal to determine whether to call the BRDF (reflection) or the BTDF (transmission), then to pass the shading normal to the BxDF. Still, this doesn't work robustly in all situations.

This problem is also known and described for production proven render engines: http://blog.irayrender.com/post/29042276644/shadow-acne-and-the-shadow-terminator The solution suggested for iRay is to use displacement mapping instead of normal maps. This way, shading and geometry normal are in agreement again.

One thing that I see being done, is that when the ray is generated, the location is shifted on the normal. Basically the normal multiplied by a small amount is added to it. If you are shading the backside of the face, then the normal needs to be inverted.

The reason why, is, for example, when a light is behind a face, and you cast the light ray. Without the offset the origin is exactly on the face, so t is 0. Algorithms see this as not a hit, so the offset along the normal, makes it so that t isn't 0 anymore.

I hope this answers it.

• The problem is actually different, it's not that I'm missing an intersection it's that the shading normals are creating rays that are valid for the shading normal, but not for the surface geometry normal. Commented Dec 10, 2016 at 18:07
• You mean that some of the rays created are not on the hemisphere of the geometry normal? Like if you would create a dot product with the ray direction and the geometry normal, it ends up being negative? As far as I know this is just ignored. Don't know what kind of artifact you actually get when you have that. Could you maybe show some pictures of the artifacts? Commented Dec 10, 2016 at 19:04