Sign in to follow this  

Shadow Maps in XNA

This topic is 3588 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm getting some strange results when I try to store shadow maps in a Texture2D array. What I'm trying to do is this: Have 4 different spot lights create 4 different shadow maps. Each map is stored in an element in a Texture2D array. Here is how I’m generating the maps in my Draw method:
 Matrix[] llookAt = new Matrix[4];
            Matrix lProjection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(phi), graphics.GraphicsDevice.Viewport.AspectRatio, 0.1f, 5000f);

            shadowMaps = new Texture2D[4];


            for (int i = 0; i < 4; i++)
            {

                graphics.GraphicsDevice.SetRenderTarget(0, renderTarget);
                graphics.GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Blue, 1.0f, 0);

                Vector3 lLook = lightPosition[i] + Vector3.Down;
                llookAt[i] = Matrix.CreateLookAt(lightPosition[i], lLook, Vector3.Forward);
                
                DrawObjects("ShadowMap", llookAt[i], buildingModel, Matrix.Identity, llookAt, lProjection);
                
                graphics.GraphicsDevice.SetRenderTarget(0, null);
                texturedRenderedTo =  renderTarget.GetTexture();          
                
                shadowMaps[i] = texturedRenderedTo;
                shadowMaps[i].Save("screenshot" + i.ToString() + ".bmp", ImageFileFormat.Bmp);  //<--- maps are saved no problem.  
                shadowMaps[0].Save("ss" + 0 + ".bmp", ImageFileFormat.Bmp); //<---- map looks just like the last one not the first one. THIS IS WHERE THE ISSUE IS.

            }

When I read the textures right after that for loop all the textures come out looking like the last element in the array. Any ideas??

Share this post


Link to post
Share on other sites

This topic is 3588 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this