Jump to content
  • Advertisement
Sign in to follow this  
spek

(cheap) Shadow casting

This topic is 4874 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

Hi, I'd like to add some shadows to a building to give some more realism. Default lighting isn't enough as area's behind other walls or inside the building are litten as well of course. As far as I know, there are 3 ways to add shadows: - pre-computed lightmaps - volumetric shadows - shadow mapping Lightmaps can give nice results, however, there are some complications. First of all, there are many different buildings and tons of other textures that need to be loaded all at the same time. I'm trying to save as much memory as possible so... Then there's another problem. The direction between the main lightsource (the sun/moon) can be different everytime and as it can go day and night, the shadows/lightspots won't be correct at all times. Besides of that, the buildings are dynamic structures. Each building is a set of sub-objects like a wall or pillar that can be removed. What I need is a shadowing method that can handle these problems. It doesn't have to be ultra-realistic but some soft shadows would be nice :) Besides of that, there's not that much power to compute shadows as there are many other things so it needs to be a 'cheap' method. Its some C&C like-game so there's lots of other stuff to handle as well. Any smart tricks? Greetings!

Share this post


Link to post
Share on other sites
Advertisement
Stencil shadows? There are a few techniques around for postprocessing stencil shadows to 'soften' them a little.

Beyond that, you're talking about a fully dynamic shadowing method for a large amount of geometry, or so it sounds to me. 'Cheap' is probably not an option.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I already was afraid it wouldn't be cheap. But on the bright side, it probably takes another million years to finish this hobby game so computers are probably fast enough by then :)

Stencil shadows... isn't that volumetric shading? I never made it myself but from what I saw from it, it gives pretty accurate results, although a little bit (too) sharp. But there's probably that softening technique for you're talking about. If I understand it right, this technique renders the building to the stencil buffer or something to create volumes/silhouettes. Ifso, that would mean the building is rendered twice right? In that case, its probably possible to use a simplified version of the building for that, although the buildings don't have that much polygons anyway.

How does the receiving of such a shadow works? I tried it before with a component (not my own code so that's why I don't really know how it works) but then my building dissapeared for a part. The simple sub-objects stayed but the (heavily) shaded walls and pillars were gone...

Thanks for helping!

Share this post


Link to post
Share on other sites
Yes, you draw the building (1 + number_of_lights) times.
Yes, you could simplify the mesh but consider this:
Many times the first one is splitted into two drawings:
1. drawing to the zbuffer
2. drawing the building with ambient lighting

(these two can be combined into 1)

The second drawing prevents black holes in your scene by faking a certain amount of ambient light.

To optimize you could consider using a simplified mesh to generate the shadowvolume. Shadowvolume creation is very expensive. So by not using a detailed mesh and by not using the most up-to-date version of the mesh (let the shadow trail behind in animations) you will gain more.

Cheers

Share this post


Link to post
Share on other sites
For stencil shadows, check out this page on nVidia's website. I think it has just about everything you need to know.

For softening stencil shadows there are two methods that I know of (although I think there are other similar to the second). First, replace a single point light with multiple dimmer point lights. This is very expensive because I'd say at least 4 lights are needed to get a semi-realistic soft shadow and that's going to cost you pretty much 4 times as much as just using one light.

The second method is in this paper. The method in the paper involves reading back the depth/colour buffers and drawing penumbra wedges manually, but it should be possible to do this in a pixel shader. If so this is definately the method to go for.

Share this post


Link to post
Share on other sites
Once again, thanks! This forum is always helpfull. I think I should check stencil shadows as there don't seem to be much other choices that can handle a dynamic scene for now.

Greetings,
Rick

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!