Esempio n. 1
0
        public Ssao(SpriteBatch spriteBatch, Settings settings,
            Effect normalDepthMapEffect, Effect ssaoMapEffect, Effect blurEffect, Effect ssaoEffect,
            Texture2D randomNormalMap)
            : base(spriteBatch)
        {
            if (settings == null) throw new ArgumentNullException("settings");
            if (normalDepthMapEffect == null) throw new ArgumentNullException("normalDepthMapEffect");
            if (ssaoMapEffect == null) throw new ArgumentNullException("ssaoMapEffect");
            if (blurEffect == null) throw new ArgumentNullException("blurEffect");
            if (ssaoEffect == null) throw new ArgumentNullException("ssaoEffect");
            if (randomNormalMap == null) throw new ArgumentNullException("randomNormalMap");

            this.settings = settings;
            this.spriteBatch = spriteBatch;

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

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

            // 法線深度マップ
            this.normalDepthMapEffect = new NormalDepthMapEffect(normalDepthMapEffect);

            // SSAO マップ
            this.ssaoMapEffect = new SsaoMapEffect(ssaoMapEffect);
            this.ssaoMapEffect.Initialize(width, height, randomNormalMap);

            // SSAO
            this.ssaoEffect = new SsaoEffect(ssaoEffect);

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

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

            // SSAO マップ
            ssaoMap = new RenderTarget2D(GraphicsDevice, width, height,
                false, SurfaceFormat.Single, DepthFormat.Depth24, 0, RenderTargetUsage.PreserveContents);

            //----------------------------------------------------------------
            // SSAO マップブラー

            blur = new SsaoMapBlur(blurEffect, spriteBatch, width, height, SurfaceFormat.Single,
                settings.Blur.Radius, settings.Blur.Amount);
        }
Esempio n. 2
0
        public Ssao(SpriteBatch spriteBatch, Settings settings,
                    Effect normalDepthMapEffect, Effect ssaoMapEffect, Effect blurEffect, Effect ssaoEffect,
                    Texture2D randomNormalMap)
            : base(spriteBatch)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            if (normalDepthMapEffect == null)
            {
                throw new ArgumentNullException("normalDepthMapEffect");
            }
            if (ssaoMapEffect == null)
            {
                throw new ArgumentNullException("ssaoMapEffect");
            }
            if (blurEffect == null)
            {
                throw new ArgumentNullException("blurEffect");
            }
            if (ssaoEffect == null)
            {
                throw new ArgumentNullException("ssaoEffect");
            }
            if (randomNormalMap == null)
            {
                throw new ArgumentNullException("randomNormalMap");
            }

            this.settings    = settings;
            this.spriteBatch = spriteBatch;

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

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

            // 法線深度マップ
            this.normalDepthMapEffect = new NormalDepthMapEffect(normalDepthMapEffect);

            // SSAO マップ
            this.ssaoMapEffect = new SsaoMapEffect(ssaoMapEffect);
            this.ssaoMapEffect.Initialize(width, height, randomNormalMap);

            // SSAO
            this.ssaoEffect = new SsaoEffect(ssaoEffect);

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

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

            // SSAO マップ
            ssaoMap = new RenderTarget2D(GraphicsDevice, width, height,
                                         false, SurfaceFormat.Single, DepthFormat.Depth24, 0, RenderTargetUsage.PreserveContents);

            //----------------------------------------------------------------
            // SSAO マップブラー

            blur = new SsaoMapBlur(blurEffect, spriteBatch, width, height, SurfaceFormat.Single,
                                   settings.Blur.Radius, settings.Blur.Amount);
        }
Esempio n. 3
0
        protected override void LoadContent()
        {
            #region Effects

            normalDepthMapEffect = EffectManager.Load<NormalDepthMapEffect>();
            ssaoMapEffect = EffectManager.Load<SsaoMapEffect>();
            ssaoMapBlurEffect = EffectManager.Load<SsaoMapBlurEffect>();
            ssaoEffect = EffectManager.Load<SsaoEffect>();

            var randomNormalMap = Content.Load<Texture2D>("Textures/RandomNormal");
            ssaoMapEffect.SetRandomNormalMap(randomNormalMap);

            #endregion

            #region Back buffers

            const int normalDepthMapSampleQuality = 0;

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

            normalDepthMapBackBuffer = BackBufferManager.Load("NormalDepthmap");
            normalDepthMapBackBuffer.Width = width;
            normalDepthMapBackBuffer.Height = height;
            normalDepthMapBackBuffer.MipMap = false;
            normalDepthMapBackBuffer.SurfaceFormat = normalDepthMapFormat;
            normalDepthMapBackBuffer.DepthFormat = DepthFormat.Depth24Stencil8;
            normalDepthMapBackBuffer.MultiSampleCount = normalDepthMapSampleQuality;
            normalDepthMapBackBuffer.Enabled = Enabled;

            ssaoMapBackBuffer = BackBufferManager.Load("SsaoMap");
            ssaoMapBackBuffer.Width = width;
            ssaoMapBackBuffer.Height = height;
            ssaoMapBackBuffer.MipMap = false;
            ssaoMapBackBuffer.SurfaceFormat = SurfaceFormat.Color;
            ssaoMapBackBuffer.DepthFormat = DepthFormat.Depth24Stencil8;
            ssaoMapBackBuffer.MultiSampleCount = 0;
            ssaoMapBackBuffer.Enabled = Enabled;

            ssaoMapBlurBackBuffer = BackBufferManager.Load("SsaoGaussianBlur");
            ssaoMapBlurBackBuffer.Width = width;
            ssaoMapBlurBackBuffer.Height = height;
            ssaoMapBlurBackBuffer.MipMap = false;
            ssaoMapBlurBackBuffer.SurfaceFormat = SurfaceFormat.Color;
            ssaoMapBlurBackBuffer.DepthFormat = DepthFormat.Depth24Stencil8;
            ssaoMapBlurBackBuffer.MultiSampleCount = 0;
            ssaoMapBlurBackBuffer.Enabled = Enabled;

            #endregion

            base.LoadContent();
        }