public void End(bool doBloom = false)
        {
            downscaler.Downscale();

            var averageLuminance = AverageLuminance();

            postEffect.Parameters["GammaReciprocal"].SetValue(1 / Gamma);
            postEffect.Parameters["ColorTexture"].SetValue(targets.ColorAccum);
            postEffect.Parameters["AverageLuminanceTexture"].SetValue(averageLuminance);
            postEffect.Parameters["MiddleGrey"].SetValue(0.25f);
            postEffect.Parameters["LumWhiteSqr"].SetValue(3f);

            if (doBloom)
            {
                var bloomImage = this.bloom.Blur(targets.ColorAccum, BloomSettings, averageLuminance, 0.1f);

                postEffect.CurrentTechnique = postEffect.Techniques["FinalBloom"];

                postEffect.Parameters["BloomIntensity"].SetValue(BloomSettings.BloomIntensity);
                postEffect.Parameters["BaseIntensity"].SetValue(BloomSettings.BaseIntensity);
                postEffect.Parameters["BaseSaturation"].SetValue(BloomSettings.BaseSaturation);
                postEffect.Parameters["BloomSaturation"].SetValue(BloomSettings.BloomSaturation);
                postEffect.Parameters["BloomTexture"].SetValue(bloomImage);
            }
            else
            {
                postEffect.CurrentTechnique = postEffect.Techniques["Final"];
            }

            graphics.SetRenderTargets();
            graphics.Clear(Color.Black);

            fullScreen.Draw(postEffect);
        }
示例#2
0
        /// <summary>
        /// Helper for drawing a texture into a rendertarget, using
        /// a custom shader to apply postprocessing effects.
        /// </summary>
        void DrawFullscreenQuad(RenderTarget2D renderTarget, Texture2D texture,
                                Effect effect)
        {
            graphics.SetRenderTarget(renderTarget);

            effect.Parameters["ColorTexture"].SetValue(texture);

            fullScreen.Draw(effect);
        }
示例#3
0
        public void WeightedAverage(float a_weight, float b_weight)
        {
            graphics.BlendState = BlendState.Opaque;

            graphics.SetRenderTarget(Accumulator);

            effect.CurrentTechnique = effect.Techniques["Average"];

            p_a_weight.SetValue(new Vector4(a_weight, a_weight, a_weight, a_weight));
            p_b_weight.SetValue(new Vector4(b_weight, b_weight, b_weight, b_weight));
            p_a_texture.SetValue(A);
            p_b_texture.SetValue(B);
            effect.Parameters["HalfTexel"].SetValue(new Vector2(0.25f, 0.25f));

            fullScreen.Draw(effect);
        }
        public void Downscale()
        {
            Texture2D last = targets.ColorAccum;

            graphics.BlendState = BlendState.Opaque;

            for (int i = 0; i < renderTargets.Length; i++)
            {
                Vector2 texelOffset = 0.5f *
                                      new Vector2(1 / last.Width - 1 / renderTargets[i].Width,
                                                  1 / last.Height - 1 / renderTargets[i].Height);

                graphics.SetRenderTarget(renderTargets[i]);

                downscale.CurrentTechnique = downscale.Techniques["Downscale"];
                downscale.Parameters["ColorTexture"].SetValue(last);
                downscale.Parameters["TexelOffset"].SetValue(texelOffset);

                fullScreen.Draw(downscale);

                last = renderTargets[i];
            }
        }