Jump to content

  • Log In with Google      Sign In   
  • Create Account

Shadow Mapping - How to make geomtery block shadow casting


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
16 replies to this topic

#1 HurtLockeR   Members   -  Reputation: 106

Like
0Likes
Like

Posted 28 July 2013 - 07:58 AM

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, 29 July 2013 - 08:03 AM.


Sponsor:

#2 Chris_F   Members   -  Reputation: 2462

Like
0Likes
Like

Posted 28 July 2013 - 08:05 AM

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.



#3 belfegor   Crossbones+   -  Reputation: 2719

Like
0Likes
Like

Posted 28 July 2013 - 08:06 AM

Bridge doesn't cast shadow?

 

Ninjad by Chris.


Edited by belfegor, 28 July 2013 - 08:07 AM.


#4 HurtLockeR   Members   -  Reputation: 106

Like
0Likes
Like

Posted 28 July 2013 - 08:14 AM

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, 28 July 2013 - 08:28 AM.


#5 belfegor   Crossbones+   -  Reputation: 2719

Like
0Likes
Like

Posted 28 July 2013 - 08:28 AM


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.



#6 HurtLockeR   Members   -  Reputation: 106

Like
0Likes
Like

Posted 28 July 2013 - 08:32 AM

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, 28 July 2013 - 08:35 AM.


#7 Burnt_Fyr   Members   -  Reputation: 1249

Like
0Likes
Like

Posted 28 July 2013 - 12:56 PM

bool castshadows=false;

 

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



#8 Styves   Members   -  Reputation: 1077

Like
0Likes
Like

Posted 28 July 2013 - 01:59 PM

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, 28 July 2013 - 02:01 PM.


#9 Orangeatang   Members   -  Reputation: 1782

Like
0Likes
Like

Posted 29 July 2013 - 01:25 AM


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, 29 July 2013 - 01:35 AM.


#10 Styves   Members   -  Reputation: 1077

Like
1Likes
Like

Posted 29 July 2013 - 05:45 AM

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



#11 ATEFred   Members   -  Reputation: 1127

Like
0Likes
Like

Posted 29 July 2013 - 06:48 AM

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.



#12 Orangeatang   Members   -  Reputation: 1782

Like
0Likes
Like

Posted 29 July 2013 - 07:00 AM


The problem however is that the floor above isn't in the shadow map

Yeah good point :)



#13 HurtLockeR   Members   -  Reputation: 106

Like
0Likes
Like

Posted 29 July 2013 - 07:38 AM

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, 29 July 2013 - 07:40 AM.


#14 Styves   Members   -  Reputation: 1077

Like
2Likes
Like

Posted 29 July 2013 - 10:31 AM

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, 29 July 2013 - 10:31 AM.


#15 kalle_h   Members   -  Reputation: 1567

Like
1Likes
Like

Posted 30 July 2013 - 01:59 PM

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, 30 July 2013 - 02:00 PM.


#16 Styves   Members   -  Reputation: 1077

Like
0Likes
Like

Posted 31 July 2013 - 04:42 AM

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, 31 July 2013 - 04:45 AM.


#17 HurtLockeR   Members   -  Reputation: 106

Like
0Likes
Like

Posted 31 July 2013 - 11:47 AM

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, 31 July 2013 - 11:52 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS