Exemplo n.º 1
0
        public override void Do(PostProcessingRenderObject ro)
        {
            if (ro.BloomBuffer.EqualRenderParameters(ro))
            {
                ro.ProcessedTexture  = ro.BloomBuffer.Texture;
                ro.CurrentBufferSize = (Vector2)ro.BloomBuffer.Size;
                ro.ProcessedUV1      = (Vector2)ro.ViewportSize / ro.CurrentBufferSize;
                return;
            }

            ro.PrepareOffscreenRendering(ro.Size);
            var bufferSize        = (Vector2)ro.BloomBuffer.Size;
            var bloomViewportSize = (Size)(bufferSize * ro.BloomTextureScaling);

            ro.BloomMaterial.BrightThreshold         = ro.BloomBrightThreshold;
            ro.BloomMaterial.InversedGammaCorrection = new Vector3(
                Mathf.Abs(ro.BloomGammaCorrection.X) > Mathf.ZeroTolerance ? 1f / ro.BloomGammaCorrection.X : 0f,
                Mathf.Abs(ro.BloomGammaCorrection.Y) > Mathf.ZeroTolerance ? 1f / ro.BloomGammaCorrection.Y : 0f,
                Mathf.Abs(ro.BloomGammaCorrection.Z) > Mathf.ZeroTolerance ? 1f / ro.BloomGammaCorrection.Z : 0f
                );
            ro.RenderToTexture(ro.FirstTemporaryBuffer.Texture, ro.ProcessedTexture, ro.BloomMaterial, Color4.White, ro.TextureClearingColor, bloomViewportSize);
            var bloomUV1 = (Vector2)bloomViewportSize / bufferSize;

            ro.BlurMaterial.Radius          = ro.BloomStrength;
            ro.BlurMaterial.BlurShaderId    = ro.BloomShaderId;
            ro.BlurMaterial.Step            = ro.ProcessedUV1 * ro.BloomTextureScaling / ro.CurrentBufferSize;
            ro.BlurMaterial.Dir             = Vector2.Down;
            ro.BlurMaterial.AlphaCorrection = 1f;
            ro.RenderToTexture(ro.SecondTemporaryBuffer.Texture, ro.FirstTemporaryBuffer.Texture, ro.BlurMaterial, Color4.White, ro.TextureClearingColor, bloomViewportSize, bloomUV1);
            ro.BlurMaterial.Dir = Vector2.Right;

            if (ro.DebugViewMode != PostProcessingPresenter.DebugViewMode.Bloom)
            {
                ro.RenderToTexture(ro.FirstTemporaryBuffer.Texture, ro.SecondTemporaryBuffer.Texture, ro.BlurMaterial, Color4.White, ro.TextureClearingColor, bloomViewportSize, bloomUV1);

                if (ro.ProcessedViewport.Width != ro.ViewportSize.Width || ro.ProcessedViewport.Height != ro.ViewportSize.Height)
                {
                    Renderer.Viewport = ro.ProcessedViewport = new Viewport(0, 0, ro.ViewportSize.Width, ro.ViewportSize.Height);
                }
                ro.BloomBuffer.Texture.SetAsRenderTarget();
                try {
                    var material = ro.AlphaDiffuseMaterial;
                    Renderer.Clear(Color4.Zero);
                    Renderer.DrawSprite(ro.ProcessedTexture, null, material, Color4.White, Vector2.Zero, ro.Size, Vector2.Zero, ro.ProcessedUV1, Vector2.Zero, Vector2.Zero);
                    Renderer.DrawSprite(ro.FirstTemporaryBuffer.Texture, null, ro.AddDiffuseMaterial, ro.BloomColor, Vector2.Zero, ro.Size, Vector2.Zero, bloomUV1, Vector2.Zero, Vector2.Zero);
                } finally {
                    ro.BloomBuffer.Texture.RestoreRenderTarget();
                }
                ro.BloomBuffer.SetRenderParameters(ro);
            }
            else
            {
                ro.RenderToTexture(ro.BloomBuffer.Texture, ro.SecondTemporaryBuffer.Texture, ro.BlurMaterial, ro.BloomColor, ro.TextureClearingColor, customUV1: bloomUV1);
                ro.BloomBuffer.MarkAsDirty();
            }
            ro.MarkBuffersAsDirty = true;
            ro.ProcessedTexture   = ro.BloomBuffer.Texture;
            ro.CurrentBufferSize  = (Vector2)ro.BloomBuffer.Size;
            ro.ProcessedUV1       = (Vector2)ro.ViewportSize / ro.CurrentBufferSize;
        }
Exemplo n.º 2
0
        public override void Do(PostProcessingRenderObject ro)
        {
            ro.ViewportSize = (Size)((Vector2)ro.ViewportSize * ro.BlurTextureScaling);
            if (ro.BlurBuffer.EqualRenderParameters(ro))
            {
                ro.ProcessedTexture  = ro.BlurBuffer.Texture;
                ro.CurrentBufferSize = (Vector2)ro.BlurBuffer.Size;
                ro.ProcessedUV1      = (Vector2)ro.ViewportSize / ro.CurrentBufferSize;
                return;
            }

            ro.PrepareOffscreenRendering(ro.Size);
            ro.BlurMaterial.Radius          = ro.BlurRadius;
            ro.BlurMaterial.BlurShaderId    = ro.BlurShader;
            ro.BlurMaterial.Step            = ro.ProcessedUV1 * ro.BlurTextureScaling / ro.CurrentBufferSize;
            ro.BlurMaterial.Dir             = Vector2.Down;
            ro.BlurMaterial.AlphaCorrection = ro.BlurAlphaCorrection;
            ro.RenderToTexture(ro.FirstTemporaryBuffer.Texture, ro.ProcessedTexture, ro.BlurMaterial, Color4.White, ro.TextureClearingColor);
            ro.CurrentBufferSize = (Vector2)ro.BlurBuffer.Size;
            ro.ProcessedUV1      = (Vector2)ro.ViewportSize / ro.CurrentBufferSize;
            ro.BlurMaterial.Dir  = Vector2.Right;
            ro.RenderToTexture(ro.BlurBuffer.Texture, ro.FirstTemporaryBuffer.Texture, ro.BlurMaterial, Color4.White, ro.TextureClearingColor);

            ro.BlurBuffer.SetRenderParameters(ro);
            ro.MarkBuffersAsDirty = true;
            ro.ProcessedTexture   = ro.BlurBuffer.Texture;
        }
        public override void Do(PostProcessingRenderObject ro)
        {
            if (ro.SharpenBuffer.EqualRenderParameters(ro))
            {
                ro.ProcessedTexture  = ro.SharpenBuffer.Texture;
                ro.CurrentBufferSize = (Vector2)ro.SharpenBuffer.Size;
                ro.ProcessedUV1      = (Vector2)ro.ViewportSize / ro.CurrentBufferSize;
                return;
            }

            ro.PrepareOffscreenRendering(ro.Size);
            ro.SharpenMaterial.Strength = ro.SharpenStrength;
            ro.SharpenMaterial.Limit    = ro.SharpenLimit;
            ro.SharpenMaterial.Step     = ro.SharpenStep * (ro.ProcessedUV1 / ro.CurrentBufferSize);
            ro.RenderToTexture(ro.SharpenBuffer.Texture, ro.ProcessedTexture, ro.SharpenMaterial, Color4.White, ro.TextureClearingColor);
            ro.CurrentBufferSize = (Vector2)ro.SharpenBuffer.Size;
            ro.ProcessedUV1      = (Vector2)ro.ViewportSize / ro.CurrentBufferSize;

            ro.SharpenBuffer.SetRenderParameters(ro);
            ro.MarkBuffersAsDirty = true;
            ro.ProcessedTexture   = ro.SharpenBuffer.Texture;
        }
Exemplo n.º 4
0
        public override void Do(PostProcessingRenderObject ro)
        {
            if (ro.ColorCorrectionBuffer.EqualRenderParameters(ro))
            {
                ro.ProcessedTexture  = ro.ColorCorrectionBuffer.Texture;
                ro.CurrentBufferSize = (Vector2)ro.ColorCorrectionBuffer.Size;
                ro.ProcessedUV1      = (Vector2)ro.ViewportSize / ro.CurrentBufferSize;
                return;
            }

            ro.PrepareOffscreenRendering(ro.Size);
            ro.ColorCorrectionMaterial.HSL        = WrappedHSL(ro.HSL);
            ro.ColorCorrectionMaterial.Brightness = ro.Brightness;
            ro.ColorCorrectionMaterial.Contrast   = ro.Contrast;
            ro.RenderToTexture(ro.ColorCorrectionBuffer.Texture, ro.ProcessedTexture, ro.ColorCorrectionMaterial, Color4.White, ro.TextureClearingColor);

            ro.ColorCorrectionBuffer.SetRenderParameters(ro);
            ro.MarkBuffersAsDirty = true;
            ro.ProcessedTexture   = ro.ColorCorrectionBuffer.Texture;
            ro.CurrentBufferSize  = (Vector2)ro.ColorCorrectionBuffer.Size;
            ro.ProcessedUV1       = (Vector2)ro.ViewportSize / ro.CurrentBufferSize;
        }
Exemplo n.º 5
0
        public override void Do(PostProcessingRenderObject ro)
        {
            if (ro.FXAABuffer.EqualRenderParameters(ro))
            {
                ro.ProcessedTexture  = ro.FXAABuffer.Texture;
                ro.CurrentBufferSize = (Vector2)ro.FXAABuffer.Size;
                ro.ProcessedUV1      = (Vector2)ro.ViewportSize / ro.CurrentBufferSize;
                return;
            }

            ro.PrepareOffscreenRendering(ro.Size);
            ro.FXAAMaterial.TexelStep    = ro.ProcessedUV1 / ro.CurrentBufferSize;
            ro.FXAAMaterial.LumaTreshold = ro.FXAALumaTreshold;
            ro.FXAAMaterial.MulReduce    = ro.FXAAMulReduce;
            ro.FXAAMaterial.MinReduce    = ro.FXAAMinReduce;
            ro.FXAAMaterial.MaxSpan      = ro.FXAAMaxSpan;
            ro.RenderToTexture(ro.FXAABuffer.Texture, ro.ProcessedTexture, ro.FXAAMaterial, Color4.White, ro.TextureClearingColor);
            ro.CurrentBufferSize = (Vector2)ro.FXAABuffer.Size;
            ro.ProcessedUV1      = (Vector2)ro.ViewportSize / ro.CurrentBufferSize;

            ro.FXAABuffer.SetRenderParameters(ro);
            ro.MarkBuffersAsDirty = true;
            ro.ProcessedTexture   = ro.FXAABuffer.Texture;
        }
        public override void Do(PostProcessingRenderObject ro)
        {
            if (ro.DistortionBuffer.EqualRenderParameters(ro))
            {
                ro.ProcessedTexture  = ro.DistortionBuffer.Texture;
                ro.CurrentBufferSize = (Vector2)ro.DistortionBuffer.Size;
                ro.ProcessedUV1      = (Vector2)ro.ViewportSize / ro.CurrentBufferSize;
                return;
            }

            ro.PrepareOffscreenRendering(ro.Size);
            ro.DistortionMaterial.BarrelPincushion    = ro.DistortionBarrelPincushion;
            ro.DistortionMaterial.ChromaticAberration = ro.DistortionChromaticAberration;
            ro.DistortionMaterial.Red   = ro.DistortionRed;
            ro.DistortionMaterial.Green = ro.DistortionGreen;
            ro.DistortionMaterial.Blue  = ro.DistortionBlue;
            ro.RenderToTexture(ro.DistortionBuffer.Texture, ro.ProcessedTexture, ro.DistortionMaterial, Color4.White, ro.TextureClearingColor);
            ro.CurrentBufferSize = (Vector2)ro.DistortionBuffer.Size;
            ro.ProcessedUV1      = (Vector2)ro.ViewportSize / ro.CurrentBufferSize;

            ro.DistortionBuffer.SetRenderParameters(ro);
            ro.MarkBuffersAsDirty = true;
            ro.ProcessedTexture   = ro.DistortionBuffer.Texture;
        }