Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

        Game.GraphicsDevice.SetRenderTarget(physicsTexture);
        Game.GraphicsDevice.Clear(Color.White);

        noiseEffect.CurrentTechnique.Passes[0].Apply();

        DrawQuad();

        Game.GraphicsDevice.SetRenderTarget(null);

        physicsTexture.GetData<Color>(physicsBuffer);

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

1 Answer 1

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

 
discard

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.