• Advertisement
Sign in to follow this  

Robust Shadow Mapping Implementation

This topic is 4382 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok so I've made an implementation of shadow mapping, but I'm noticing some serious artifacts. I'm sure this problem has been solved before, so I'm hoping someone experienced can point me in the right direction. Step 1, I get it working without any biasing, and I get this(light source is above): http://www.geocities.com/terrence321/SM1.jpg There are two major sources of visual artifacts that I know of: self-shadowing problems, and projective aliasing. The self-shadowing problems account for all the pixely garbage on the lit surface of the sphere, while projective aliasing appears right on the border of the shadow, in the places where the normals of the sphere are nearly perpendicular to the light direction (and thus there isn't good projective sampling there). So, I add biasing to fix those two problems, and get something like this: http://www.geocities.com/terrence321/SM2.jpg The self shadowing errors are gone, and the borders are a lot cleaner. The main problem now is that due to what I assume is my biasing, some of the shadow is getting taken off. When the light source is moved sufficiently far away, the shadows now completely disappear! I can partially solve this by adding a diffuse lighting model, and simply choosing the light value per-pixel as the minimum of the shadow value and diffuse value. Then I get this: http://www.geocities.com/terrence321/SM3.jpg The problem is, this only fixes the missing shadowing on each object. If the camera gets more than a few hundred world units away, the shadows on the ground completely disappear! What can I do to strike a balance between biasing to remove artifacts, and accuracy so my shadows don't disappear? Note my ultimate use for this system will be in an RTS game, so the light source should ideally be from roughly above at an infinite distance. Thanks a lot for any advice. Terrence

Share this post


Link to post
Share on other sites
Advertisement
Please post your shader code, the code you use to render to the depth texture and the code you use to render the scene with shadowmapping.

Share this post


Link to post
Share on other sites
Are you using projected shadow mapping (a la spotlight) or isometric shadow mapping (a la directionl light)?

With projective, when your light goes out far enough, you will need to increase resolution of the map to not lose the objects because of aliasing. You could also reduce the FOV of the shadow map to only cover the objects that need shadowing.

There's also some risk that your shadow map suffers from a "far" plane that's too near -- the objects won't be rendered into the map, because they're clipped, when rendering the map. A similar risk is if you have too poor depth resolution, because the "near" field of the camera that renders the shadow map is too small -- you should typically make it much further out than you would for a scene-rendering camera. Push it until it almost touches the first object that will cast a shadow (and clamp it to some large minimum, too, for moving lights/objects that get too close).

Share this post


Link to post
Share on other sites
I'm not at the correct computer right now, but I'll organize the source code and put it up here if that helps. I am using projective shadow mapping (right now with an fov of 90). I'm not familiar with directional light shadow mapping, but really that's what I'd want. I have no need for local light sources, just light due to the sun. Is that a special case of projective shadow mapping or is it more work?

With regards to narrowing down my frustum to avoid losing shadows, I guess I was hoping to avoid "special casing" it. Maybe there's no other way... I just envisioned shadow mapping as being a fairly general technique if implemented right. Thanks for the feedback.

Share this post


Link to post
Share on other sites
Narrowing down the frustum for the shadow map is not "special casing", I guess, as you should do this anyway for most cases, as using a FOV / frustum that is larger than needed would also mean wasting a part of the shadow map resolution for objects that aren´t seen anyway and so on. I guess same is valid for adjusting near and far clipping planes for the shadow map.

Share this post


Link to post
Share on other sites
*scratches head* Haven't you tried using a SMALL bias while you have the N dot L lighting in? You only need the bias to get rid of the acne, not to eliminate the projective aliasing, as that all but disappears when you have the N dot L term and even a little bit of PCF.

Share this post


Link to post
Share on other sites
Cypher19: I was setting my bias to try to minimize projective aliasing, but you're right, I just decreased my bias by one order of magnitude and still was able to avoid acne and projective aliasing as long as I used the n dot l model. That drastically reduced the shadow falloff. Once that approach is combined with directional lights with a frustum that "clamps" to the objects in the scene I think I'll be happy with the results.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement