Exemple #1
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);
        }
Exemple #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);
        }
Exemple #3
0
        protected override void LoadContent()
        {
            #region Effects

            depthMapEffect = EffectManager.Load<DepthMapEffect>();
            depthOfFieldEffect = EffectManager.Load<DofEffect>();

            #endregion

            #region Back buffers

            const int depthMapSampleQuality = 0;

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

            depthMapBackBuffer = BackBufferManager.Load("DepthMap");
            depthMapBackBuffer.Width = width;
            depthMapBackBuffer.Height = height;
            depthMapBackBuffer.MipMap = false;
            depthMapBackBuffer.SurfaceFormat = depthMapFormat;
            depthMapBackBuffer.DepthFormat = DepthFormat.Depth24Stencil8;
            depthMapBackBuffer.MultiSampleCount = depthMapSampleQuality;
            depthMapBackBuffer.Enabled = Enabled;

            bluredSceneMapBackBuffer = BackBufferManager.Load("BluredSceneMap");
            bluredSceneMapBackBuffer.Width = width;
            bluredSceneMapBackBuffer.Height = height;
            bluredSceneMapBackBuffer.MipMap = false;
            bluredSceneMapBackBuffer.SurfaceFormat = SurfaceFormat.Color;
            bluredSceneMapBackBuffer.MultiSampleCount = 0;
            bluredSceneMapBackBuffer.Enabled = Enabled;

            #endregion

            #region Gaussian blur

            gaussianBlur = new GaussianBlur(RenderContext, width, height, bluredSceneMapBackBuffer.SurfaceFormat);
            gaussianBlur.LoadContent();
            gaussianBlur.Enabled = Enabled;

            #endregion

            base.LoadContent();
        }