Пример #1
0
        public Bloom(SpriteBatch spriteBatch, Settings settings, Effect bloomExtractEffect, Effect bloomEffect, Effect blurEffect)
            : base(spriteBatch)
        {
            if (settings == null) throw new ArgumentNullException("settings");
            if (bloomExtractEffect == null) throw new ArgumentNullException("bloomExtractEffect");
            if (bloomEffect == null) throw new ArgumentNullException("bloomEffect");
            if (blurEffect == null) throw new ArgumentNullException("blurEffect");

            this.settings = settings;

            //----------------------------------------------------------------
            // エフェクト

            this.bloomExtractEffect = new BloomExtractEffect(bloomExtractEffect);
            this.bloomEffect = new BloomEffect(bloomEffect);

            //----------------------------------------------------------------
            // レンダ ターゲット

            var pp = GraphicsDevice.PresentationParameters;
            var width = (int) (pp.BackBufferWidth * settings.MapScale);
            var height = (int) (pp.BackBufferHeight * settings.MapScale);

            bloomExtractMap = new RenderTarget2D(GraphicsDevice, width, height,
                false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PreserveContents);

            //----------------------------------------------------------------
            // ブラー

            blur = new GaussianBlur(blurEffect, spriteBatch, width, height,
                SurfaceFormat.Color, settings.Blur.Radius, settings.Blur.Amount);
        }
Пример #2
0
        public Dof(SpriteBatch spriteBatch, Settings settings, Effect depthMapEffect, Effect dofEffect, Effect blurEffect)
            : base(spriteBatch)
        {
            if (settings == null) throw new ArgumentNullException("settings");
            if (depthMapEffect == null) throw new ArgumentNullException("depthMapEffect");
            if (dofEffect == null) throw new ArgumentNullException("dofEffect");
            if (blurEffect == null) throw new ArgumentNullException("blurEffect");

            this.settings = settings;

            //----------------------------------------------------------------
            // エフェクト

            this.depthMapEffect = new DepthMapEffect(depthMapEffect);
            this.dofEffect = new DofEffect(dofEffect);

            //----------------------------------------------------------------
            // レンダ ターゲット

            var pp = GraphicsDevice.PresentationParameters;
            var width = (int) (pp.BackBufferWidth * settings.MapScale);
            var height = (int) (pp.BackBufferHeight * settings.MapScale);

            // 深度マップ
            depthMap = new RenderTarget2D(GraphicsDevice, width, height,
                false, SurfaceFormat.Single, DepthFormat.Depth24, 0, RenderTargetUsage.DiscardContents);

            // ブラー済みシーン マップ
            bluredSceneMap = new RenderTarget2D(GraphicsDevice, width, height,
                false, SurfaceFormat.Color, DepthFormat.Depth24, 0, RenderTargetUsage.PreserveContents);

            //----------------------------------------------------------------
            // ブラー

            blur = new GaussianBlur(blurEffect, spriteBatch, width, height, SurfaceFormat.Color,
                settings.Blur.Radius, settings.Blur.Amount);
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
        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);
        }