void DrawShadowMap() { Instrument.Begin(InstrumentDrawShadowMap); //---------------------------------------------------------------- // 準備 ShadowMap.Prepare(activeCamera); //---------------------------------------------------------------- // 投影オブジェクトを収集 for (int i = 0; i < shadowCasters.Count; i++) { ShadowMap.TryAddShadowCaster(shadowCasters[i]); } //---------------------------------------------------------------- // シャドウ マップを描画 var lightDirection = activeDirectionalLight.Direction; ShadowMap.Draw(ref lightDirection); Instrument.End(); }
public Sssm(SpriteBatch spriteBatch, ShadowMap.Settings shadowMapSettings, Settings sssmSettings, Effect shadowSceneEffect, Effect sssmEffect, Effect blurEffect) : base(spriteBatch) { if (shadowMapSettings == null) throw new ArgumentNullException("shadowMapSettings"); if (sssmSettings == null) throw new ArgumentNullException("sssmSettings"); if (shadowSceneEffect == null) throw new ArgumentNullException("shadowSceneEffect"); if (sssmEffect == null) throw new ArgumentNullException("sssmEffect"); if (blurEffect == null) throw new ArgumentNullException("blurEffect"); this.shadowMapSettings = shadowMapSettings; this.sssmSettings = sssmSettings; this.sssmEffect = sssmEffect; //================================================================ // シャドウ シーン //---------------------------------------------------------------- // エフェクト this.shadowSceneEffect = new ShadowSceneEffect(shadowSceneEffect); this.shadowSceneEffect.DepthBias = shadowMapSettings.DepthBias; this.shadowSceneEffect.SplitCount = shadowMapSettings.SplitCount; this.shadowSceneEffect.ShadowMapSize = shadowMapSettings.Size; this.shadowSceneEffect.ShadowMapTechnique = shadowMapSettings.Technique; //---------------------------------------------------------------- // レンダ ターゲット var pp = GraphicsDevice.PresentationParameters; var width = (int) (pp.BackBufferWidth * sssmSettings.MapScale); var height = (int) (pp.BackBufferHeight * sssmSettings.MapScale); // メモ: ブラーをかける場合があるので RenderTargetUsage.PreserveContents で作成。 shadowSceneMap = new RenderTarget2D(GraphicsDevice, width, height, false, SurfaceFormat.Color, DepthFormat.Depth24, 0, RenderTargetUsage.PreserveContents); //================================================================ // スクリーン スペース シャドウ マッピング //---------------------------------------------------------------- // エフェクト shadowColorParameter = sssmEffect.Parameters["ShadowColor"]; shadowSceneMapParameter = sssmEffect.Parameters["ShadowSceneMap"]; currentPass = sssmEffect.CurrentTechnique.Passes[0]; //---------------------------------------------------------------- // ブラー if (sssmSettings.BlurEnabled) { var blurSettings = sssmSettings.Blur; blur = new GaussianBlur(blurEffect, spriteBatch, width, height, SurfaceFormat.Vector2, blurSettings.Radius, blurSettings.Amount); } }
void DrawScene(ShadowMap shadowMap) { Instrument.Begin(InstrumentDrawScene); GraphicsDevice.DepthStencilState = DepthStencilState.Default; GraphicsDevice.SetRenderTarget(RenderTarget); GraphicsDevice.Clear(new Color(BackgroundColor)); //================================================================ // // オクルージョン クエリ // Instrument.Begin(InstrumentOcclusionQuery); GraphicsDevice.BlendState = colorWriteDisable; for (int i = 0; i < opaqueObjects.Count; i++) { opaqueObjects[i].UpdateOcclusion(); } //for (int i = 0; i < translucentObjects.Count; i++) // translucentObjects[i].UpdateOcclusion(); Instrument.End(); //================================================================ // // 描画 // Instrument.Begin(InstrumentDrawSceneObjects); //---------------------------------------------------------------- // 不透明オブジェクト GraphicsDevice.BlendState = BlendState.Opaque; for (int i = 0; i < opaqueObjects.Count; i++) { var opaque = opaqueObjects[i]; if (opaque.Occluded) { OccludedSceneObjectCount++; continue; } opaque.Draw(); } //---------------------------------------------------------------- // 半透明オブジェクト GraphicsDevice.BlendState = BlendState.AlphaBlend; for (int i = 0; i < translucentObjects.Count; i++) { var translucent = translucentObjects[i]; if (translucent.Occluded) { OccludedSceneObjectCount++; continue; } translucent.Draw(); } //---------------------------------------------------------------- // スカイ スフィア foreach (var obj in skySphereNode.Objects) { if (obj.Visible) { obj.Draw(); } } //if (skySphere != null && skySphere.Visible) // skySphere.Draw(); Instrument.End(); GraphicsDevice.SetRenderTarget(null); Instrument.End(); }