Ejemplo n.º 1
0
        /// <summary>
        /// Helper for drawing a texture into the current rendertarget,
        /// using a custom shader to apply postprocessing effects.
        /// </summary>
        void DrawFullscreenQuad(GraphicsDevice graphicsDevice,
                                Texture2D texture, int width, int height,
                                PixelShader pixelShader, IntermediateBuffer currentBuffer)
        {
            // If the user has selected one of the show intermediate buffer options,
            // we still draw the quad to make sure the image will end up on the screen,
            // but might need to skip applying the custom pixel shader.
            if (showBuffer < currentBuffer)
            {
                pixelShader = null;
            }

            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque);

            if (pixelShader != null)
            {
                graphicsDevice.SetPixelShader(pixelShader);
            }

            spriteBatch.Draw(texture, new Rectangle(0, 0, width, height), Color.White);

            spriteBatch.End();

            // TODO SL bug: this state reset should not be needed!
            graphicsDevice.Textures[0] = null;
            graphicsDevice.Textures[1] = null;
        }
Ejemplo n.º 2
0
        public void DrawFullScreenQuadRender(Texture2D texture, RenderTarget2D renderTarget,
                                             Effect effect, IntermediateBuffer currentBuffer)
        {
            GraphDev.SetRenderTarget(renderTarget);

            DrawFullScreenQuadRender(texture, renderTarget.Width, renderTarget.Height, effect, currentBuffer);
        }
Ejemplo n.º 3
0
        public void Process(RenderTarget2D scene, IntermediateBuffer show = IntermediateBuffer.Result)
        {
            device.SetRenderTarget(scene);

            device.SamplerStates[1] = SamplerState.LinearClamp;

            bloomExtract.Parameters["BloomThreshold"].SetValue(0.25F);

            RenderQuad(scene, primary, bloomExtract, IntermediateBuffer.PreBloom);

            SetBlurParameters(0, 1.0f / (float)primary.Width);

            RenderQuad(primary, secondary, blurGaussian, IntermediateBuffer.BlurHorizontal);

            SetBlurParameters(0, 1.0f / (float)primary.Height);

            RenderQuad(secondary, primary, blurGaussian, IntermediateBuffer.BlurAll);

            device.SetRenderTarget(null);

            var parameters = bloomCombine.Parameters;
            parameters["BloomIntensity"].SetValue(1.25F);
            parameters["BaseIntensity"].SetValue(1.0F);
            parameters["BloomSaturation"].SetValue(1.0F);
            parameters["BaseSaturation"].SetValue(1.0F);

            device.Textures[1] = scene;

            var view = device.Viewport;
            RenderQuad(primary, view.Width, view.Height, bloomCombine, IntermediateBuffer.Result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Helper for drawing a texture into the current rendertarget,
        /// using a custom shader to apply postprocessing effects.
        /// </summary>
        void DrawFullscreenQuad(Texture2D texture, int width, int height,
                                Effect effect, IntermediateBuffer currentBuffer)
        {
            spriteBatch.Begin(SpriteSortMode.Immediate,
                              BlendState.Opaque);

            // Begin the custom effect, if it is currently enabled. If the user
            // has selected one of the show intermediate buffer options, we still
            // draw the quad to make sure the image will end up on the screen,
            // but might need to skip applying the custom pixel shader.
            if (showBuffer >= currentBuffer)
            {
                //effect.Begin();
                effect.CurrentTechnique.Passes[0].Apply();
            }

            // Changing this to 1 fixed the reach complaint about clamping the texture. The wonders of XNA.
            GraphicsDevice.SamplerStates[1] = SamplerState.PointClamp;
            // Draw the quad.
            spriteBatch.Draw(texture, new Rectangle(0, 0, width, height), Color.White);
            spriteBatch.End();

            // End the custom effect.
            if (showBuffer >= currentBuffer)
            {
                //effect.CurrentTechnique.Passes[0].End();
                //effect.End();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Helper for drawing a texture into the current rendertarget,
        /// using a custom shader to apply postprocessing effects.
        /// </summary>
        void DrawFullscreenQuad(Texture2D texture, int width, int height,
                                Effect effect, IntermediateBuffer currentBuffer)
        {
            spriteBatch.Begin(SpriteBlendMode.None,
                              SpriteSortMode.Immediate,
                              SaveStateMode.None);

            game.Renderer.SetDefaultRenderStates();

            // Begin the custom effect, if it is currently enabled. If the user
            // has selected one of the show intermediate buffer options, we still
            // draw the quad to make sure the image will end up on the screen,
            // but might need to skip applying the custom pixel shader.
            if (showBuffer >= currentBuffer)
            {
                effect.Begin();
                effect.CurrentTechnique.Passes[0].Begin();
            }

            // Draw the quad.
            spriteBatch.Draw(texture, new Rectangle(0, 0, width, height), Color.White);
            spriteBatch.End();

            // End the custom effect.
            if (showBuffer >= currentBuffer)
            {
                effect.CurrentTechnique.Passes[0].End();
                effect.End();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Helper for drawing a texture into the current rendertarget,
        /// using a custom shader to apply postprocessing effects.
        /// </summary>
        private void DrawFullscreenQuad(Texture2D texture, int width, int height,
                                        Effect effect, IntermediateBuffer currentBuffer)
        {
            // If the user has selected one of the show intermediate buffer options,
            // we still draw the quad to make sure the image will end up on the screen,
            // but might need to skip applying the custom pixel shader.
            if (showBuffer < currentBuffer)
            {
                effect = null;
            }

            try
            {
                DwarfGame.SafeSpriteBatchBegin(0, BlendState.Opaque, null, null, null, effect, Matrix.Identity);
                DwarfGame.SpriteBatch.Draw(texture, new Rectangle(0, 0, width, height), Color.White);
            }
            catch (InvalidOperationException operationException)
            {
                Console.Error.WriteLine(operationException.ToString());
            }
            finally
            {
                DwarfGame.SpriteBatch.End();
            }
        }
        void SetBloomEffectParameters(float dx, float dy, float theta, IntermediateBuffer BlurDirection, int sampleCount)
        {
            // Create temporary arrays for computing our filter settings.
            float[]   sampleWeights = new float[sampleCount];
            Vector2[] sampleOffsets = new Vector2[sampleCount];

            // The first sample always has a zero offset.
            sampleWeights[0] = ComputeBloomGaussian(0, theta);
            sampleOffsets[0] = new Vector2(0);

            // Maintain a sum of all the weighting values.
            float totalWeights = sampleWeights[0];

            // Add pairs of additional sample taps, positioned
            // along a line in both directions from the center.
            for (int i = 0; i < sampleCount / 2; i++)
            {
                // Store weights for the positive and negative taps.
                float weight = ComputeBloomGaussian(i + 1, theta);

                sampleWeights[i * 2 + 1] = weight;
                sampleWeights[i * 2 + 2] = weight;

                totalWeights += weight * 2;

                // To get the maximum amount of blurring from a limited number of
                // pixel shader samples, we take advantage of the bilinear filtering
                // hardware inside the texture fetch unit. If we position our texture
                // coordinates exactly halfway between two texels, the filtering unit
                // will average them for us, giving two samples for the price of one.
                // This allows us to step in units of two texels per sample, rather
                // than just one at a time. The 1.5 offset kicks things off by
                // positioning us nicely in between two texels.
                float sampleOffset = i * 2 + 1.5f;

                Vector2 delta = new Vector2(dx, dy) * sampleOffset;

                // Store texture coordinate offsets for the positive and negative taps.
                sampleOffsets[i * 2 + 1] = delta;
                sampleOffsets[i * 2 + 2] = -delta;
            }

            // Normalize the list of sample weightings, so they will always sum to one.
            for (int i = 0; i < sampleWeights.Length; i++)
            {
                sampleWeights[i] /= totalWeights;
            }

            // Tell the effect about our new filter settings.
            if (BlurDirection == IntermediateBuffer.BlurredHorizontally)
            {
                sampleWeightsX = sampleWeights;
                sampleOffsetsX = sampleOffsets;
            }
            else
            {
                sampleWeightsY = sampleWeights;
                sampleOffsetsY = sampleOffsets;
            }
        }
Ejemplo n.º 8
0
 public BloomRenderComponent(Game game) : base(game)
 {
     this.GraphDev = game.GraphicsDevice;
     this.Content  = game.Content;
     this.SColor   = Color.Gray;
     this.Settings = BloomParams.BModes[BloomStates.SOFT];
     this.IBuffer  = IntermediateBuffer.Final;
 }
Ejemplo n.º 9
0
        protected void DrawFullscreenQuad(Texture2D texture, RenderTarget2D renderTarget,
                                Effect effect, IntermediateBuffer currentBuffer)
        {
            GraphicsDevice.SetRenderTarget(renderTarget);

            DrawFullscreenQuad(texture,renderTarget.Width, renderTarget.Height,
                               effect, currentBuffer);
        }
Ejemplo n.º 10
0
        protected void DrawFullscreenQuad(Texture2D texture, RenderTarget2D renderTarget,
                                          Effect effect, IntermediateBuffer currentBuffer)
        {
            GraphicsDevice.SetRenderTarget(renderTarget);

            DrawFullscreenQuad(texture, renderTarget.Width, renderTarget.Height,
                               effect, currentBuffer);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Helper for drawing a texture into a rendertarget, using
        /// a custom shader to apply postprocessing effects.
        /// </summary>
        public void DrawRenderTargetIntoOther(vxEngine vxEngine, Texture2D texture, RenderTarget2D renderTarget,
                                              Effect effect, IntermediateBuffer currentBuffer)
        {
            Engine.GraphicsDevice.SetRenderTarget(renderTarget);

            DrawFullscreenQuad(texture,
                               renderTarget.Width, renderTarget.Height,
                               effect);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Helper for drawing a texture into a rendertarget, using
        /// a custom shader to apply postprocessing effects.
        /// </summary>
        private void DrawFullscreenQuad(SpriteBatch spriteBatch, Texture2D texture, RenderTarget2D renderTarget,
                                        Effect effect, IntermediateBuffer currentBuffer)
        {
            spriteBatch.GraphicsDevice.SetRenderTarget(renderTarget);

            DrawFullscreenQuad(spriteBatch, texture,
                               renderTarget.Width, renderTarget.Height,
                               effect, currentBuffer);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Helper for drawing a texture into a rendertarget, using
        /// a custom shader to apply postprocessing effects.
        /// </summary>
        void DrawFullscreenQuad(GraphicsDevice graphicsDevice,
                                Texture2D texture, RenderTarget2D renderTarget,
                                PixelShader pixelShader, IntermediateBuffer currentBuffer)
        {
            graphicsDevice.SetRenderTarget(renderTarget);

            DrawFullscreenQuad(graphicsDevice, texture,
                               renderTarget.Width, renderTarget.Height,
                               pixelShader, currentBuffer);
        }
Ejemplo n.º 14
0
        protected void DrawFullscreenQuad(Texture2D texture, int width, int height,
                                Effect effect, IntermediateBuffer currentBuffer)
        {
            // If the user has selected one of the show intermediate buffer options,
            // we still draw the quad to make sure the image will end up on the screen,
            // but might need to skip applying the custom pixel shader.
            if (showBuffer < currentBuffer)
            {
                effect = null;
            }

            m_SpriteBatch.Begin(0, BlendState.Opaque, null, null, null, effect);
            m_SpriteBatch.Draw(texture, new Rectangle(0, 0, width, height), Color.White);
            m_SpriteBatch.End();
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Helper for drawing a texture into the current rendertarget,
        /// using a custom shader to apply postprocessing effects.
        /// </summary>
        private void DrawFullscreenQuadFinal(SpriteBatch spriteBatch, Texture2D texture, int width, int height,
                                             Effect effect, IntermediateBuffer currentBuffer)
        {
            // If the user has selected one of the show intermediate buffer options,
            // we still draw the quad to make sure the image will end up on the screen,
            // but might need to skip applying the custom pixel shader.
            if (showBuffer < currentBuffer)
            {
                effect = null;
            }

            spriteBatch.Begin(0, BlendState.AlphaBlend, null, null, null, effect);
            spriteBatch.Draw(texture, new Rectangle(0, 0, width, height), Color.White);
            spriteBatch.End();
        }
Ejemplo n.º 16
0
        void DrawFullScreenQuadRender(Texture2D texture, int width, int height, Effect effect,
                                      IntermediateBuffer currentBuffer)
        {
            // for intermidiate buffer options, still draw
            if (IBuffer < currentBuffer)
            {
                effect = null;
            }

            Batcher.Begin(SpriteSortMode.Deferred,
                          BlendState.Opaque,
                          null, null, null,
                          effect);

            Batcher.Draw(texture, new Rectangle(0, 0, width, height), Color.White);
            Batcher.End();
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Helper for drawing a texture into the current rendertarget,
        /// using a custom shader to apply postprocessing effects.
        /// </summary>
        void DrawFullscreenQuad(Texture2D texture, int width, int height,
                                Effect effect, IntermediateBuffer currentBuffer)
        {
            // If the user has selected one of the show intermediate buffer options,
            // we still draw the quad to make sure the image will end up on the screen,
            // but might need to skip applying the custom pixel shader.
            if (_showBuffer < currentBuffer)
            {
                effect = null;
            }

            // Must do this for each target if using transparent target
            _graphicsDevice.Clear(Color.TransparentBlack);
            _spriteBatch.Begin(0, BlendState.Opaque, null, null, null, effect);
            _spriteBatch.Draw(texture, new Rectangle(0, 0, width, height), Color.White);
            _spriteBatch.End();
        }
Ejemplo n.º 18
0
        private void DrawFullscreenQuad(
            IRenderTarget2D textureToDraw,
            int width,
            int height,
            EffectInstance effect,
            IntermediateBuffer currentBuffer,
            BlendMode blendState = BlendMode.AlphaBlendPremultiplied)
        {
            if (DisplayedBuffer < currentBuffer)
            {
                // The user has selected one of the show intermediate buffer options,
                // we still draw the quad to make sure the image will end up on the screen,
                // but might need to skip applying the custom pixel shader.
                effect = null;
            }

            // Clear with transparent black. Must do this for each target if using transparent target.
            this.device.Clear(Color.FromArgb(255, 0, 0, 0));
            this.device.DrawTexture(textureToDraw, width, height, effect, blendState);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Helper for drawing a texture into the current rendertarget,
        /// using a custom shader to apply postprocessing effects.
        /// </summary>
        void DrawFullscreenQuad(Texture2D texture, int width, int height,
                                Effect effect, IntermediateBuffer currentBuffer)
        {
            spriteBatch.Begin(0, BlendState.Opaque, null, null, null, effect);

            // Begin the custom effect, if it is currently enabled. If the user
            // has selected one of the show intermediate buffer options, we still
            // draw the quad to make sure the image will end up on the screen,
            // but might need to skip applying the custom pixel shader.
            if (showBuffer >= currentBuffer)
            {
                effect.CurrentTechnique.Passes[0].Apply();
            }

            // Draw the quad.
            spriteBatch.Draw(texture, new Rectangle(0, 0, width, height), Color.White);
            spriteBatch.End();

            // End the custom effect.
            if (showBuffer >= currentBuffer)
            {
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Helper for drawing a texture into the current rendertarget,
        /// using a custom shader to apply postprocessing effects.
        /// </summary>
        private void DrawFullscreenQuad(Texture2D texture, int width, int height,
            Effect effect, IntermediateBuffer currentBuffer)
        {
            // If the user has selected one of the show intermediate buffer options,
            // we still draw the quad to make sure the image will end up on the screen,
            // but might need to skip applying the custom pixel shader.
            if(showBuffer < currentBuffer)
            {
                effect = null;
            }

            try
            {
                spriteBatch.Begin(0, BlendState.Opaque, null, null, null, effect);
                spriteBatch.Draw(texture, new Rectangle(0, 0, width, height), Color.White);
                spriteBatch.End();
            }
            catch (InvalidOperationException operationException)
            {
                Console.Error.WriteLine(operationException.Message);
            }
        }
Ejemplo n.º 21
0
        private void DrawQuad(Texture2D texture, int Width, int Height, string Technique, IntermediateBuffer currentBuffer)
        {
            // if the user has selected one of the show intermediate buffer options,  we still draw the quad to make sure the image will end up on the screen,
            // but might need to skip applying the custom pixel shader.
            if (IntermediateBuffer.FinalResult < currentBuffer)
                CProgram.gQ2Game.gEffect = null;
            else
                CProgram.gQ2Game.gEffect.CurrentTechnique = CProgram.gQ2Game.gEffect.Techniques[Technique];

            spriteBatch.Begin(0, BlendState.Opaque, null, null, null, CProgram.gQ2Game.gEffect);
            spriteBatch.Draw(texture, new Rectangle(0, 0, Width, Height), Color.White);
            spriteBatch.End();
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Helper for drawing a texture into the current rendertarget,
        /// using a custom shader to apply postprocessing effects.
        /// </summary>
        void DrawFullscreenQuad(Texture2D texture, int width, int height,
                                Effect effect, IntermediateBuffer currentBuffer)
        {
            spriteBatch.Begin(SpriteBlendMode.None,
                              SpriteSortMode.Immediate,
                              SaveStateMode.SaveState);

            // Begin the custom effect, if it is currently enabled. If the user
            // has selected one of the show intermediate buffer options, we still
            // draw the quad to make sure the image will end up on the screen,
            // but might need to skip applying the custom pixel shader.
            if (showBuffer >= currentBuffer)
            {
                effect.Begin();
                effect.CurrentTechnique.Passes[0].Begin();
            }

            // Draw the quad.
            spriteBatch.Draw(texture, new Rectangle(0, 0, width, height), Color.White);
            spriteBatch.End();

            // End the custom effect.
            if (showBuffer >= currentBuffer)
            {
                effect.CurrentTechnique.Passes[0].End();
                effect.End();
            }
        }
Ejemplo n.º 23
0
 private void DrawQuad(Texture2D texture, RenderTarget2D RenderTarget, string Technique, IntermediateBuffer currentBuffer)
 {
     CProgram.gQ2Game.gGraphicsDevice.SetRenderTarget(RenderTarget);
     DrawQuad(texture, RenderTarget.Width, RenderTarget.Height, Technique, currentBuffer);
     CProgram.gQ2Game.gGraphicsDevice.SetRenderTarget(null);
 }
Ejemplo n.º 24
0
        private void DrawQuad(Texture2D texture, int Width, int Height, string Technique, IntermediateBuffer currentBuffer)
        {
            // if the user has selected one of the show intermediate buffer options,  we still draw the quad to make sure the image will end up on the screen,
            // but might need to skip applying the custom pixel shader.
            if (IntermediateBuffer.FinalResult < currentBuffer)
            {
                CProgram.gQ2Game.gEffect = null;
            }
            else
            {
                CProgram.gQ2Game.gEffect.CurrentTechnique = CProgram.gQ2Game.gEffect.Techniques[Technique];
            }

            spriteBatch.Begin(0, BlendState.Opaque, null, null, null, CProgram.gQ2Game.gEffect);
            spriteBatch.Draw(texture, new Rectangle(0, 0, Width, Height), Color.White);
            spriteBatch.End();
        }
Ejemplo n.º 25
0
 private void DrawFullscreenQuad(Texture2D texture, int width, int height, Effect effect, IntermediateBuffer currentBuffer)
 {
     if (showBuffer < currentBuffer)
     {
         effect = null;
     }
     spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, null, null, null, effect);
     spriteBatch.Draw(texture, new Rectangle(0, 0, width, height), Color.White);
     spriteBatch.End();
 }
Ejemplo n.º 26
0
        private void RenderQuad(Texture2D texture, int width, int height, Effect effect, IntermediateBuffer current)
        {
            if (ShowBuffer < current)
                effect = null;

            batch.Begin(0, BlendState.Opaque, null, null, null, effect);
            batch.Draw(texture, new Rectangle(0, 0, width, height), Color.White);
            batch.End();
        }
Ejemplo n.º 27
0
        private void RenderQuad(Texture2D texture, RenderTarget2D target, Effect effect, IntermediateBuffer current)
        {
            device.SetRenderTarget(target);

            RenderQuad(texture, target.Width, target.Height, effect, current);
        }
Ejemplo n.º 28
0
        private void DrawFullscreenQuad(Texture2D texture, int width, int height,
                                 Effect effect, IntermediateBuffer currentBuffer)
        {
            if (showBuffer < currentBuffer)
            {
                effect = null;
            }

            spriteBatch.Begin(0, BlendState.Opaque, null, null, null, effect);
            spriteBatch.Draw(texture, new Rectangle(0, 0, width, height), Color.White);
            spriteBatch.End();
        }
Ejemplo n.º 29
0
        private void DrawFullScreenQuad(Texture2D tex, RenderTarget2D target, Effect effect, IntermediateBuffer buffer)
        {
            GraphicsDevice.SetRenderTarget(target);

            DrawFullscreenQuad(tex, target.Width, target.Height, effect, buffer);
        }
Ejemplo n.º 30
0
 private void DrawQuad(Texture2D texture, RenderTarget2D RenderTarget, string Technique, IntermediateBuffer currentBuffer)
 {
     CProgram.gQ2Game.gGraphicsDevice.SetRenderTarget(RenderTarget);
     DrawQuad(texture, RenderTarget.Width, RenderTarget.Height, Technique, currentBuffer);
     CProgram.gQ2Game.gGraphicsDevice.SetRenderTarget(null);
 }