How to increase shadow mapping distance?

Jun 23, 2013 at 2:17 PM
Hi Abuzer,

While I am working on my specular map shader I am also trying to increase the range that my shadows will go.

I have looked around, and I honestly cannot think of how to increase the distance for the shadows. Any ideas?

Also, it looks really clean, which is exactly what I would want, but the shadows seem to stop near the object casting them. Do you know why?

I've attached a photo so you can tell what I mean:
Image

Thanks.
Developer
Jun 23, 2013 at 3:10 PM
That's caused by a couple of factors. The funny part is that it's not actually that the range of your shadows go far, but quite the opposite. Your shadows are actually going too far, causing it to loose depth precision which in turn makes it harder to resolve depth differences that are small. This is also one of the reasons why tuning shadows to catch good self-shadowing is hard because self-shadowing relies on very high precision to resolve the depth differences between parts of an object that are very close to each other (i.e. the depth difference between the shadow caster and receiver).

Anyway. Long story short, there are two things you need to do. First decrease the near and far clip plane distances on your shadow camera frustum. This will make sure you're giving more precision to the values in the shadow map. The trick is to find a good set of clip plane distances that are large enough to capture all the shadow casters, but not too far that they start to fall out of that range.

The next one is adjusting what is called a "depth bias". There are many articles on shadow map biasing. The reason for having shadow biasing is to make sure an object that is both a shadow caster and a receiver does not end up "shadowing itself" which shows up as what is usually called "shadow acne". The simplest implementation of shadow bias is to simply increment the shadow depth value by a tiny constant value. This value depends on how you've adjusted your shadow near and far clip planes. The smaller the near far clip distance, the smaller you can keep the shadow bias. So you need to figure out a shadow bias value that is large enough that eliminates shadow acne, and small enough that you do not see the problem you're seeing in the screenshot above.

I'm guessing your shadow implementation already has a shadow bias, but it is too large, but simply making is smaller could introduce shadow acne. So again, find a shadow map near and far clip range values that are smaller. This should be easy to know when you look at the shadow map image in the upper left hand corner. When your clip distances are good, the gray scale "color" of the shadow map should have a nice visible gradient going from almost white to almost black. You can see in your current image that it hardly shows that gradient. Later you'll find that the real problem is how to deal with adjusting your shadow near and far clip distances when you have a scene that goes far into the distance and you want to shadow everything in it. That is a whole different discussion though, but one that almost every game runs into.

The other easy win is to change your shadow map format to store higher precision depth values. For example if it's currently storing 16-bit values, then you can switch to 32-bit. Only do this after you've really adjusted the other factors and you cannot get any more precision out of the existing format though.

Unfortunately I don't know about any of the code specifics so I can't really respond to that.

Hope that helps.
Jun 23, 2013 at 3:21 PM
Hey Abuzer, changing the Surface Format, as you suggested, worked really well. As did decreasing the farclip. Thank you very much.

A photo of the improved shadows:
Image