Task IQueryPostProcessor <TCommand, VoidUnit> .ProcessAsync(
     TCommand command,
     IPostProcessorContext <VoidUnit> context,
     CancellationToken cancellationToken)
 {
     return(ProcessAsync(command, cancellationToken));
 }
示例#2
0
        void Filter(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentFilter);

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

            edgeEffect.EdgeWidth         = EdgeWidth;
            edgeEffect.EdgeIntensity     = EdgeIntensity;
            edgeEffect.NormalThreshold   = NormalThreshold;
            edgeEffect.DepthThreshold    = DepthThreshold;
            edgeEffect.NormalSensitivity = NormalSensitivity;
            edgeEffect.DepthSensitivity  = DepthSensitivity;
            edgeEffect.EdgeColor         = EdgeColor;
            edgeEffect.NormalDepthMap    = normalDepthMap;

            //----------------------------------------------------------------
            // 描画

            GraphicsDevice.SetRenderTarget(context.Destination);
            SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, null, null, null, edgeEffect.Effect);
            SpriteBatch.Draw(context.Source, context.Destination.Bounds, Color.White);
            SpriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);

            Instrument.End();
        }
示例#3
0
        void Filter(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentFilter);

            if (blur != null)
            {
                blur.Filter(shadowSceneMap);
            }

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

            shadowColorParameter.SetValue(shadowColor);
            shadowSceneMapParameter.SetValue(shadowSceneMap);

            //----------------------------------------------------------------
            // 描画

            GraphicsDevice.SetRenderTarget(context.Destination);

            SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, null, null, null, sssmEffect);
            SpriteBatch.Draw(context.Source, context.Destination.Bounds, Color.White);
            SpriteBatch.End();

            GraphicsDevice.SetRenderTarget(null);

            Instrument.End();
        }
示例#4
0
        void Filter(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentFilter);

            //================================================================
            // シーンにブラーを適用

            blur.Filter(context.Source, bluredSceneMap);

            //================================================================
            // シーンとブラー済みシーンを深度マップに基いて合成

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

            var distance = internalCamera.Projection.FarPlaneDistance - internalCamera.Projection.NearPlaneDistance;

            dofEffect.NearPlaneDistance = internalCamera.Projection.NearPlaneDistance;
            dofEffect.FarPlaneDistance  = internalCamera.Projection.FarPlaneDistance / distance;
            dofEffect.FocusDistance     = internalCamera.FocusDistance;
            dofEffect.FocusRange        = internalCamera.FocusRange;
            dofEffect.DepthMap          = depthMap;
            dofEffect.BluredSceneMap    = bluredSceneMap;

            //----------------------------------------------------------------
            // 描画

            GraphicsDevice.SetRenderTarget(context.Destination);
            SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, null, null, null, dofEffect.Effect);
            SpriteBatch.Draw(context.Source, context.Destination.Bounds, Color.White);
            SpriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);

            Instrument.End();
        }
示例#5
0
 Task IQueryPostProcessor <TCommand, VoidUnit> .ProcessAsync(
     TCommand command,
     IPostProcessorContext <VoidUnit> context,
     CancellationToken cancellationToken)
 {
     Process(command, cancellationToken);
     return(TaskBridge.CompletedTask);
 }
 Task IQueryPostProcessor <TQuery, TResult> .ProcessAsync(
     TQuery query,
     IPostProcessorContext <TResult> context,
     CancellationToken cancellationToken)
 {
     Process(query, context, cancellationToken);
     return(TaskBridge.CompletedTask);
 }
 public Task ProcessAsync(
     Calculate request,
     IPostProcessorContext <int> context,
     CancellationToken cancellationToken)
 {
     context.Result = Value;
     return(TaskBridge.CompletedTask);
 }
示例#8
0
        public override void Process(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentProcess);

            DrawNormalDepth(context);
            Filter(context);

            TextureDisplay.Add(normalDepthMap);

            Instrument.End();
        }
示例#9
0
        public override void Process(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentProcess);

            DrawShadowScene(context);
            Filter(context);

            TextureDisplay.Add(shadowSceneMap);

            Instrument.End();
        }
示例#10
0
        void DrawNormalDepth(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentDrawNormalDepth);

            var viewerCamera = context.ActiveCamera;

            //----------------------------------------------------------------
            // 内部カメラの準備

            internalCamera.View.Position                = viewerCamera.View.Position;
            internalCamera.View.Direction               = viewerCamera.View.Direction;
            internalCamera.View.Up                      = viewerCamera.View.Up;
            internalCamera.Projection.Fov               = viewerCamera.Projection.Fov;
            internalCamera.Projection.AspectRatio       = viewerCamera.Projection.AspectRatio;
            internalCamera.Projection.NearPlaneDistance = viewerCamera.Projection.NearPlaneDistance;
            internalCamera.Projection.FarPlaneDistance  = FarPlaneDistance;
            internalCamera.Update();

            internalCamera.Frustum.GetCorners(frustumCorners);
            frustumSphere = BoundingSphere.CreateFromPoints(frustumCorners);

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

            normalDepthMapEffect.View       = internalCamera.View.Matrix;
            normalDepthMapEffect.Projection = internalCamera.Projection.Matrix;

            //----------------------------------------------------------------
            // 描画

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

            GraphicsDevice.SetRenderTarget(normalDepthMap);
            GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.White, 1.0f, 0);

            // 不透明オブジェクトのみ対象。
            for (int i = 0; i < context.OpaqueObjects.Count; i++)
            {
                var opaque = context.OpaqueObjects[i];

                // 専用カメラの視錐台に含まれるもののみを描画。
                if (IsVisibleObject(opaque))
                {
                    opaque.Draw(normalDepthMapEffect);
                }
            }

            GraphicsDevice.SetRenderTarget(null);

            Instrument.End();
        }
示例#11
0
        public override void Process(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentProcess);

            GraphicsDevice.SetRenderTarget(context.Destination);
            SpriteBatch.Begin();
            SpriteBatch.Draw(context.Source, context.Destination.Bounds, Color.White);
            SpriteBatch.Draw(fillTexture, context.Destination.Bounds, Color);
            SpriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);

            Instrument.End();
        }
示例#12
0
        public override void Process(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentProcess);

            GraphicsDevice.SetRenderTarget(context.Destination);
            SpriteBatch.Begin();
            SpriteBatch.Draw(context.Source, context.Destination.Bounds, Color.White);
            SpriteBatch.Draw(fillTexture, context.Destination.Bounds, Color);
            SpriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);

            Instrument.End();
        }
示例#13
0
        public override void Process(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentProcess);

            monochromeEffect.Cb = cbCr.X;
            monochromeEffect.Cr = cbCr.Y;

            GraphicsDevice.SetRenderTarget(context.Destination);
            SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, null, null, null, monochromeEffect.Effect);
            SpriteBatch.Draw(context.Source, context.Destination.Bounds, Color.White);
            SpriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);

            Instrument.End();
        }
示例#14
0
        public override void Process(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentProcess);

            monochromeEffect.Cb = cbCr.X;
            monochromeEffect.Cr = cbCr.Y;

            GraphicsDevice.SetRenderTarget(context.Destination);
            SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, null, null, null, monochromeEffect.Effect);
            SpriteBatch.Draw(context.Source, context.Destination.Bounds, Color.White);
            SpriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);

            Instrument.End();
        }
示例#15
0
        public override void Process(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentProcess);

            var height = context.Destination.Height;

            density.SetValue(height * MathHelper.PiOver2);
            brightness.SetValue(Brightness);

            GraphicsDevice.SetRenderTarget(context.Destination);
            SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, null, null, null, effect);
            SpriteBatch.Draw(context.Source, context.Destination.Bounds, Color.White);
            SpriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);

            Instrument.End();
        }
示例#16
0
        public override void Process(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentProcess);

            var height = context.Destination.Height;

            density.SetValue(height * MathHelper.PiOver2);
            brightness.SetValue(Brightness);

            GraphicsDevice.SetRenderTarget(context.Destination);
            SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, null, null, null, effect);
            SpriteBatch.Draw(context.Source, context.Destination.Bounds, Color.White);
            SpriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);

            Instrument.End();
        }
示例#17
0
        void Filter(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentFilter);

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

            ssaoEffect.SsaoMap = ssaoMap;

            //----------------------------------------------------------------
            // 描画

            GraphicsDevice.SetRenderTarget(context.Destination);
            SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, null, null, null, ssaoEffect.Effect);
            SpriteBatch.Draw(context.Source, context.Destination.Bounds, Color.White);
            SpriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);

            Instrument.End();
        }
示例#18
0
        void DrawShadowScene(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentDrawShadowScene);

            var camera    = context.ActiveCamera;
            var shadowMap = context.ShadowMap;

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

            shadowSceneEffect.View                      = camera.View.Matrix;
            shadowSceneEffect.Projection                = camera.Projection.Matrix;
            shadowSceneEffect.SplitDistances            = shadowMap.SplitDistances;
            shadowSceneEffect.SplitLightViewProjections = shadowMap.SplitLightViewProjections;
            shadowSceneEffect.SplitShadowMaps           = shadowMap.SplitShadowMaps;

            //----------------------------------------------------------------
            // 描画

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

            GraphicsDevice.SetRenderTarget(shadowSceneMap);
            GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.White, 1.0f, 0);

            for (int i = 0; i < context.OpaqueObjects.Count; i++)
            {
                var opaque = context.OpaqueObjects[i];
                opaque.Draw(shadowSceneEffect);
            }

            for (int i = 0; i < context.TranslucentObjects.Count; i++)
            {
                var translucent = context.TranslucentObjects[i];
                translucent.Draw(shadowSceneEffect);
            }

            GraphicsDevice.SetRenderTarget(null);

            Instrument.End();
        }
示例#19
0
        public override void Process(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentProcess);

            //----------------------------------------------------------------
            // ブルーム エクストラクト マップ

            bloomExtractEffect.Threshold = Threshold;

            GraphicsDevice.SetRenderTarget(bloomExtractMap);
            SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, null, null, null, bloomExtractEffect.Effect);
            SpriteBatch.Draw(context.Source, bloomExtractMap.Bounds, Color.White);
            SpriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);

            //----------------------------------------------------------------
            // ブルーム エクストラクト マップへブラーを適用

            blur.Filter(bloomExtractMap);

            //----------------------------------------------------------------
            // ブルーム

            bloomEffect.BloomIntensity  = BloomIntensity;
            bloomEffect.BaseIntensity   = BaseIntensity;
            bloomEffect.BloomSaturation = BloomSaturation;
            bloomEffect.BaseSaturation  = BaseSaturation;
            bloomEffect.BloomExtractMap = bloomExtractMap;

            GraphicsDevice.SetRenderTarget(context.Destination);
            SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, null, null, null, bloomEffect.Effect);
            SpriteBatch.Draw(context.Source, context.Destination.Bounds, Color.White);
            SpriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);

            Instrument.End();
        }
示例#20
0
        void Filter(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentFilter);

            if (blur != null) blur.Filter(shadowSceneMap);

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

            shadowColorParameter.SetValue(shadowColor);
            shadowSceneMapParameter.SetValue(shadowSceneMap);

            //----------------------------------------------------------------
            // 描画

            GraphicsDevice.SetRenderTarget(context.Destination);

            SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, null, null, null, sssmEffect);
            SpriteBatch.Draw(context.Source, context.Destination.Bounds, Color.White);
            SpriteBatch.End();

            GraphicsDevice.SetRenderTarget(null);

            Instrument.End();
        }
示例#21
0
        void DrawShadowScene(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentDrawShadowScene);

            var camera = context.ActiveCamera;
            var shadowMap = context.ShadowMap;

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

            shadowSceneEffect.View = camera.View.Matrix;
            shadowSceneEffect.Projection = camera.Projection.Matrix;
            shadowSceneEffect.SplitDistances = shadowMap.SplitDistances;
            shadowSceneEffect.SplitLightViewProjections = shadowMap.SplitLightViewProjections;
            shadowSceneEffect.SplitShadowMaps = shadowMap.SplitShadowMaps;

            //----------------------------------------------------------------
            // 描画

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

            GraphicsDevice.SetRenderTarget(shadowSceneMap);
            GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.White, 1.0f, 0);

            for (int i = 0; i < context.OpaqueObjects.Count; i++)
            {
                var opaque = context.OpaqueObjects[i];
                opaque.Draw(shadowSceneEffect);
            }

            for (int i = 0; i < context.TranslucentObjects.Count; i++)
            {
                var translucent = context.TranslucentObjects[i];
                translucent.Draw(shadowSceneEffect);
            }

            GraphicsDevice.SetRenderTarget(null);

            Instrument.End();
        }
示例#22
0
        public override void Process(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentProcess);

            DrawShadowScene(context);
            Filter(context);

            TextureDisplay.Add(shadowSceneMap);

            Instrument.End();
        }
示例#23
0
        void Filter(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentFilter);

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

            edgeEffect.EdgeWidth = EdgeWidth;
            edgeEffect.EdgeIntensity = EdgeIntensity;
            edgeEffect.NormalThreshold = NormalThreshold;
            edgeEffect.DepthThreshold = DepthThreshold;
            edgeEffect.NormalSensitivity = NormalSensitivity;
            edgeEffect.DepthSensitivity = DepthSensitivity;
            edgeEffect.EdgeColor = EdgeColor;
            edgeEffect.NormalDepthMap = normalDepthMap;

            //----------------------------------------------------------------
            // 描画

            GraphicsDevice.SetRenderTarget(context.Destination);
            SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, null, null, null, edgeEffect.Effect);
            SpriteBatch.Draw(context.Source, context.Destination.Bounds, Color.White);
            SpriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);

            Instrument.End();
        }
示例#24
0
        void DrawNormalDepth(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentDrawNormalDepth);

            var viewerCamera = context.ActiveCamera;

            //----------------------------------------------------------------
            // 内部カメラの準備

            internalCamera.View.Position = viewerCamera.View.Position;
            internalCamera.View.Direction = viewerCamera.View.Direction;
            internalCamera.View.Up = viewerCamera.View.Up;
            internalCamera.Projection.Fov = viewerCamera.Projection.Fov;
            internalCamera.Projection.AspectRatio = viewerCamera.Projection.AspectRatio;
            internalCamera.Projection.NearPlaneDistance = viewerCamera.Projection.NearPlaneDistance;
            internalCamera.Projection.FarPlaneDistance = FarPlaneDistance;
            internalCamera.Update();

            internalCamera.Frustum.GetCorners(frustumCorners);
            frustumSphere = BoundingSphere.CreateFromPoints(frustumCorners);

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

            normalDepthMapEffect.View = internalCamera.View.Matrix;
            normalDepthMapEffect.Projection = internalCamera.Projection.Matrix;

            //----------------------------------------------------------------
            // 描画

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

            GraphicsDevice.SetRenderTarget(normalDepthMap);
            GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.White, 1.0f, 0);

            // 不透明オブジェクトのみ対象。
            for (int i = 0; i < context.OpaqueObjects.Count; i++)
            {
                var opaque = context.OpaqueObjects[i];

                // 専用カメラの視錐台に含まれるもののみを描画。
                if (IsVisibleObject(opaque))
                    opaque.Draw(normalDepthMapEffect);
            }

            GraphicsDevice.SetRenderTarget(null);

            Instrument.End();
        }
示例#25
0
        public override void Process(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentProcess);

            DrawNormalDepth(context);
            Filter(context);

            TextureDisplay.Add(normalDepthMap);

            Instrument.End();
        }
示例#26
0
 public abstract void Process(IPostProcessorContext context);
示例#27
0
        void DrawSsaoMap(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentDrawSsaoMap);

            var viewerCamera = context.ActiveCamera;

            //================================================================
            //
            // 法線深度マップを描画
            //

            //----------------------------------------------------------------
            // 内部カメラの準備

            internalCamera.View.Position = viewerCamera.View.Position;
            internalCamera.View.Direction = viewerCamera.View.Direction;
            internalCamera.View.Up = viewerCamera.View.Up;
            internalCamera.Projection.Fov = viewerCamera.Projection.Fov;
            internalCamera.Projection.AspectRatio = viewerCamera.Projection.AspectRatio;
            internalCamera.Projection.NearPlaneDistance = viewerCamera.Projection.NearPlaneDistance;
            // TODO
            // 状況に応じて FarPlaneDistance を変化させられるように。
            //internalCamera.Projection.FarPlaneDistance = viewerCamera.Projection.FarPlaneDistance;
            internalCamera.Projection.FarPlaneDistance = 32;
            internalCamera.Update();

            internalCamera.Frustum.GetCorners(frustumCorners);
            frustumSphere = BoundingSphere.CreateFromPoints(frustumCorners);

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

            normalDepthMapEffect.View = internalCamera.View.Matrix;
            normalDepthMapEffect.Projection = internalCamera.Projection.Matrix;

            //----------------------------------------------------------------
            // 描画

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

            GraphicsDevice.SetRenderTarget(normalDepthMap);
            GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.White, 1.0f, 0);

            // 不透明オブジェクトのみ対象。
            for (int i = 0; i < context.OpaqueObjects.Count; i++)
            {
                var opaque = context.OpaqueObjects[i];

                if (!(opaque is ShadowCaster)) continue;

                // 専用カメラの視錐台に含まれるもののみを描画。
                if (IsVisibleObject(opaque))
                    opaque.Draw(normalDepthMapEffect);
            }

            GraphicsDevice.SetRenderTarget(null);

            //================================================================
            //
            // SSAO マップを描画
            //

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

            var randomOffsetVector = viewerCamera.View.Position + viewerCamera.View.Direction;

            ssaoMapEffect.TotalStrength = TotalStrength;
            ssaoMapEffect.Strength = Strength;
            ssaoMapEffect.Falloff = Falloff;
            ssaoMapEffect.Radius = Radius;
            ssaoMapEffect.RandomOffset = randomOffsetVector.LengthSquared();

            //----------------------------------------------------------------
            // 描画

            GraphicsDevice.SetRenderTarget(ssaoMap);

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, SamplerState.PointClamp, null, null, ssaoMapEffect.Effect);
            spriteBatch.Draw(normalDepthMap, ssaoMap.Bounds, Color.White);
            spriteBatch.End();

            GraphicsDevice.SetRenderTarget(null);

            //================================================================
            //
            // SSAO マップへブラーを適用
            //

            // TODO
            for (int i = 0; i < 3; i++)
                blur.Filter(ssaoMap, normalDepthMap);

            Instrument.End();
        }
示例#28
0
        void Filter(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentFilter);

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

            ssaoEffect.SsaoMap = ssaoMap;

            //----------------------------------------------------------------
            // 描画

            GraphicsDevice.SetRenderTarget(context.Destination);
            SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, null, null, null, ssaoEffect.Effect);
            SpriteBatch.Draw(context.Source, context.Destination.Bounds, Color.White);
            SpriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);

            Instrument.End();
        }
 /// <summary>
 /// Executes an action after <typeparamref name="TQuery"/> was handled.
 /// </summary>
 /// <param name="query">The query to <see cref="IMediator"/>.</param>
 /// <param name="context">
 /// The context that contains the result of <paramref name="query"/>.
 /// </param>
 /// <param name="cancellationToken">
 /// A cancellation token that should be used to cancel the work.
 /// </param>
 protected abstract void Process(
     TQuery query,
     IPostProcessorContext <TResult> context,
     CancellationToken cancellationToken
     );
示例#30
0
        public override void Process(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentProcess);

            //----------------------------------------------------------------
            // ブルーム エクストラクト マップ

            bloomExtractEffect.Threshold = Threshold;

            GraphicsDevice.SetRenderTarget(bloomExtractMap);
            SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, null, null, null, bloomExtractEffect.Effect);
            SpriteBatch.Draw(context.Source, bloomExtractMap.Bounds, Color.White);
            SpriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);

            //----------------------------------------------------------------
            // ブルーム エクストラクト マップへブラーを適用

            blur.Filter(bloomExtractMap);

            //----------------------------------------------------------------
            // ブルーム

            bloomEffect.BloomIntensity = BloomIntensity;
            bloomEffect.BaseIntensity = BaseIntensity;
            bloomEffect.BloomSaturation = BloomSaturation;
            bloomEffect.BaseSaturation = BaseSaturation;
            bloomEffect.BloomExtractMap = bloomExtractMap;

            GraphicsDevice.SetRenderTarget(context.Destination);
            SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, null, null, null, bloomEffect.Effect);
            SpriteBatch.Draw(context.Source, context.Destination.Bounds, Color.White);
            SpriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);

            Instrument.End();
        }
示例#31
0
        void Filter(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentFilter);

            //================================================================
            // シーンにブラーを適用

            blur.Filter(context.Source, bluredSceneMap);

            //================================================================
            // シーンとブラー済みシーンを深度マップに基いて合成

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

            var distance = internalCamera.Projection.FarPlaneDistance - internalCamera.Projection.NearPlaneDistance;
            dofEffect.NearPlaneDistance = internalCamera.Projection.NearPlaneDistance;
            dofEffect.FarPlaneDistance = internalCamera.Projection.FarPlaneDistance / distance;
            dofEffect.FocusDistance = internalCamera.FocusDistance;
            dofEffect.FocusRange = internalCamera.FocusRange;
            dofEffect.DepthMap = depthMap;
            dofEffect.BluredSceneMap = bluredSceneMap;

            //----------------------------------------------------------------
            // 描画

            GraphicsDevice.SetRenderTarget(context.Destination);
            SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, null, null, null, dofEffect.Effect);
            SpriteBatch.Draw(context.Source, context.Destination.Bounds, Color.White);
            SpriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);

            Instrument.End();
        }
示例#32
0
        void DrawSsaoMap(IPostProcessorContext context)
        {
            Instrument.Begin(InstrumentDrawSsaoMap);

            var viewerCamera = context.ActiveCamera;

            //================================================================
            //
            // 法線深度マップを描画
            //

            //----------------------------------------------------------------
            // 内部カメラの準備

            internalCamera.View.Position                = viewerCamera.View.Position;
            internalCamera.View.Direction               = viewerCamera.View.Direction;
            internalCamera.View.Up                      = viewerCamera.View.Up;
            internalCamera.Projection.Fov               = viewerCamera.Projection.Fov;
            internalCamera.Projection.AspectRatio       = viewerCamera.Projection.AspectRatio;
            internalCamera.Projection.NearPlaneDistance = viewerCamera.Projection.NearPlaneDistance;
            // TODO
            // 状況に応じて FarPlaneDistance を変化させられるように。
            //internalCamera.Projection.FarPlaneDistance = viewerCamera.Projection.FarPlaneDistance;
            internalCamera.Projection.FarPlaneDistance = 32;
            internalCamera.Update();

            internalCamera.Frustum.GetCorners(frustumCorners);
            frustumSphere = BoundingSphere.CreateFromPoints(frustumCorners);

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

            normalDepthMapEffect.View       = internalCamera.View.Matrix;
            normalDepthMapEffect.Projection = internalCamera.Projection.Matrix;

            //----------------------------------------------------------------
            // 描画

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

            GraphicsDevice.SetRenderTarget(normalDepthMap);
            GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.White, 1.0f, 0);

            // 不透明オブジェクトのみ対象。
            for (int i = 0; i < context.OpaqueObjects.Count; i++)
            {
                var opaque = context.OpaqueObjects[i];

                if (!(opaque is ShadowCaster))
                {
                    continue;
                }

                // 専用カメラの視錐台に含まれるもののみを描画。
                if (IsVisibleObject(opaque))
                {
                    opaque.Draw(normalDepthMapEffect);
                }
            }

            GraphicsDevice.SetRenderTarget(null);

            //================================================================
            //
            // SSAO マップを描画
            //

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

            var randomOffsetVector = viewerCamera.View.Position + viewerCamera.View.Direction;

            ssaoMapEffect.TotalStrength = TotalStrength;
            ssaoMapEffect.Strength      = Strength;
            ssaoMapEffect.Falloff       = Falloff;
            ssaoMapEffect.Radius        = Radius;
            ssaoMapEffect.RandomOffset  = randomOffsetVector.LengthSquared();

            //----------------------------------------------------------------
            // 描画

            GraphicsDevice.SetRenderTarget(ssaoMap);

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, SamplerState.PointClamp, null, null, ssaoMapEffect.Effect);
            spriteBatch.Draw(normalDepthMap, ssaoMap.Bounds, Color.White);
            spriteBatch.End();

            GraphicsDevice.SetRenderTarget(null);

            //================================================================
            //
            // SSAO マップへブラーを適用
            //

            // TODO
            for (int i = 0; i < 3; i++)
            {
                blur.Filter(ssaoMap, normalDepthMap);
            }

            Instrument.End();
        }
示例#33
0
 public abstract void Process(IPostProcessorContext context);