Jump to content
  • Advertisement
Sign in to follow this  

Shadow Maps in XNA

This topic is 3929 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
Sign in to follow this  

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!