public ShadowMap(GraphicsDevice graphicsDevice, Settings settings, SpriteBatch spriteBatch, Effect shadowMapEffect, Effect blurEffect) { if (graphicsDevice == null) throw new ArgumentNullException("graphicsDevice"); if (settings == null) throw new ArgumentNullException("settings"); if (spriteBatch == null) throw new ArgumentNullException("spriteBatch"); if (shadowMapEffect == null) throw new ArgumentNullException("shadowMapEffect"); if (blurEffect == null) throw new ArgumentNullException("blurEffect"); GraphicsDevice = graphicsDevice; this.settings = settings; this.spriteBatch = spriteBatch; this.shadowMapEffect = new ShadowMapEffect(shadowMapEffect); this.shadowMapEffect.ShadowMapTechnique = settings.Technique; Technique = settings.Technique; Size = settings.Size; DepthBias = settings.DepthBias; SplitCount = settings.SplitCount; inverseSplitCount = 1 / (float) SplitCount; splitDistances = new float[SplitCount + 1]; safeSplitDistances = new float[SplitCount + 1]; safeSplitLightViewProjections = new Matrix[SplitCount]; safeSplitShadowMaps = new Texture2D[SplitCount]; splitCameras = new BasicCamera[SplitCount]; for (int i = 0; i < splitCameras.Length; i++) splitCameras[i] = new BasicCamera("PssmLight" + i); splitLightCameras = new LightCamera[SplitCount]; for (int i = 0; i < splitLightCameras.Length; i++) splitLightCameras[i] = new LightCamera(settings.Size); // TODO: パラメータ見直し or 外部設定化。 var pp = GraphicsDevice.PresentationParameters; // メモ: ブラーをかける場合があるので RenderTargetUsage.PreserveContents で作成。 splitRenderTargets = new RenderTarget2D[SplitCount]; for (int i = 0; i < splitRenderTargets.Length; i++) { splitRenderTargets[i] = new RenderTarget2D(GraphicsDevice, settings.Size, settings.Size, false, settings.Format, DepthFormat.Depth24, 0, RenderTargetUsage.PreserveContents); splitRenderTargets[i].Name = "ShadowMap" + i; } // TODO: 初期容量。 splitShadowCasters = new Queue<ShadowCaster>[SplitCount]; for (int i = 0; i < splitShadowCasters.Length; i++) splitShadowCasters[i] = new Queue<ShadowCaster>(); if (settings.Technique == Techniques.Vsm) { blur = new GaussianBlur(blurEffect, spriteBatch, settings.Size, settings.Size, SurfaceFormat.Vector2, settings.VsmBlur.Radius, settings.VsmBlur.Amount); } Monitor = new ShadowMapMonitor(SplitCount); }
public ShadowMap(GraphicsDevice graphicsDevice, Settings settings, SpriteBatch spriteBatch, Effect shadowMapEffect, Effect blurEffect) { if (graphicsDevice == null) { throw new ArgumentNullException("graphicsDevice"); } if (settings == null) { throw new ArgumentNullException("settings"); } if (spriteBatch == null) { throw new ArgumentNullException("spriteBatch"); } if (shadowMapEffect == null) { throw new ArgumentNullException("shadowMapEffect"); } if (blurEffect == null) { throw new ArgumentNullException("blurEffect"); } GraphicsDevice = graphicsDevice; this.settings = settings; this.spriteBatch = spriteBatch; this.shadowMapEffect = new ShadowMapEffect(shadowMapEffect); this.shadowMapEffect.ShadowMapTechnique = settings.Technique; Technique = settings.Technique; Size = settings.Size; DepthBias = settings.DepthBias; SplitCount = settings.SplitCount; inverseSplitCount = 1 / (float)SplitCount; splitDistances = new float[SplitCount + 1]; safeSplitDistances = new float[SplitCount + 1]; safeSplitLightViewProjections = new Matrix[SplitCount]; safeSplitShadowMaps = new Texture2D[SplitCount]; splitCameras = new BasicCamera[SplitCount]; for (int i = 0; i < splitCameras.Length; i++) { splitCameras[i] = new BasicCamera("PssmLight" + i); } splitLightCameras = new LightCamera[SplitCount]; for (int i = 0; i < splitLightCameras.Length; i++) { splitLightCameras[i] = new LightCamera(settings.Size); } // TODO: パラメータ見直し or 外部設定化。 var pp = GraphicsDevice.PresentationParameters; // メモ: ブラーをかける場合があるので RenderTargetUsage.PreserveContents で作成。 splitRenderTargets = new RenderTarget2D[SplitCount]; for (int i = 0; i < splitRenderTargets.Length; i++) { splitRenderTargets[i] = new RenderTarget2D(GraphicsDevice, settings.Size, settings.Size, false, settings.Format, DepthFormat.Depth24, 0, RenderTargetUsage.PreserveContents); splitRenderTargets[i].Name = "ShadowMap" + i; } // TODO: 初期容量。 splitShadowCasters = new Queue <ShadowCaster> [SplitCount]; for (int i = 0; i < splitShadowCasters.Length; i++) { splitShadowCasters[i] = new Queue <ShadowCaster>(); } if (settings.Technique == Techniques.Vsm) { blur = new GaussianBlur(blurEffect, spriteBatch, settings.Size, settings.Size, SurfaceFormat.Vector2, settings.VsmBlur.Radius, settings.VsmBlur.Amount); } Monitor = new ShadowMapMonitor(SplitCount); }