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

I'm setting a render target in XNA using the following lines of code:






Now, physicsTexture is a RenderTarget2D. This texture already has some of its pixels colored by the CPU before it gets set as the render target.

So when my pass in the HLSL pixel shader runs, my question is: Can I get the current pixel color of a given texture coordinate using tex2D or something similar on the render target, before drawing a new pixel at that area?

share|improve this question
Before the pass, you .Clear() the surface to white. So, all of the pixels on the RenderTarget2D would be white when your pass runs. Maybe I've misunderstood your question. – Richard Marskell - Drackir Sep 25 '11 at 14:24
up vote 6 down vote accepted

Unfortunately no. You cannot read from the current render target in a shader. You have two basic options:

  1. If the operation you would do with the read fragment color is simple enough that you can achieve it using blend state operations, you can use those.

  2. You can pass the color data you need into shader via some other resource, for example, a texture containing a copy of the framebuffer prior to execution of the render pass that you're currently in, which can be read as a normal texture.

share|improve this answer

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.