Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Let's say I set two render targets

GraphicsDevice.SetRenderTargets(rt0, rt1);

If I call


both render targets will be cleared.

Therefore, how can I clear a render target at a specific index? For example just 'rt1' and not 'rt0'.

I would like to avoid texture baking the contents of 'rt0' to another render target and copying them back to 'rt0'. This is because PreserveContents on the XBOX 360 can only hold one render target in memory.


Is there any way just clear the color for a render target? I would like to keep the depth for depth reading.

share|improve this question
Sorry i misread your question – Kikaimaru Jul 22 '12 at 15:12
up vote 1 down vote accepted

To clear a specific render target you can either call SetRenderTarget() with only the one you want to clear, or use a pixel shader that outputs an opaque colour to one target and transparent to the other.

To avoid clearing depth use GraphicsDevice.Clear(ClearOptions.Target, Color.Transparent, 0.0f, 0);

share|improve this answer
I see so colour *= 1 for the target to keep its contents and *= 0 to lose the contents. How does the avoid clearing depth work what does the 0.0f parameter do? – user1423893 Jul 22 '12 at 17:43
The MSDN documentation for GraphicsDevice.Clear() explains what the extra parameters do. In this case they do nothing since you're only clearing the colour buffer.… – Adam Jul 22 '12 at 21:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.