0
\$\begingroup\$

I'm currently rendering my whole game to a RenderTarget in order to stretch the scene to any resolution. I also have a bloom effect rendered with the scene. I'm now working on the UI part of the game, the problem is, I don't want the bloom to affect the UI elements.

So in order to not have the bloom apply to the UI, I need to draw it after the base.Draw(gameTime); call. It works, the UI is not affected by the bloom but is also rendered outside of the render target which isn't making it responsive for every resolution.

How can I incorporate the UI inside the render target but without having it affected by the bloom component?

This is the Draw method code:

    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.SetRenderTarget(_renderTarget);
        GraphicsDevice.Clear(Color.Black);

        Bloom.BeginDraw();

        _currentState.Draw(gameTime, _spriteBatch);
        GraphicsDevice.SetRenderTarget(null);
        _spriteBatch.Begin(blendState: BlendState.AlphaBlend);
        _spriteBatch.Draw(_renderTarget, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
        //_spriteBatch.Draw(texture, new Rectangle(50, 50, 500, 200), new Color(Color.Black, 0.7f));
        _spriteBatch.End();

        base.Draw(gameTime);

        _currentState.PostDraw(gameTime, _spriteBatch);
    }
\$\endgroup\$
4
  • \$\begingroup\$ Are you doing the bloom effect on the CPU or GPU? \$\endgroup\$
    – user122973
    Nov 19, 2022 at 18:38
  • \$\begingroup\$ Please look at craftworks answer to gamedev.stackexchange.com/questions/82841/… \$\endgroup\$
    – user122973
    Nov 19, 2022 at 22:22
  • \$\begingroup\$ @Strom on the GPU using 3 shaders. The answer you posted is not relevant to the question sadly. \$\endgroup\$
    – Syll
    Nov 21, 2022 at 7:24
  • \$\begingroup\$ If you find you're getting suggestions that are not relevant to your use case, it can help to edit your question to clarify the situation. This can help make the question more specific and helpful to future readers navigating similar situations. \$\endgroup\$
    – DMGregory
    Nov 21, 2022 at 12:20

1 Answer 1

1
\$\begingroup\$

I've figured it out thanks to the Monogame community discord. For anyone who will come across this issue - What I did in the end is render the "bloomed scene" to the main render target of the game (instead of the backbuffer as it was until now) and then render both the main render target and the UI elements to a new secondary render target which gets drawn to the backbuffer. So the solution was effectively using 2 render targets which have the same size and are using the same GraphicsDevice. Works like a charm.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Please provide the code to help others searching this issue. \$\endgroup\$
    – user122973
    Nov 21, 2022 at 7:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .