Bloom effect

Hello guys,

I 've found a tutorial to use some bloom effect in my game. The tuto can be found here.
But I encounter an strange error. Actually, Visual Studio tell me that
Build : 1 succeeded, 0 failed, 0 skipped but no window appear …

If you put the line 34 in comment, the code still build successfull and a window appear but without the bloom effect ( it’s normal because we put the line 34 in comment).
So why when the line 34 is not in comment, the project build well but no window appear ?

Thanks in advance to the time you’ll give me

This is the code :

using System;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

using BloomPostprocess;

namespace TestNeon
{
///


/// This is the main type for your game.
///

public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

    Texture2D space_Sprite;
    Texture2D player_Sprite;
    BloomComponent bloom;
    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
        graphics.PreferredBackBufferWidth = 1280;
        graphics.PreferredBackBufferHeight = 720;
        bloom = new BloomComponent(this);
        Components.Add(bloom);
        bloom.Settings = new BloomSettings(null, 0.25f, 4, 2, 10, 1.5f, 1);
    }
    /// <summary>
    /// Allows the game to perform any initialization it needs to before starting to run.
    /// This is where it can query for any required services and load any non-graphic
    /// related content.  Calling base.Initialize will enumerate through any components
    /// and initialize them as well.
    /// </summary>
    protected override void Initialize()
    {
        // TODO: Add your initialization logic here
        base.Initialize();
    }
    /// <summary>
    /// LoadContent will be called once per game and is the place to load
    /// all of your content.
    /// </summary>
    protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.
        spriteBatch = new SpriteBatch(GraphicsDevice);
        player_Sprite = Content.Load<Texture2D>("geometryShip");
        space_Sprite = Content.Load<Texture2D>("spaceSprite");
        // TODO: use this.Content to load your game content here
    }
    /// <summary>
    /// UnloadContent will be called once per game and is the place to unload
    /// game-specific content.
    /// </summary>
    protected override void UnloadContent()
    {
        // TODO: Unload any non ContentManager content here
    }
    /// <summary>
    /// Allows the game to run logic such as updating the world,
    /// checking for collisions, gathering input, and playing audio.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Update(GameTime gameTime)
    {
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            Exit();
        // TODO: Add your update logic here
        base.Update(gameTime);
    }
    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw(GameTime gameTime)
    {
        
        GraphicsDevice.Clear(Color.CornflowerBlue);
        spriteBatch.Begin();
        
        spriteBatch.Draw(space_Sprite, new Vector2(0, 0), Color.White);
        spriteBatch.End();
        bloom.BeginDraw();
        spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Additive);
        // TODO: Add your drawing code here
        
        Rectangle sourceRectangle = new Rectangle(0, 0, player_Sprite.Width, player_Sprite.Height);
        Vector2 origin2 = new Vector2(player_Sprite.Width / 2, player_Sprite.Height / 2);
        spriteBatch.Draw(player_Sprite, new Vector2(50,50), sourceRectangle, Color.White, 0, origin2, 0.5f, SpriteEffects.None, 1);
        spriteBatch.End();
        base.Draw(gameTime);
    }
}

}

Heello guy,

I try
> GameComponentCollection components = new GameComponentCollection();

        bloom = new BloomComponent(this);
        components.Add(bloom);
        bloom.Settings = new BloomSettings(null, 0.25f, 4, 2, 1, 2, 0);

But no bloom effect so I guess that GameComponentCollection object is not what expected.

Anyone has an idea ?

take a look
sample
edit link

Thanks PumpkinPudding but I have a 404 not found error :confused:

Thanks a lot PumpkinPudding. Now I understand where I was making an mistake. Therefore, I’ve still a problem.

It’s strange because I have downloaded the last version on http://xbox.create.msdn.com/en-US/education/catalog/sample/bloom

I’ve now to search why I have this Issue but thanks a lot :slight_smile:

“must be SM 4.0 level 9.1 or higher!”

that sample use 2.0

PixelShader = compile ps_2_0 PixelShaderFunction();

replace with 4_0_level_9_1, 4_0_level_9_3 or 4_0…

I assumed the problem came from there too.
Now a window appear but nothing in it … :frowning: There is an improvement because before I did not even have a window :slight_smile: . But now no Sprite appears in the window.

Edit : I solve the Warning but nothing change : “When I load Bloomcombine.fx, I have a warning message X3206 (20,18)‘dot’: implicit truncation of vector type. Do you think the problem come from that ?”

No this is not the problem.

BTW here is some shameless advertising for a newer, modern bloom, in case you just want the effect and don’t care about learning to code shaders https://github.com/Kosmonaut3d/BloomFilter-for-Monogame-and-XNA

1 Like

Interesting way to learn kosmonautgames but I would like to understand where is the issue in my case … :confused:

@Valentin_Honore Make sure the input for your pixel shader matches the output of the Sprite effects vertex shader:

struct VertexShaderOutput
{
	float4 Position : SV_POSITION;
	float4 Color : COLOR0;
	float2 TextureCoordinates : TEXCOORD0;
};

@Jjagg, Could you please be more precise ?
Where do I find this lines ? or where do I have to put them ? :confused:

in 3 .fx files

replace

float4 PixelShaderFunction(float2 texCoord : TEXCOORD0) : COLOR0

with

struct VertexShaderOutput
{
    float4 Position : SV_POSITION;
    float4 Color : COLOR0;
    float2 TextureCoordinates : TEXCOORD0;
};

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
1 Like

Nothing has changed :confused:

Could you share the full shader?

Here is all the project :

Some one can help me ?

ack…

do this

your scene is too dark and blur too heavy…
try

  bloom.Settings = new BloomSettings("Default", 0.1f, 1.5f, 3.25f, 1, 1, 1);

Hello,

The window appear but then close immediatly … :confused: