Jump to content
Sign in to follow this  
  • entries
    235
  • comments
    509
  • views
    172540

Per-Caster Shadow Maps

Sign in to follow this  
SimmerD

111 views

More Progress

Yesterday I fixed a bug where directional lights weren't matching between the level editor and the engine. In the process, I fixed the arrow that represents the light direction to visually match in the editor.

Once I got that sorted, I noticed that several of the character shadows were getting cut off at the legs or feet. I figured it was due to the bounding sphere used for shadow creation not being the right size. I was right - I had old code in there that shrunk the bounding sphere to 80% of its real radius so as to make the collisions feel better. I fixed it to use a bigger radius, which solved the shadow clipping problems. This won't hurt the collisions, b/c I'm using an AA ellipsoid for those anyway.

I also started work on a real level. I'm tired of test levels, and wanted to make something that actually looks cool. So, far, so good. I was pleasantly surprised when I brought it up in the game - I thought - this game is going to be !@#!@#$ cool!!

It's easy to get bogged down in the technical crap and forget the whole point sometimes, so it's good to be reminded of the cool factor driving the whole project.

Here's a shot of the level I've made so far.

New Level

Shadow Fun

I have probably spent more time on shadowing than any other aspect of the Ancient Galaxy engine. I suppose that's because shadowing is a very difficult thing to get right for
many types of scenes.

My friends from the movie rendering side of things tell me that in the movies, they cheat by allowing the artist to specify how big the shadow maps are for each frame of the movie, and similar manual tweaks. Also, they often use 4k x 4k shadow maps - not exactly practical for real-time on a gf3!

As I mentioned yesterday, I use per-caster shadow maps. Each shadow map is packed into an atlas for speed purposes.

Here is a diagram of how the light position and object bounding sphere together define the shadow frustum.

Shadow Diagram

I take the character's bounding sphere, and use this to make a frustum that exactly encloses it.

One of the things I need to improve about my shadow maps still is to line up the shadow maps in local object space. This should do a better job with texel distribution, as well as make objects fit better when they are tilted. Here is a shot of an ellipsoidal boulder that is taking up too much space in the shadow atlas, due to being tilted.

Bad chart

I also use the bounding diameter to map the light-space depth function. If you do per-caster shadow maps, you don't need every object in the scene in the same shadow map. That has several advantages : one is that you can use less shadow texels overall as your shadows are tightly restricted to what the casters need. The next is that you can use less depth precision. For a character not under extreme zoom, 255 depth values is plenty for self-shadowing and for the character shadowing nearby objects.

For a long time, I wasn't doing depth shadow maps, but just black on white shadow maps, and it worked great. I would get occasional artifacts when a character was close to a stair, but it wasn't common. As I worked on making more realistic levels with the level editor, I added things like sarcophagi and fountains, and other low objects that can intersect the shadow frustum and the casterbounding sphere at the same time. This causes the projected shadow to leak towards the light, which looks awful and distracting.

Shadow Bug

So, it took me about a day to extend the per-caster shadow maps I already had to use 8-bit depth maps. This way the character's depth is rendered into the shadow map, and any receiving objects
map into the same depth range, and test their depth vs the depth already in the shadow map to see if they should be shadowed or not. This completely fixed the artifacts I was having, at a slight speed hit. I could have also used 8-bit object id maps instead, but that would not have worked for self-shadowing objects or characters, which I may add later on.

Shadow Bug
Sign in to follow this  


4 Comments


Recommended Comments

Looking good as usual () - a few random comments:


Quote:
It's easy to get bogged down in the technical crap and forget the whole point sometimes

How very true, but sadly too many people seem to be quite content with getting bogged down [smile]

I've lost track of how long I've been saying I'd make a game rather than an engine - just never got around to it [rolleyes]

Quote:
I suppose that's because shadowing is a very difficult thing to get right for many types of scenes.

I suppose that until we get to full physically-accurate realtime GI solutions that there'll be quirks and limitations of the (many) different tools used to create decent real-time lighting [grin]

Would you say that the system you've developed approaches (or is actually) "correct"? (couldn't think of a better word)

Quote:
Also, they often use 4k x 4k shadow maps

Only 4k? I'm sure I read somewhere about either pixar or dreamworks (whichever) using 16k x 16k shadow maps. Although that might have been effective pixels once the jittered sampling is factored in [oh]

Cheers,
Jack

Share this comment


Link to comment
Quote:
Quote:
Also, they often use 4k x 4k shadow maps

Only 4k? I'm sure I read somewhere about either pixar or dreamworks (whichever) using 16k x 16k shadow maps. Although that might have been effective pixels once the jittered sampling is factored in


I think they also use low field-of-view lights as well, e.g. 20d, which greatly increases the texel 'density'. However, such small field of views are impractical for typical gaming scenarios. Because SimmerD is using such low FOVs for his object based shadows though, he can use low res shadows that still look high quality.


By the way Simmer, you get self-shadowing with your current method? Awesome! Out of curiosity, do the shadows still look good when the object moves near a light?

Oh, and the game looks very good, I can't wait to see it in action!

Share this comment


Link to comment
The shadows don't use more shadow map texels when they are near a light, they use a # of texels proportional to their potential maximum size in screen space.

It's possible to get some stretching when the light is low to a floor, but that's rare.

I could tilt the shadow maps to give more detail near a light, or on the floor, but it doesn't seem to be needed as of yet.

Right now I do proper character->world shadows, but the same technique works for character->self or character->character or even world->character, I just don't use it for those.

The same basic frustum ( with different clip planes ) can be used to find all of the world geometry or other characters that might cast a shadow on a character, and you can use the same technique to get shadows that way.

For what I'm doing, that would be overkill. So, right now my implementation of the technique is not 'correct', because I am hacking the world geomtery->character shadows and character->character shadows, but the technique itself can be implemented 'correctly'.

The other thing I am skimping on is the light field of view. I'm not properly handing >= 180 degree fov ( which would require rendering into a cubemap or something like that ), so when a character intersects a light source, things look a bit strange.

Glad you guys like the look. AG actually looks a lot better in motion, especially with the moving water. I also have an animated cloud layer that affects the sunlight, that doesn't show up too well in a static screen shot.

Share this comment


Link to comment
Quote:
Glad you guys like the look. AG actually looks a lot better in motion, especially with the moving water. I also have an animated cloud layer that affects the sunlight, that doesn't show up too well in a static screen shot.

I think you need to post a rolling (graphics) demo video [grin]

Jack

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!