Beispiel #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);
        }
Beispiel #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);
        }
        protected virtual void ParameterSetup()
        {
            //
            SsaoEffect = new SsaoEffect
            {
                TextureSize = 1024,
                OccConstantArea = false,
                OccMaxDist = 40,
                OccMinSampleRatio = 0.5f,
                OccPixmax = 44,
                OccPixmin = 2,
                SamplesCount = 32,
                Strength = 1,
                Bias = 0.2f,
                BlurEdgeAvoidance = 0.2f
            };

            //
            m_SunLight = new Light
            {
                Direction = new Vector3(1, 1, 1),
                Type = LightType.Directional
            };

            SunLightImpl = new ShadowImplementationParameters(m_SunLight);
            SunLightImpl.ImplementationType = ShadowImplementationType.Soft2;

            //
            ShadowTextureSize = 1024;
            SolidModeTextureSize = 1024;

            LightSize = 0.1f;
            //ExpMapLevel = 1;
            ShadowSampleCount = 15;
            //ExpMapRange = 0.0055f;
            //ExpMapRangeK = 0.85f;
        }
Beispiel #4
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();
        }