Sign in to follow this  
HurtLockeR

Shadow Mapping - How to make geomtery block shadow casting

Recommended Posts

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!

Edited by HurtLockeR

Share this post


Link to post
Share on other sites

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? 

Edited by HurtLockeR

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites

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

Edited by HurtLockeR

Share this post


Link to post
Share on other sites

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*.

Edited by Styves

Share this post


Link to post
Share on other sites

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.

Edited by Orangeatang

Share this post


Link to post
Share on other sites

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).

Share this post


Link to post
Share on other sites

If only the dynamic objects are casting real time shadows, you can build a unique shadow map for each, then have them project into the scene by rendering small boxes around the gynamic geo extruded/ stretched in the light direction (deferred shadow map style). You could then limit this extrusion by some arbitrary amount to avoid them reaching casting too far, based on your scene. Kind of hacky, but would work in most cases.

Share this post


Link to post
Share on other sites

Thanks for the ideas. Hope I can get somewhere smile.png

 

Would it be an idea/possible to have 2 shadow depth textures (D3DFMT_32F), and then in one I render the entire scene: static + dynamic models.

(Even though I don't want static models like bridges, houses, walls, etc. to cast shadows since I use lightmapping for those)

 

And then to the 2nd texture I only render all dynamic models.

 

Then in the 2nd pass shadow shader, I test against the 1st buffer but if the test passes I use the data from the 2nd?

 

 

I keep thinking some games must have used something like this (lightmapped scenes + dynamic shadows)? It sounds pretty simple to implementsad.png

Edited by HurtLockeR

Share this post


Link to post
Share on other sites

A better approach is to use a G16R16F texture and store dynamic geometry into the red channel and static in the green channel. Then when you read it in you can compare the shadow to the static depth too, without needing to read extra textures (or wasting more memory).

 

Honestly though, if you're going to go through the trouble of rendering your static geometry into a shadow map anyway, you might as well use them in the shadow mapping stage and reserve your lightmaps for your indirect lighting. It will look a lot more consistent to have the same shadows on all objects (look at "The Last of Us", they do this).

 

Most of the time "the other guys" use some form of blending like I mentioned. Just pre-compute the lightmap shadows (no GI or indirect lighting, just shadows) to the alpha channel of your lightmap textures (or wherever) and use this as a mask for your shadows. Then you can check if your shadow is inside a lightmapped shadow and just remove it. Rendering all your static objects to a shadow map and not using them at all for shadows (just masking) is a bit redundant and negates the point of having lightmap shadows in the first place.

Edited by Styves

Share this post


Link to post
Share on other sites

A better approach is to use a G16R16F texture and store dynamic geometry into the red channel and static in the green channel. Then when you read it in you can compare the shadow to the static depth too, without needing to read extra textures (or wasting more memory).

 

Honestly though, if you're going to go through the trouble of rendering your static geometry into a shadow map anyway, you might as well use them in the shadow mapping stage and reserve your lightmaps for your indirect lighting. It will look a lot more consistent to have the same shadows on all objects (look at "The Last of Us", they do this).

 

Most of the time "the other guys" use some form of blending like I mentioned. Just pre-compute the lightmap shadows (no GI or indirect lighting, just shadows) to the alpha channel of your lightmap textures (or wherever) and use this as a mask for your shadows. Then you can check if your shadow is inside a lightmapped shadow and just remove it. Rendering all your static objects to a shadow map and not using them at all for shadows (just masking) is a bit redundant and negates the point of having lightmap shadows in the first place.

 

http://miciwan.com/SIGGRAPH2013/Lighting%20Technology%20of%20The%20Last%20Of%20Us.pdf

There is presentation that explain how "Last of us" does their lights and shadows. Some levels only contains fully baked lightmap that contain main directional component of lighting and ambient color. These are used by gpu and sub resolution copy of screen space buffer about is handed to SPU. Then per pixel direction value is used as starting point for cone trace against dynamics objects that are approximated with spheres. This is how they get super soft dynamic directional and ambient occlusion shadows that blend perfectly with baked light maps. Quite hacky and complicated(at least implementation wise).

Edited by kalle_h

Share this post


Link to post
Share on other sites

Yeah I finally got to look at the paper after my post, seems I jumped the gun on using it as a reference. I remember them mentioning this for Uncharted 2 though. At any rate I didn't see any lightmapped shadows in the Uncharted games, only lightmapped GI.

 

Still, the concept can work for the OP. smile.png The idea is to blend the lighting together to make it consistent, doesn't really matter how OP chooses to do it.

Edited by Styves

Share this post


Link to post
Share on other sites

Hello Styves, kale_h,

 

Thanks for your suggestions! I decided to go with the lightmap blending option. This is the easiest to implement: just make sure the world light is in the same position as the lightmap lighting, and then blend the realtime dynamic shadows with the baked lightmaps in the shader.

 

This makes the realtime shadows and the lightmap shadows blend perfectly, and there's no need to depth pass the static models! Frame rate = happy.

 

This whole thing of blending lightmaps and realtime shadows is actually interesting since it could give you the best of both worlds until hardware will be fast enough to do global illumination + shadows on detailed levels, which is probably a few years off yet.

 

If you make the realtime shadows soft, then you can't really tell the difference between what's pre-lightmapped and what's real time.

 

Thanks again, next step will be to look into the Last of Us shadowing! (especially hard edged shadows close up and softer at a larger model distance).

Edited by HurtLockeR

Share this post


Link to post
Share on other sites

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

Sign in to follow this