(cheap) Shadow casting

Started by
5 comments, last by krausest 18 years, 10 months ago
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!
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.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

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!
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
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.
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
Don't miss Lengyel GDC presentation on http://www.terathon.com/gdc_lengyel.ppt .
He discusses both hard and soft shadow volumes. He recently mentioned that you shouldn't expect too much performance of the soft shadow approach in this thread:
http://www.gamedev.net/community/forums/topic.asp?topic_id=321395

This topic is closed to new replies.

Advertisement