Skip to main content
GameDev.net gamedev.net
🔒 Locked

xna and shadows/shadow volumes

Started by EvilWeebl Aug 12, 2010 at 5:12 PM 3 replies 3.8k views
Original Post
EvilWeebl
EvilWeebl
Hi all, I've recently been messing around with shaders in xna and am now moving onto using them for shadows. I have successfully implemented shadow mapping thanks to reimers site but am not happy with the quality this technique produces. I have looked at many forms of shadowing techniques and shadow volumes/stencil shadows appeals to me.

The reason for this is I want to make a game with the viewpoint of a little big planet game(3d but side on and scrolling) but with a large focus on the shadows(a key concept of the game story and design). Now in this I would like to try and make possible collision detection between shadows. I was thinking collision between shadow volumes could be possible or possibly faking it with per pixel 2d collision with sprites projected on the background wall.

Any ideas how i could test for shadow collisions? Also I cannot find any tutorials for shadow volumes with xna anywhere, can anybody provide links.

I love how this game works and would really like to know how its done and what shadow technique it uses - http://www.shadowphysics.com/

Any help would be greatly appreciated
EvilWeebl
EvilWeebl
Can nobody provide insight into this? Perhaps some source code/demo of shadow volumes being used in xna?

If I can at least get this down then any collision stuff can be an after thought for now.
Cygon
Cygon
I have used shadow volumes in my first XNA game. I wrote it back in the XNA 1.0 days (I've updated the code to XNA 3.1 in the meantime, though) - I wasn't aware of the garbage issue and used lists, enumerators and temporary objects pretty indiscriminately. On the positive side, it's clean code and well documented ;)

This helper takes the triangles from a mesh (as IEnumerable) and generates a line list of the mesh's silhouette as seen from the direction of a light source:
SilhouetteGenerator.cs

This class extrudes that silhouette into a skirt:
ShadowVolumeGenerator.cs

I didn't bother to generate a cap for the skirt (that requires a tessellator), because in my game I always had a floor cutting off the shadow volume.

This is the shader I use to prepare the stencil buffer by rendering the skirt after the scene has already been drawn. It doesn't change any pixels, it only modifies the stencil buffer where the z-buffer doesn't clip off the skirt polygons (carmack's reverse, essentially):
StencilShadowVolume.fx

After the, I simply render a big, alpha-blended quad over the whole screen, drawing only the portions where the stencil bits aren't counted back to zero yet.

Hope this helps! :)
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
MJP
MJP
People don't really go for shadow volumes anymore, because they have some very undesirable/unpredicatable performance characteristics. If the light is at a certain angle you can end up burning through your fillrate. They also don't scale very well at all with geometric complexity, which often requires that you use a low-detail mesh for generating the volumes. Shadow maps, on the other hand, generally have much more stable and predictable performance.
EvilWeebl
EvilWeebl
Thanks alot Cygon thats a great help! Sorry for the late reply i've been miles away. So I think between what you've shown me and the directx shadow volume tutorial I can nail this but i've still been racking my brain as to how I could do collision between the shadows cast on a wall... any ideas?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.