Пример #1
0
        private void PostProcess(RenderContext context, RenderTarget2D source, RenderTarget2D target)
        {
            Debug.Assert(source != null);
            Debug.Assert(target != null);

            var originalSourceTexture = context.SourceTexture;
            var originalRenderTarget  = context.RenderTarget;
            var originalViewport      = context.Viewport;

            if (Filter != null && Filter.Enabled)
            {
                context.SourceTexture = source;
                context.RenderTarget  = source;
                context.Viewport      = new Viewport(0, 0, source.Width, source.Height);
                Filter.Process(context);
            }

            bool doUpsampling = UseHalfResolution && Numeric.IsGreater(UpsampleDepthSensitivity, 0);

            Debug.Assert(doUpsampling && source != target || !doUpsampling && source == target);

            if (doUpsampling)
            {
                if (_upsampleFilter == null)
                {
                    _upsampleFilter = _graphicsService.GetUpsampleFilter();
                }

                var graphicsDevice     = _graphicsService.GraphicsDevice;
                var originalBlendState = graphicsDevice.BlendState;
                graphicsDevice.BlendState = BlendState.Opaque;

                // The previous scene render target is bound as texture.
                // --> Switch scene render targets!
                context.SourceTexture            = source;
                context.RenderTarget             = target;
                context.Viewport                 = new Viewport(0, 0, target.Width, target.Height);
                _upsampleFilter.DepthSensitivity = UpsampleDepthSensitivity;
                _upsampleFilter.Mode             = UpsamplingMode.Bilateral;
                _upsampleFilter.RebuildZBuffer   = false;
                _upsampleFilter.Process(context);

                if (originalBlendState != null)
                {
                    graphicsDevice.BlendState = originalBlendState;
                }
            }

            context.SourceTexture = originalSourceTexture;
            context.RenderTarget  = originalRenderTarget;
            context.Viewport      = originalViewport;
        }