Jump to content
  • Advertisement
Sign in to follow this  
karx11erx

How to prevent shadows to penetrate walls?

This topic is 4242 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Following problem: Light source -> object -> wall <- viewer With this constellation, the object's shadow penetrates the wall between object and viewer. One should think that the wall that would block the light and the shadow of the object behind the wall is a back face, but disabling face culling didn't cure this. How do I prevent such things from happening?

Share this post


Link to post
Share on other sites
Advertisement
I've been wondering about that also.
Only thing I would suggest is to have the wall be made up of two faces, with their backfaces facing each other. The shadow might not get to the second face.

Share this post


Link to post
Share on other sites
You're looking at it from the wrong angle - you don't need to stop the shadow penetrating the wall, you need to stop the light penetrating the wall in the first place. Then the shadow will be invisible.

Assuming you're using shadow volumes (since you mentioned that in your second post) then having the walls themselves cast shadows should fix it.

Share this post


Link to post
Share on other sites
Yeah, shadow volumes (z-fail). The problem is that there is a light source behind the wall too. So the wall doesn't cast a shadow.

Just imagine two big halls, connected by a doorway. Both halls are lit and contain objects. The shadows of the objects in one hall will be visible in the other hall, because that hall is lit, too.

Share this post


Link to post
Share on other sites
OrangyTang is right. If the wall casts shadows like other objects, shadows won't "penetrate" walls. Just try it ^^ (remember that walls need to have a facing face in both directions for this to work, like blakedev said).

Share this post


Link to post
Share on other sites
Spawn,

maybe you don't understand. The walls would themselves cast shadows into lit areas. Just read what I wrote about the two halls. They are lit independently. In that sense you could say that the light penetrating the walls of hall 1 does not affect hall 2 because it has its own light source. Now if the walls of hall 1 cast a shadow, that shadow will darken hall 2 just as the object shadows from hall 1. What I need is some stencil buffer updating using the shadow volumes of hall 1's walls to make the object shadows from hall 1 disappear. But how?

Share this post


Link to post
Share on other sites
Quote:
Original post by karx11erx
Spawn,

maybe you don't understand. The walls would themselves cast shadows into lit areas. Just read what I wrote about the two halls. They are lit independently. In that sense you could say that the light penetrating the walls of hall 1 does not affect hall 2 because it has its own light source. Now if the walls of hall 1 cast a shadow, that shadow will darken hall 2 just as the object shadows from hall 1. What I need is some stencil buffer updating using the shadow volumes of hall 1's walls to make the object shadows from hall 1 disappear. But how?


don't render the shadows.

render the entire scene with ambient light only, then render one pass / lightsource using the appropriate stencil buffer to exclude the areas covered by that lights shadow volumes.

rendering a black quad over the shadowed areas gives all kinds of problems and doesn't look that great. (its quick though)

Share this post


Link to post
Share on other sites
Simon,

I don't really understand.

I have two shadow render paths: One renders the entire mine bright, then renders all object's shadows into the stencil buffer, then renders a dark quad.

The other renders the mine dark, renders all object's shadows into the stencil buffer, then renders the mine bright where the stencil is 0.

Both paths create shadows penetrating walls.

Thank you for your input, but from what you wrote I don't understand what to change. It's just too general.

Share this post


Link to post
Share on other sites
Quote:
Original post by karx11erx
Simon,

I don't really understand.

I have two shadow render paths: One renders the entire mine bright, then renders all object's shadows into the stencil buffer, then renders a dark quad.

The other renders the mine dark, renders all object's shadows into the stencil buffer, then renders the mine bright where the stencil is 0.

Both paths create shadows penetrating walls.

Thank you for your input, but from what you wrote I don't understand what to change. It's just too general.


basically you have to use the second method BUT,
after the first dark render you have to do this:

for each light:
calculate shadow volumes.
render shadow volumes to stencil buffer
render the scene with that light only, no ambient light and don't render the shadowed parts. Then add the result to the existing one, (additive blending).
clear stencil buffer
repeat for the next light.

basically you have to render the scene n+1 times, where n is the number of lights affecting the scene

a good idea is to limit the number of lights that can affect a specific object (say a character) thus limiting the number of passes needed for it, 2-3 lights on a small object (such as the player) should be enough. pick the lights that has the largest effect.

One thing to remember, multipass solutions are expensive, many older games (Jedi Knight 2 for example) uses a method similar to the one you are using and does suffer from shadows punching trough walls as well.

im pretty sure someone can figure out a way to do nice volymetric shadows in a single pass with some fancy shader magic though.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!