1

I'm trying to implement a bloom effect on some lasers in a game, but I'm stumbling into some problems. First I applied the bloom to everything, like so:

    protected override void Draw(GameTime gameTime)
    {


        batch.Begin(SpriteSortMode.Texture, BlendState.Additive);
        bloom.BeginDraw();

        stateManager.Draw(gameTime, batch);

        batch.End();

        base.Draw(gameTime);
    }

That worked fine, but ofcourse, it looked horrible, so to seperate it all into two draw calls, one with bloom, and one without, I tried this:

    protected override void Draw(GameTime gameTime)
    {
        bloom.BeginDraw();
        GraphicsDevice.Clear(Color.Black);

        batch.Begin(SpriteSortMode.Texture, BlendState.Additive);

        stateManager.DrawBloomed(gameTime, batch);

        batch.End();

        base.Draw(gameTime);

        batch.Begin(SpriteSortMode.Deferred, BlendState.Additive);

        stateManager.Draw(gameTime, batch);

        batch.End();

        base.Draw(gameTime);

    }

However, now everything's totally black. Could anyone point me in the right direction as to why this is happening and how I 'really' should approach this issue?

Istarnion
  • 109
  • 1
  • 10

1 Answers1

0

Does your state manager call GraphicsDevice.Clear()? If so, it's clearing the screen each time and so doing away with all your previous rendering.

You should only call base.Draw() once per call, so remove the one in the middle. If base.Draw() is clearing the screen, that will be causing the problem too, so either remove the call or put it at the start of the method.

Should your second batch be additive? I'd have expected it to be alpha blend or opaque.

If none of the above resolve your issue, post the code to stateManager.Draw(), the code to stateManager.DrawBloomed(), the code for your base class (if it's a non-XNA class) and a screenshot of the expected result.

Steve Lillis
  • 3,263
  • 5
  • 22
  • 41
  • First, no, there's no call to GraphicsDevice.Clear() anywhere else in the code. Second, All the code I posted was from the default main class of XNA, that extends xna.Framework.Game The stateManager.Draw() simply looks at the current state and calls the Draw method there, passing on the parameters. From there it is just batch.Draw(Texture2D, ... ) I referenced this tutorial when implementing this: [Tuts+ XNA tutorial][1] Thanks for your answer! – Istarnion Jan 06 '15 at 17:52
  • And about the blend mode, you are absolutely right. It whould be AlphaBlend for the lasers an either Opaque or AlphaBlend for the other sprites. I was getting desperate and tried all combinations... – Istarnion Jan 06 '15 at 17:52
  • Made a mistake with the link above, here it is: http://gamedevelopment.tutsplus.com/tutorials/make-a-neon-vector-shooter-in-xna-bloom-and-black-holes--gamedev-9877 – Istarnion Jan 06 '15 at 20:30
  • Do you get rendering when you remove the bloom.BeginDraw()? If so, your issue is that bloom.BeginDraw() is setting values that you are not resetting before performing the rest of your blending. At least, when I used to work with XNA, that is an issue that i have experienced. – Steve Lillis Jan 07 '15 at 10:16
  • Also, per the article you linked, all non-bloom drawing is to occur *after* the call to base.Draw(), so remove your second call. Ultimately, your best bet is to understand how to use a shader in XNA directly and write your own implementation. You'll find it easier than shoe-horning this bloom code into your needs, which will likely end up needing a render target and the like in order to achieve the end result you want. – Steve Lillis Jan 07 '15 at 10:19
  • I think you're right. I've tried to remove either Draw() call, but to no avail. I'll look into RenderTargets and shaders now, though I hope I can still atleast keep using the given shaders. They seem to be pretty flexible. Thanks for your help! I would have given you an upvote on your answer, but I need a bit more rep, sorry. – Istarnion Jan 07 '15 at 11:55