XNA Creators Club Online
Page 1 of 1 (4 items)
Sort Posts: Previous Next

Some questions about shadows

Last post 05-12-2008 3:46 PM by jwatte. 3 replies.
  • 05-11-2008 6:47 PM

    Some questions about shadows

    For a while now, I've been trying to find the best way to get shadows into my game.  From a tutorial I saw on using a stencil buffer, it appeared as though you can only use that to cast shadows onto a plane.  I want to have objects cast shadows on anything, including themselves.  So I heard about shadow mapping.  I followed a tutorial on that, but I didn't like the results. They were very jaggy, and not visually impressive.  Finally, I found a sample with variance shadow mapping. I loved the results I was getting, but when I ran it on other computers, it went way too slow to be feasible for a game.  Also, when I moved a model somewhat far away from a light, and then went into a building, the shadow would suddenly become very pixelly.

    Basically, I just want shadows that aren't necessarily soft, but not sharp and jagged either. So now I have some questions:

    How costly would it be to use a standard shadow map, and then use a gaussian blur to make it a little softer? How nice would that look?

    Are stencil shadows limited to casting shadows on one plane, or am I mistaken? Are they better than shadow maps, or does it depend on my needs?

    Also, when using a shadow map, should I be moving the light closer to the objects when the camera is more zoomed in on an object?

    Right now my game has normal mapping and bloom lighting. To finish off with the graphics, I wanted basic shadows that aren't pixelly, but nothing fancy.  Does anyone have any suggestions?

    Thank you very much for your replies!
  • 05-12-2008 3:55 AM In reply to

    Re: Some questions about shadows

    If your models are closed, and not too high-poly, you could try shadow volumes. Shadow volumes dont suffer from aliasing but they are relatively expensive in CPU time. Soft shadows can be done with shadow volumes, but AFAIK the only way involves having two shadow volumes for each shadowing object, which is pretty hard on performance.

    You cant just apply a gaussian blur to a standard shadow map, since the map stores depth values. When you blur the shadow map, the depth values become invalid. You could possibly render out the shadows to a screen buffer and then blur that, deferred-style, but the results would probably look quite strange.

    Alternately you can use projective shadows, where you render shadow maps from the geometry you want to be shadowed, blur them, and then apply them as a texture on the geometry you want to shadow. If anything gets between the caster and the receiver its not really gonna work out well though ;)

    Hope that helps.

  • 05-12-2008 3:13 PM In reply to

    Re: Some questions about shadows

    Hmmm, I could try shadow volumes, but that would require a pretty high-end computer, wouldn't it?  Can you tell me which requires more processing power? Variance shadow mapping, or shadow volumes?

    Also, I didn't want to blur the shadow map.  I meant the buffer containing the shadows, like you said.

    Projective shadows could work, but I kind of want to have dynamic shadows for the characters in my game, as I'm going for a realistic look.

    Thank you very much for your reply, I'll look into shadow volumes.
  • 05-12-2008 3:46 PM In reply to

    Re: Some questions about shadows

    Shadow volumes (stencil) are all about fill rate. If you have a very small window (640x480), or a very fast fill card (GeForce 6800 and up, say), then it will likely work fine.

    Shadow maps can't be blurred in map space, because they store depth, not color. Blurring doesn't do the right thing. You have to blur when you fetch the texture, which makes texturing more expensive (say, fetching 9 or 12 samples per shadow texel). You can also blur in screen space, but that causes problems with leaking.

    My currently preferred method is cascading shadow maps. I think Tom Forsyth has a good article about it, if you google it.

    Jon Watte, Direct3D MVP kW X-port 3ds Max .X exporter kW Animation source code
Page 1 of 1 (4 items) Previous Next