<p>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. <a href="http://pbrt.org" rel="nofollow noreferrer" title="PBRT">PBRT</a> 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.</p>

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

CC BY-SA 3.0
2017-01-09T19:35:15.503Z
2017-01-09T19:35:15.503Z
Stefan Werner
<p>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.</p>

<p>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.</p>

<p>I hope this answers it.</p>

CC BY-SA 3.0
2016-12-10T18:07:07.110Z
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.
anonymoose2121
CC BY-SA 3.0
2016-12-10T19:04:28.773Z
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?
bram0101
CC BY-SA 3.0
2016-12-10T18:01:57.447Z
2016-12-10T18:01:57.447Z
bram0101
<p>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.</p>

<p>How is this handled normally?</p>

CC BY-SA 3.0
2016-12-12T04:26:19.290Z
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.
Alan Wolfe
CC BY-SA 3.0
2016-12-12T23:13:09.203Z
Are you able to share your code?
trichoplax is on Codidact now
<raytracing><geometry><shading><normal-mapping>
Sampling against geometry normals
anonymoose2121
# Sampling against geometry normals

(Asked by: username_0 on 2016-12-10)

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?

**Tags:** raytracing, geometry, shading, normal-mapping

> **Comments:**
> **username_1**: 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.  
> **username_2**: Are you able to share your code?  

---

## 2 answers

### Answer by username_3 on 2017-01-09. Score: 4

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](http://pbrt.org "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.


---

### Answer by username_4 on 2016-12-10. Score: 0

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.

> **Comments:**
> **username_0**: 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.  
> **username_4**: 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?  

---

