Additive blend from a rendertarget

Hi,

I am trying to render a bunch of flares as additive, if I draw them directly in graphics device it works as intended, but if I draw to a render target first I get full black.

I made a separate project to try and isolate this, this is the code I’m using
Render target creation

renderTarget = new RenderTarget2D(GraphicsDevice, 300, 300, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PreserveContents);

Draw code

GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null);
spriteBatch.Draw(jiro, new Vector2(150, 100), new Rectangle(0, 0, jiro.Width, jiro.Height), Color.White, 0, Vector2.Zero, Vector2.One, SpriteEffects.None, 0);
spriteBatch.End();

GraphicsDevice.SetRenderTarget(renderTarget);
GraphicsDevice.Clear(Color.Transparent);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);
spriteBatch.Draw(sphere, new Vector2(100, 60), new Rectangle(0, 0, sphere.Width, sphere.Height), Color.White, 0, Vector2.Zero, Vector2.One, SpriteEffects.None, 0);
spriteBatch.End();

GraphicsDevice.SetRenderTarget(null);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, null, null, null);
spriteBatch.Draw(renderTarget, Vector2.Zero, renderTargetSourceRect, Color.White, 0, Vector2.Zero, Vector2.One, SpriteEffects.None, 0);
spriteBatch.End();

No clue where things are going wrong :frowning:

Thanks

change order:

GraphicsDevice.SetRenderTarget(renderTarget);
GraphicsDevice.Clear(Color.Transparent);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);
spriteBatch.Draw(sphere, new Vector2(100, 60), new Rectangle(0, 0, sphere.Width, sphere.Height), Color.White, 0, Vector2.Zero, Vector2.One, SpriteEffects.None, 0);
spriteBatch.End();

GraphicsDevice.SetRenderTarget(null);
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null);
spriteBatch.Draw(jiro, new Vector2(150, 100), new Rectangle(0, 0, jiro.Width, jiro.Height), Color.White, 0, Vector2.Zero, Vector2.One, SpriteEffects.None, 0);
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, null, null, null);
spriteBatch.Draw(renderTarget, Vector2.Zero, renderTargetSourceRect, Color.White, 0, Vector2.Zero, Vector2.One, SpriteEffects.None, 0);
spriteBatch.End();

option:

        graphics.PreparingDeviceSettings += graphics_PreparingDeviceSettings;

        void graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
        {
            e.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PreserveContents;
        }
1 Like

Oh I see, sadly this is not the issue I’m having on the real game, but at least now that I got it working on this small example I can dig to figure it out.

Thanks for the help.