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

  • 1
    $\begingroup$ Do you have GL_CULL_FACE disabled when rendering to shadow map? $\endgroup$ – narthex Dec 22 '16 at 15:19
  • $\begingroup$ I tried with it both on and off, it only changes the shadow slightly under the models feet. $\endgroup$ – Kachinsky Dec 22 '16 at 19:34

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 (sometimes called winding number), or 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.

| improve this answer | |
  • $\begingroup$ 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. $\endgroup$ – Kachinsky Dec 22 '16 at 11:47
  • $\begingroup$ Shouldn't the light POV camera be in the same position as the light? $\endgroup$ – user1118321 Dec 22 '16 at 16:00
  • 3
    $\begingroup$ @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. $\endgroup$ – Olivier Dec 23 '16 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.