Jump to content
  • Advertisement
Sign in to follow this  

Shadow Maps in XNA

This topic is 3749 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 + Vector3.Down;
                llookAt = Matrix.CreateLookAt(lightPosition, lLook, Vector3.Forward);
                
                DrawObjects("ShadowMap", llookAt, buildingModel, Matrix.Identity, llookAt, lProjection);
                
                graphics.GraphicsDevice.SetRenderTarget(0, null);
                texturedRenderedTo =  renderTarget.GetTexture();          
                
                shadowMaps = texturedRenderedTo;
                shadowMaps.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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!