Question

I'm having an issue with back faces (to the light) and shadow mapping that I can't seem to get past. I'm still at the relatively early stages of optimizing my engine, however I can't seem to get there as even with everything hand-tuned for this one piece of geometry it still looks like garbage.

What it is is a skinny wall that is "curved" via about 5 different chunks of wall. When I create my depth map I'm culling front faces (to the light). This definitely helps, but the front faces on the other side of the wall are what seem to be causing the z-fighting/projective shadowing.

Artifacts on bent wall

Some notes on the screenshot:

  • Front faces are culled when the depth texture (from the light) is being drawn
  • I have the near and far planes tuned just for this chunk of geometry (set at 20 and 25 respectively)
  • One directional light source, coming down on a slight angle toward the right side of the scene, enough to indicate that wall should be shadowed, but mostly straight down
  • Using a ludicrously large 4096x4096 shadow map texture
  • All lighting is disabled, but know that I am doing soft lighting (and hence vertex normals for the vertices) even on this wall

As mentioned here it concludes you should not shadow polygons that are back faced from the light. I'm struggling with this particular issue because I don't want to pass the face normals all the way through to the fragment shader to rule out the true back faces to the light there - however if anyone feels this is the best/only solution for this geometry thats what I'll have to do. Considering how the pipeline doesn't make it easy/obvious to pass the face normals through it makes me feel like this isn't the path of least resistance. And note that the normals I am passing are the vertex normals, to allow for softer lighting effects around the edges (will likely include both non-shadowed and shadowed surfaces).

Note that I am having some nasty Perspective Aliasing, but I'm hoping my next steps are to work on cascaded shadow maps, but without fixing this I feel like I'm just delaying the inevitable as I've hand-tightened the view as best I can (or so I think).

Anyways I feel like I'm missing something, so if you have any thoughts or help at all would be most appreciated!

EDIT

To be clear, the wall technically should NOT be in shadow, based on where the light is coming from.

Overhead view

Below is an image with shadowing turned off. This is just using the vertex normals to calculate diffuse lighting - its not pretty (too much geometry is visible) but it does show that some of the edges are somewhat visible.

Without shadowing turned on

So yes, the wall SHOULD be in shadow, but I'm hoping I can get the smoothing working better so the edges can have some diffuse lighting. If I need to have it completely in shadow, then if its the shadow map that puts it in shadow, or my code specifically putting it in shadow because the face normal is away, I'm fine with that - but passing the face normal through to my vertex/fragment shader does not seem like the path of least resistance.

Perhaps these will help illustrate my problem better, or perhaps bring to light some fundamental understanding I am missing.

EDIT #2

I've included the depth texture below. You can see the wall in question in the bottom left, and from the screenshot you can see how i've trimmed the depth values to ~0.4->1. This means the depth values of that wall start in the 0.4 range. So its not PERFECTLY clipped for it, but its close. Does that seem reasonable? I'm pretty sure its a full 24 or 32 bit depth buffer, a la DEPTH_COMPONENT extension on iOS. For @starmole, does this help to determine if its a scaling error in my projection? Do you think the size/area covered of my map is too large, hence if it focuses closer it might help?

enter image description here

Was it helpful?

Solution

The problem seems to be that you are

  1. Culling the front faces
  2. Looking at the back face
  3. Not removing the light from the back face because it's actually not lit by the normal - or there is some inaccuracy in the computation
  4. Probably not adding some epsilon

(1) and (2) mean that there will be Z-fighting between the shadow map and the back faces.

Also, the shadow map resolution is not going to help you - just look at the wall in the shadow map, it's one pixel thick.

Recommendations:

  1. Epsilons. Make sure that Z > lightZ + epsilon
  2. Epsilons. Make sure that the wall is facing the light (dot of normal > epsilon) to make sure the wall is shadowed if it's very nearly orthogonal
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top