My game currently uses multiple screens to represent different things to be rendered to the game screen. For instance I have a screen that renders the 3D scene and another screen that renders the GUI ontop of the 3D scene. The screens are stack based and drawn from bottom to top.
I'm trying to apply different post processing effects to each screen. I'm having trouble because I can't get the transparency to work right for screens that require transparent values. The GUI won't allow the 3D scene to be shown because when I draw the GUI I must clear the render target used by the post processing effect.
Heres my code for drawing a screen. Each frame of my game I iterate through every screen and draw them. The ScreenManager calls the screen's BeginDraw(), Draw(GameTime gameTime), then EndDraw() methods.
internal void BeginDraw()
{
// Change to the off screen render target.
this.previousTarge t= this.Graphics.GraphicsDevice.GetRenderTarget(0) as RenderTarget2D;
this.Graphics.GraphicsDevice.SetRenderTarget(0, this.renderTarget);
this.Graphics.GraphicsDevice.Clear(Color.TransparentWhite);
}
internal void EndDraw()
{
// Change back to the back buffer and get the scene as a texture.
this.Graphics.GraphicsDevice.ResolveRenderTarget(0);
this.shaderTexture = this.renderTarget.GetTexture();
this.Graphics.GraphicsDevice.SetRenderTarget(0, this.previousTarget);
// Draw the screen.
this.spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.SaveState);
if (this.effects.Count == 0)
{
this.spriteBatch.Draw(this.shaderTexture, Vector2.Zero, Color.White);
}
else
{
foreach (Effect effect in this.effects)
{
effect.Begin();
// Activate each pass in the effect.
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
this.spriteBatch.Draw(this.shaderTexture, Vector2.Zero, Color.White);
pass.End();
}
}
this.spriteBatch.End();
}