<p>It's not entirely clear what the scene in your picture is supposed to look like, so I'm not sure I'm interpreting it correctly. But if I am, it seems like the problem is that you're projecting the shadow properly, but onto the wrong face of the gray wall. If you want to research it, you might have luck looking up <a href="https://en.wikipedia.org/wiki/Winding_number" rel="nofollow noreferrer">winding order</a> (sometimes called winding number), or <a href="https://en.wikipedia.org/wiki/Back-face_culling" rel="nofollow noreferrer">back-face culling</a>. </p>

<p>If I'm correct in what's shown above, I think you could solve it in your shader by only applying the shadows to the current fragment if the vector from the light source to the surface points away from the surface normal. In other words, take the dot product of those 2 vectors, and if it's negative apply shadows, otherwise, don't.</p>

CC BY-SA 3.0
2016-12-22T11:47:40.470Z
Thanks for the answer. So this can only be fixed in the shader? Or is there something I am doing wrong with my actual light pov camera? because basically I am taking my normal cameras position and moving the light pov camera to that position every frame instead of just having a static light pov camera for the entire scene high up somewhere.
Kachinsky
CC BY-SA 3.0
2016-12-22T16:00:40.433Z
Shouldn't the light POV camera be in the same position as the light?
user1118321
CC BY-SA 3.0
2016-12-23T15:41:40.463Z
@Kachinsky what user1118321 means, I think, is that you're applying the shadow to a surface which is not lit (the light comes from behind). It's what it looks like to me anyway. You must think of the shadow map as something which alters the intensity of a specific light, not something you can just slap onto the object at the end of your shader. If there's no light, there can be no shadow.
Olivier
CC BY-SA 3.0
2016-12-22T06:11:47.190Z
2016-12-22T06:11:47.190Z
user1118321
<p>I have been following a tutorial, shadow mapping works more or less as expected except sometimes the shadow projects completely weirdly on nearby walls. This isn't sampling outside the lightmap because I use CLAMP_TO_EDGE and if(min(ShadowCoord.x, ShadowCoord.y) > 0.0 &amp;&amp; max(ShadowCoord.x, ShadowCoord.y) &lt; 1.0) in the fragment shader. Does anyone know what the official term for this problem is so I can go research it some more? Thanks.</p>

<p><img src="https://i.sstatic.net/rISb0.png" alt="Shadowmapping error"></p>

CC BY-SA 3.0
2016-12-22T15:19:37.290Z
Do you have `GL_CULL_FACE` disabled when rendering to shadow map?
mdkdy
CC BY-SA 3.0
2016-12-22T19:34:24.083Z
I tried with it both on and off, it only changes the shadow slightly under the models feet.
Kachinsky
<shadow><shadow-mapping>
What is this shadow mapping error called?
Kachinsky
# What is this shadow mapping error called?

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

I have been following a tutorial, shadow mapping works more or less as expected except sometimes the shadow projects completely weirdly on nearby walls. This isn't sampling outside the lightmap because I use CLAMP\_TO\_EDGE and if(min(ShadowCoord.x, ShadowCoord.y) > 0.0 && max(ShadowCoord.x, ShadowCoord.y) < 1.0) in the fragment shader. Does anyone know what the official term for this problem is so I can go research it some more? Thanks.

![Shadowmapping error](https://i.sstatic.net/rISb0.png)

**Tags:** shadow, shadow-mapping

> **Comments:**
> **username_1**: Do you have `GL_CULL_FACE` disabled when rendering to shadow map?  
> **username_0**: I tried with it both on and off, it only changes the shadow slightly under the models feet.  

---

## 1 answers

### Answer by username_2 on 2016-12-22. Score: 1

It's not entirely clear what the scene in your picture is supposed to look like, so I'm not sure I'm interpreting it correctly. But if I am, it seems like the problem is that you're projecting the shadow properly, but onto the wrong face of the gray wall. If you want to research it, you might have luck looking up [winding order](https://en.wikipedia.org/wiki/Winding_number) (sometimes called winding number), or [back-face culling](https://en.wikipedia.org/wiki/Back-face_culling).

If I'm correct in what's shown above, I think you could solve it in your shader by only applying the shadows to the current fragment if the vector from the light source to the surface points away from the surface normal. In other words, take the dot product of those 2 vectors, and if it's negative apply shadows, otherwise, don't.

> **Comments:**
> **username_0**: Thanks for the answer. So this can only be fixed in the shader? Or is there something I am doing wrong with my actual light pov camera? because basically I am taking my normal cameras position and moving the light pov camera to that position every frame instead of just having a static light pov camera for the entire scene high up somewhere.  
> **username_2**: Shouldn't the light POV camera be in the same position as the light?  
> **username_3**: @username_0 what username_2 means, I think, is that you're applying the shadow to a surface which is not lit (the light comes from behind). It's what it looks like to me anyway. You must think of the shadow map as something which alters the intensity of a specific light, not something you can just slap onto the object at the end of your shader. If there's no light, there can be no shadow.  

---

