I want to try adding shadows to a 3D XNA game. I've set up some testing environment with one light and one camera. However, I'm running into artifacts with my approach.
I'm using the shader code from http://pastebin.com/zXi0hmsU to render the final result and http://pastebin.com/rY4Gcj9N to create the shadow maps. The code is pretty straight forward and involves production of the depthmap from the light point of view, then projecting it into the camera space and checking for occlusions.
However, from most angles I am getting pretty ugly results
The scene consists of some simple cubes (constructed by hand, facing outside, backface is culled), one light (shadow map shown in top left corner - looks okay) and one camera.
My RenderTarget for the shadow maps is initialized by
int shadowMapSize = 512; RenderTarget2D shadowMap = new RenderTarget2D(GraphicsDevice, shadowMapSize, shadowMapSize, true, GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24Stencil8); GraphicsDevice.SetRenderTarget(shadowMap); GraphicsDevice.Clear(Color.White); GraphicsDevice.DepthStencilState = DepthStencilState.Default;
CreateShadowMap effect is applied, followed by the LambertWithShadows effect. Finally, the shadow map is drawn using a
Rest of the code consists of simply providing the correct values to the shaders. If necessary, I can provide it at well.