Testing my new plugin :)

Well, i just installed this new plugin and i’m trying it right now.
It’s a simple formatting coloring plugin. The file is courtesy from Jamezila from his tutorial on post processing bloom/blur effects.

#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion

namespace XNAGame1
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        ContentManager content;

        Texture2D[] screenShot;
        Effect bloomatic;
        SpriteBatch sprite;

        RenderTarget2D rTarg;
        RenderTarget2D bloomTarg;

        int currentPic;
        double alphaFrame;
        GamePadState oldState;

        bool Additive;
        bool HiRange;


        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            content = new ContentManager(Services);
        }

        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
        }


        protected override void LoadGraphicsContent(bool loadAllContent)
        {
            if (loadAllContent)
            {
                // TODO: Load any ResourceManagementMode.Automatic content
            }

            sprite = new SpriteBatch(graphics.GraphicsDevice);

            rTarg = new RenderTarget2D(graphics.GraphicsDevice, 1024, 1024,
                0, SurfaceFormat.Color);
            bloomTarg = new RenderTarget2D(graphics.GraphicsDevice, 256, 256,
                0, SurfaceFormat.Color);

            screenShot = new Texture2D[8];
            for (int i = 0; i < screenShot.Length; i++)
            {
                screenShot[i] = content.Load(@"gfx/screen" +
                    (i + 1).ToString());
            }

            bloomatic = content.Load(@"fx/bloomatic");

            // TODO: Load any ResourceManagementMode.Manual content
        }


         protected override void UnloadGraphicsContent(bool unloadAllContent)
        {
            if (unloadAllContent == true)
            {
                content.Unload();
            }
        }

        protected override void Update(GameTime gameTime)
        {
            // Allows the default game to exit on Xbox 360 and Windows
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            if (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed
                && oldState.Buttons.A == ButtonState.Released)
                    currentPic = (currentPic + 1) % screenShot.Length;

            if (GamePad.GetState(PlayerIndex.One).Buttons.B == ButtonState.Pressed
                && oldState.Buttons.B == ButtonState.Released)
                    Additive = !Additive;
            if (GamePad.GetState(PlayerIndex.One).Buttons.Y == ButtonState.Pressed
                && oldState.Buttons.Y == ButtonState.Released)
                    HiRange = !HiRange;

            alphaFrame += (gameTime.ElapsedGameTime.TotalSeconds * 2.0);

            oldState = GamePad.GetState(PlayerIndex.One);
            // TODO: Add your update logic here

            base.Update(gameTime);
        }


        protected override void Draw(GameTime gameTime)
        {
            

            graphics.GraphicsDevice.SetRenderTarget(0, rTarg);
            graphics.GraphicsDevice.Clear(Color.Black);
            sprite.Begin();

            sprite.Draw(screenShot[currentPic], new Rectangle(0, 0, 800, 600),
                Color.White);

            sprite.End();
            graphics.GraphicsDevice.ResolveRenderTarget(0);

            graphics.GraphicsDevice.SetRenderTarget(0, bloomTarg);

            graphics.GraphicsDevice.Clear(Color.Black);

            bloomatic.Parameters["mag"].SetValue(0.008f);
            bloomatic.Parameters["alpha"].SetValue((float)(Math.Cos(alphaFrame) * 0.5 + 0.5));
            
            
            bloomatic.Parameters["hirange"].SetValue(HiRange);

            bloomatic.Begin();
            sprite.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate,
                SaveStateMode.SaveState);

            EffectPass pass = bloomatic.CurrentTechnique.Passes[0];
            pass.Begin();

            sprite.Draw(rTarg.GetTexture(), new Rectangle(0, 0, 256, 256),
                new Rectangle(0, 0, 800, 600), Color.White);

            pass.End();
            sprite.End();
            bloomatic.End();

            graphics.GraphicsDevice.ResolveRenderTarget(0);

            graphics.GraphicsDevice.SetRenderTarget(0, null);

            sprite.Begin();
            sprite.Draw(rTarg.GetTexture(), new Rectangle(0, 0, 800, 600),
                new Rectangle(0, 0, 800, 600), Color.White);
            sprite.End();

            if (Additive)
            {
                sprite.Begin(SpriteBlendMode.Additive);
            }
            else
            {
                sprite.Begin(SpriteBlendMode.AlphaBlend);
            }
            sprite.Draw(bloomTarg.GetTexture(), new Rectangle(0, 0, 800, 600),
                Color.White);
            sprite.End();

            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
    }
}

And here is the shader he used. (Just for trying language marquers on a shader, and it looks like csharp marquer is the most appropriate)

// bloomatic.fx
sampler samplerState;

//Width to sample from
float mag;

//Alpha value
float alpha;

//Operate on a high range (0.5 - 1.0) or the full range (0.0 - 1.0)
bool hirange;

const float2 offsets[12] = {
-0.326212, -0.405805,
-0.840144, -0.073580,
-0.695914,  0.457137,
-0.203345,  0.620716,
0.962340, -0.194983,
0.473434, -0.480026,
0.519456,  0.767022,
0.185461, -0.893124,
0.507431,  0.064425,
0.896420,  0.412458,
-0.321940, -0.932615,
-0.791559, -0.597705,
};

struct PS_INPUT
{
float2 TexCoord : TEXCOORD0;
};

float4 bloomEffect(PS_INPUT Input) : COLOR0 {
float4 sum = tex2D(samplerState, Input.TexCoord);
float4 tex;

//accumulate the color values from 12 neighboring pixels
for(int i = 0; i < 12; i++){
tex = tex2D(samplerState, Input.TexCoord + mag * offsets[i]);

sum += tex;
}
//average the sum
sum /= 13;

//fix alpha
sum.a = alpha;

//expand the higher range if applicable
if (hirange) {
sum.r = (sum.r - 0.5) * 2.0;
sum.g = (sum.g - 0.5) * 2.0;
sum.b = (sum.b - 0.5) * 2.0;
}

return sum;
}

technique Bloom {
pass P0{
PixelShader = compile ps_2_0 bloomEffect();
}

}

One Comment

  1. Nice blog, I was performing some internet browsing and stumbled upon your blog, I used to be wondering if you knew your website is rendering unusually within the K-mellon browser. I will see everything however the pictures are one way or another out of wallop. Most likely not a huge issue since basically nobody uses it anymore however I am old school and still use it.