using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace Kav { public class DirectionalShadowMapData { public static readonly int MAX_SHADOW_CASCADES = 4; public RenderTarget2D[] ShadowMaps { get; } public Matrix LightSpaceMatrixOne { get; set; } public Matrix LightSpaceMatrixTwo { get; set; } public Matrix LightSpaceMatrixThree { get; set; } public Matrix LightSpaceMatrixFour { get; set; } public float[] CascadeFarPlanes { get; } public int ShadowMapSize { get; } public int NumShadowCascades { get; } internal DirectionalShadowMapData( GraphicsDevice graphicsDevice, int shadowMapSize, int numCascades ) { ShadowMapSize = shadowMapSize; NumShadowCascades = (int)MathHelper.Clamp(numCascades, 1, MAX_SHADOW_CASCADES); ShadowMaps = new RenderTarget2D[NumShadowCascades]; for (var i = 0; i < NumShadowCascades; i++) { ShadowMaps[i] = new RenderTarget2D( graphicsDevice, shadowMapSize, shadowMapSize, false, SurfaceFormat.Single, DepthFormat.Depth24, 0, RenderTargetUsage.PreserveContents ); } CascadeFarPlanes = new float[MAX_SHADOW_CASCADES]; } public void Clear(GraphicsDevice graphicsDevice) { foreach (var shadowMap in ShadowMaps) { graphicsDevice.SetRenderTarget(shadowMap); graphicsDevice.Clear(Color.White); } } } }