Shadow Mapping - How to make geomtery block shadow casting

Started by
15 comments, last by HurtLockeR 10 years, 8 months ago

Hello everyone,

Quick shadow mapping question:

I have shadow mapping working (using DirectX 9) based on the soft shadow tut here on gamedev.

http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/soft-edged-shadows-r2193

The problem I have is that I have the static scene lightmapped (walls, buildings, etc.) and I don't want those casting shadows. I only want the dynamic models such as the player to cast shadows.

But I still need the depth from the static models otherwise the shadows won't look correct.

For example:

The player model is standing on a bridge. Shadow light is directly above him. His shadow appears correctly on the bridge road, but the same shadow also appears on the ground under the bridge, where of course there shouldn't be any visible shadow since the bridge would block the player's shadow. (the bridge itself isn't a shadow caster since it's part of a lightmapped scene).

How can I make geometry block the shadow casting? Is there something simple I am missing and need to add some sort of extra depth checking pass to the shader?

Can anyone tell me what's needed? Many thanks in advance!

Advertisement

Doesn't block shadows? huh.png

It sounds to me like the problem isn't with your characters shadow, but rather the lack of a bridge shadow.

Bridge doesn't cast shadow?

Ninjad by Chris.

Maybe I'm not being clear sorry smile.png

Let's say there's a box in a house, on the second floor. The box's shadow is correct on that floor.

But on the ground floor, the same shadow appears, because the floor doesn't block the shadow. So in the shader, when I draw the 2nd floor it is shadowed, but when I draw the

ground, it is also shadowed.

I assume shadows shouldn't be visible on geometry which is 'invisible' to the light.

The bridge is not a shadow caster. But whether the bridge itself cast shadows or not shouldn't make any difference - that will simply 'hide' the problem.

Suppose I don't want certain objects like the bridge not to cast shadows because they're lightmapped or whatever. The player shadow should still work correctly, surely?

There must be some kind of depth check necessary in the shader to prevent the shadow from being drawn onto geometry invisible to the light?


Whether the bridge itself cast shadows or not shouldn't make any difference?

It makes a big difference!


There must be some kind of depth check necessary in the shader to prevent the shadow from being drawn onto geometry invisible to the light?

No, you must draw all geometry that blocks the light if you want natural visual representation.

Thanks belfegor,

But if the bridge's shadow (or a house's shadow) is already lightmapped onto the terrain below, and I don't want real-time shadows from that, only from the player.

This sound reasonable simple and surely should be possible?

Not every single object in a game needs to be a shadow caster. I understand that if I draw the bridge's shadow, things will 'look' fine, but I don't want it to cast shadowsmellow.png

bool castshadows=false;

Why not just not pass that mesh in during shadow generation?

Check out some of the tech behind the Toy Story 3 game. They have a shadow like this for the player character that is independent of the scene, sounds a lot like what you want.

You can also try applying the shadows to the scene based on luminance (or precalculated shadows or some such) from your lightmap, that way dynamic shadows will only render in areas that are *lit*.


But on the ground floor, the same shadow appears, because the floor doesn't block the shadow. So in the shader, when I draw the 2nd floor it is shadowed, but when I draw the
ground, it is also shadowed.

Hey HurtLockeR,

When you're doing your lighting pass, are you checking the depth of the current vertex (converted to light-view space) against the value stored in the light's depth map? The ground floor should be completely blocked since the floor above is closer to the light source.

The problem however is that the floor above isn't in the shadow map, which means there's no way to check the depth of the ground floor and compare it to the other floor.

The only way to solve this is some form of shadowing term from the lightmaps that will affect the shadow contribution. Otherwise you should use shadow mapping for all shadows (regardless if static) and use the lightmaps for indirect lighting (Naughty Dog style).

This topic is closed to new replies.

Advertisement