I need to write to two render targets: one for colour and another for depth+normal (for post-processing). I have a problem, though. Both targets seem to be getting the value output by COLOR0, while the second should logically be getting the value from COLOR1. What did I do wrong?

RT Initialization:

renderTarget = new RenderTarget2D(device, gameResolution.Width, gameResolution.Height, false, graphics.PreferredBackBufferFormat, DepthFormat.Depth24);
extraTarget = new RenderTarget2D(device, gameResolution.Width, gameResolution.Height, false, SurfaceFormat.Color, DepthFormat.None);

Using RTs:

Device.SetRenderTargets(new RenderTargetBinding(renderTarget), new RenderTargetBinding(extraTarget));

Relevant HLSL:

struct Pixel
    float4 Color : COLOR0;
    float4 Extra : COLOR1;

Pixel PS(Middle input)
    Pixel output;

    // perform other shader code

    output.Color = float4(totalDiffuse * matDiffuseColor * color.rgb + totalSpecular * matSpecularColor, color.a);
    output.Extra = float4(input.Position.z / input.Position.w, clippedNormal);

    return output;

Try to set your render targets directly:

Device.SetRenderTargets(renderTarget, extraTarget);
  • \$\begingroup\$ I tried this first, but to no avail. \$\endgroup\$ – jmegaffin Apr 20 '12 at 18:46
  • \$\begingroup\$ Are you sure that your graphics card supports more than one render target? I think that your code is correct. \$\endgroup\$ – Vodáček Apr 20 '12 at 19:07
  • \$\begingroup\$ How do I check for this? \$\endgroup\$ – jmegaffin Apr 20 '12 at 19:14
  • \$\begingroup\$ Try to use this tool: create.msdn.com/en-US/education/catalog/utility/… \$\endgroup\$ – Vodáček Apr 20 '12 at 19:19
  • 1
    \$\begingroup\$ @Boreal Do you think you could spare the time to say which? If you propose an edit to Vodacek's post which details the combination, you'll be able to help other people who had your same problem in the future who find this answer. \$\endgroup\$ – doppelgreener Apr 21 '12 at 0:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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