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?

  • \$\begingroup\$ 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. \$\endgroup\$ Sep 25, 2011 at 14:24

1 Answer 1


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.


You must log in to answer this question.

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