Sunday 19 July 2009

XNA Moving Shadow Sample

I have added shadows to a moving skinned model. I could not find a similar example of this already having been done that showed how, so I have posted my code here.

UPDATE: This version now uses Parallel Split Shadow Maps (PSSM, for XNA 3.1).

This is a sample to show the moving shadows. The models used are just to show the shadows and that attached models also have shadows. (Many thanks to the artists who created the original meshes, sorry I don't know who you are.)

The basic process was to join the XNA Creators Club Skinning Sample effect file with the MSDN Shadow Mapping sample effect file. With a bit of messing about I got it to work. This updated version was then modified based on some Direct3D examples and the NVidia GPU Gems articles. This is still work in progress it just demonstrates the moving shadows, there is still more work to do like adding Percentage Closer Filtering (PCF). The download includes a complete working XNA 3.0 source code project. See the comments in the code for more details. Look at the RenderShadows() method in GameplayScreen.cs and follow this to the Shadows.cs class. The two Effect shaders are also essential reading.

Download Source Code

XNA Shadow Sample (22Mb) July 2009 for XNA 3.1