public void Filter(Texture2D source, BackBuffer destination)
        {
            if (!Enabled)
            {
                throw new InvalidOperationException("Screen space shadow is disabled.");
            }

            #region Prepare effects

            screenSpaceShadowEffect.ShadowSceneMapParameter.SetValue(shadowSceneMap);
            screenSpaceShadowEffect.ShadowColorParameter.SetValue(Scene.SceneSettings.DirectionalLight0.ShadowColor);

            #endregion

            #region Draw

            GraphicsDevice.DepthStencilState = DepthStencilState.None;
            GraphicsDevice.BlendState = BlendState.Opaque;

            destination.Begin();
            {
                SpriteBatch.Render(screenSpaceShadowEffect, source, destination.Bounds);
            }
            destination.End();

            #endregion
        }
Example #2
0
        public void Filter(Texture2D source, BackBuffer destination)
        {
            if (!Enabled)
            {
                throw new InvalidOperationException("VolumeFog disabled");
            }

            int w = destination.Width;
            int h = destination.Height;

            volumeFogBlendEffect.ViewportSize = new Vector2(w, h);
            volumeFogBlendEffect.SceneMap = source;
            volumeFogBlendEffect.FogMap = fogMapBackBuffer.GetRenderTarget();

            destination.Begin();
            {

                GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead;
                GraphicsDevice.BlendState = BlendState.NonPremultiplied;

                foreach (var pass in volumeFogBlendEffect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    quadVertexBuffer.Draw();
                }

                GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            }
            destination.End();
        }
Example #3
0
        public void Filter(Texture2D source, BackBuffer destination)
        {
            if (!Enabled)
            {
                throw new InvalidOperationException("ColorOverlap disabled.");
            }

            var color = new Color(Settings.Color) * Settings.Alpha;

            destination.Begin();
            {
                SpriteBatch.Begin();
                SpriteBatch.Draw(source, destination.Bounds, Color.White);
                SpriteBatch.Draw(whiteTexture, destination.Bounds, color);
                SpriteBatch.End();
            }
            destination.End();
        }
Example #4
0
        public void Filter(Texture2D source, BackBuffer destination)
        {
            if (!Enabled)
            {
                throw new InvalidOperationException("Monochrome is disabled");
            }

            monochromeEffect.CbParameter.SetValue(Settings.CbCr.X);
            monochromeEffect.CrParameter.SetValue(Settings.CbCr.Y);

            GraphicsDevice.DepthStencilState = DepthStencilState.None;
            GraphicsDevice.BlendState = BlendState.Opaque;

            destination.Begin();
            {
                SpriteBatch.Render(monochromeEffect, source, destination.Bounds);
            }
            destination.End();
        }
Example #5
0
        public void Filter(Texture2D source, BackBuffer destination)
        {
            AssertEnabled();

            #region Prepare effects

            ssaoEffect.SetSsaoMap(ssaoMapBackBuffer.GetRenderTarget());

            #endregion

            #region Draw

            GraphicsDevice.DepthStencilState = DepthStencilState.None;
            GraphicsDevice.BlendState = BlendState.Opaque;

            destination.Begin();
            {
                SpriteBatch.Render(ssaoEffect, source, destination.Bounds);
            }
            destination.End();

            #endregion
        }
Example #6
0
        public void Filter(Texture2D source, BackBuffer destination)
        {
            if (!Enabled)
            {
                throw new InvalidOperationException("Depth of field disabled");
            }

            #region Prepare effects

            var pp = GraphicsDevice.PresentationParameters;
            var width = (int) (pp.BackBufferWidth * Settings.MapScale);
            var height = (int) (pp.BackBufferHeight * Settings.MapScale);
            edgeDetectionEffect.SetEdgeWidth(Settings.EdgeWidth);
            edgeDetectionEffect.SetMapSize(width, height);
            edgeDetectionEffect.SetNormalDepthMap(normalDepthMapBackBuffer.GetRenderTarget());
            edgeDetectionEffect.SetEdgeIntensity(Settings.EdgeIntensity);
            edgeDetectionEffect.SetNormalThreshold(Settings.NormalThreshold);
            edgeDetectionEffect.SetDepthThreshold(Settings.DepthThreshold);
            edgeDetectionEffect.SetNormalSensitivity(Settings.NormalSensitivity);
            edgeDetectionEffect.SetDepthSensitivity(Settings.DepthSensitivity);
            edgeDetectionEffect.SetEdgeColor(ref Settings.EdgeColor);

            #endregion

            #region Draw

            GraphicsDevice.DepthStencilState = DepthStencilState.None;
            GraphicsDevice.BlendState = BlendState.Opaque;

            destination.Begin();
            {
                SpriteBatch.Render(edgeDetectionEffect, source, destination.Bounds);
            }
            destination.End();

            #endregion
        }
Example #7
0
        public void Filter(Texture2D source, BackBuffer destination)
        {
            if (!Enabled)
            {
                throw new InvalidOperationException("Depth of field disabled");
            }

            #region Adjust back buffer size if the destination is resized

            var pp = GraphicsDevice.PresentationParameters;
            bluredSceneMapBackBuffer.Width = (int) (pp.BackBufferWidth * Settings.MapScale);
            bluredSceneMapBackBuffer.Height = (int) (pp.BackBufferHeight * Settings.MapScale);

            #endregion

            #region Blur

            gaussianBlur.Radius = Settings.BlurRadius;
            gaussianBlur.Amount = Settings.BlurAmount;
            gaussianBlur.Filter(source, bluredSceneMapBackBuffer);

            #endregion

            #region Notify the intermadiate map

            if (DebugMap.Instance != null)
            {
                DebugMap.Instance.Maps.Add(bluredSceneMapBackBuffer.GetRenderTarget());
            }

            #endregion

            #region Apply DoF to the destination

            var pov = Scene.ActiveCamera.Pov;

            depthOfFieldEffect.NearPlaneDistance = pov.NearPlaneDistance;
            depthOfFieldEffect.FarPlaneDistance = pov.FarPlaneDistance / (pov.FarPlaneDistance - pov.NearPlaneDistance);

            if (Settings.FocusOverrideEnabled)
            {
                depthOfFieldEffect.FocusRange = Settings.FocusRange;
                depthOfFieldEffect.FocusDistance = Settings.FocusDistance;
            }
            else
            {
                depthOfFieldEffect.FocusRange = pov.FocusRange;
                depthOfFieldEffect.FocusDistance = pov.FocusDistance;
            }

            depthOfFieldEffect.DepthMap = depthMapBackBuffer.GetRenderTarget();
            depthOfFieldEffect.BluredSceneMap = bluredSceneMapBackBuffer.GetRenderTarget();

            GraphicsDevice.DepthStencilState = DepthStencilState.None;
            GraphicsDevice.BlendState = BlendState.Opaque;

            destination.Begin();
            {
                SpriteBatch.Render(depthOfFieldEffect, source, destination.Bounds);
            }
            destination.End();

            #endregion
        }
Example #8
0
        public void Filter(Texture2D source, BackBuffer destination)
        {
            if (!Enabled) throw new InvalidOperationException("Bloom disabled.");

            #region Create bloom extract map

            #region Prepare effects

            bloomExtractEffect.SetThreshold(Settings.Threshold);

            #endregion

            #region Prepare back buffers

            var pp = GraphicsDevice.PresentationParameters;
            bloomExtractMapBackBuffer.Width = (int) (pp.BackBufferWidth * Settings.MapScale);
            bloomExtractMapBackBuffer.Height = (int) (pp.BackBufferHeight * Settings.MapScale);

            #endregion

            #region Draw

            GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            GraphicsDevice.BlendState = BlendState.Opaque;

            bloomExtractMapBackBuffer.Begin();
            {
                SpriteBatch.Render(bloomExtractEffect, source, bloomExtractMapBackBuffer.Bounds);
            }
            bloomExtractMapBackBuffer.End();

            #endregion

            #endregion

            #region Blur

            gaussianBlur.Radius = Settings.BlurRadius;
            gaussianBlur.Amount = Settings.BlurAmount;
            gaussianBlur.Filter(
                bloomExtractMapBackBuffer.GetRenderTarget(),
                bloomExtractMapBackBuffer);

            #endregion

            #region Notify intermediate maps

            if (DebugMap.Instance != null)
            {
                DebugMap.Instance.Maps.Add(bloomExtractMapBackBuffer.GetRenderTarget());
            }

            #endregion

            #region Apply bloom to the destination

            bloomEffect.BloomExtractMapParameter.SetValue(bloomExtractMapBackBuffer.GetRenderTarget());
            bloomEffect.SetBloomIntensity(Settings.BloomIntensity);
            bloomEffect.SetBaseIntensity(Settings.BaseIntensity);
            bloomEffect.SetBloomSaturation(Settings.BloomSaturation);
            bloomEffect.SetBaseSaturation(Settings.BaseSaturation);

            GraphicsDevice.DepthStencilState = DepthStencilState.None;
            GraphicsDevice.BlendState = BlendState.Opaque;

            destination.Begin();
            {
                SpriteBatch.Render(bloomEffect, source, destination.Bounds);
            }
            destination.End();

            #endregion
        }
        public override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            #region Effect の初期化

            effectManager = new EffectManager(GraphicsDevice, Content);
            normalMapEffect = effectManager.Load<FluidSurfaceNormalMapEffect>();
            normalMapEffect.SampleOffset = new Vector2(1.0f / (float) TextureSize, 1.0f / (float) TextureSize);

            #endregion

            #region 内部で使用する RenderTarget の初期化

            backBufferManager = new BackBufferManager(GraphicsDevice);

            prevWaveMapBackBuffer = backBufferManager.Load("FluidSurfacePrevWaveMap");
            prevWaveMapBackBuffer.Width = TextureSize;
            prevWaveMapBackBuffer.Height = TextureSize;
            prevWaveMapBackBuffer.MipMap = true;
            prevWaveMapBackBuffer.SurfaceFormat = SurfaceFormat.Vector2;
            prevWaveMapBackBuffer.DepthFormat = DepthFormat.None;
            prevWaveMapBackBuffer.MultiSampleCount = 0;
            prevWaveMapBackBuffer.Enabled = true;

            waveMapBackBuffer = backBufferManager.Load("FluidSurfaceWaveMap");
            waveMapBackBuffer.Width = TextureSize;
            waveMapBackBuffer.Height = TextureSize;
            waveMapBackBuffer.MipMap = true;
            waveMapBackBuffer.SurfaceFormat = SurfaceFormat.Vector2;
            waveMapBackBuffer.DepthFormat = DepthFormat.None;
            waveMapBackBuffer.MultiSampleCount = 0;
            waveMapBackBuffer.Enabled = true;

            normalMapBackBuffer = backBufferManager.Load("FluidSurfaceNormalMap");
            normalMapBackBuffer.Width = TextureSize;
            normalMapBackBuffer.Height = TextureSize;
            normalMapBackBuffer.MipMap = true;
            normalMapBackBuffer.SurfaceFormat = SurfaceFormat.Vector2;
            normalMapBackBuffer.DepthFormat = DepthFormat.None;
            normalMapBackBuffer.MultiSampleCount = 0;
            normalMapBackBuffer.Enabled = true;

            prevWaveMapBackBuffer.Begin();
            {
                GraphicsDevice.Clear(Color.Black);
            }
            prevWaveMapBackBuffer.End();

            #endregion

            base.LoadContent();
        }
Example #10
0
        void FilterByVirticalBlur(Texture2D source, BackBuffer destination)
        {
            renderContext.GraphicsDevice.DepthStencilState = DepthStencilState.None;

            effect.CurrentTechnique = effect.VerticalBlurTechnique;
            destination.Begin();
            {
                renderContext.SpriteBatch.Render(
                    effect,
                    backBuffer.GetRenderTarget(),
                    new Rectangle(0, 0, destination.Width, destination.Height));
            }
            destination.End();
        }