tags:

views:

228

answers:

3

I've set

m_lpD3DDevice->SetRenderTarget(0,Buffer1);
m_lpD3DDevice->SetRenderTarget(1,Buffer2);
m_lpD3DDevice->SetRenderTarget(2,Buffer2);

and if I render the pixelshader only affects the first render target.

It's output structure is

struct PS_OUTPUT
{
    float4 Color0    :  COLOR0;
    float4 Color1    :  COLOR1;
    float4 Color2    :  COLOR2;
};

what do I need to do to affect the other two render targets too?

A: 

In your pixel shader, make sure you're returning the struct not a float4. Also don't beind the semantion COLOR0 to the function signature, that is don't do this:

PS_OUTPUT myPS(VS_OUTPUT): COLOR0

I duobt that will copmpile, but it might confuse the compiler. A simple MRT shader looks like this:

PS_OUTPUT myPS(VS_OUTPUT)
{
    PS_OUTPUT out;
    out.color0 = float4(0.5,0.5,0.5,1.0);
    out.color1 = float4(0.2,0.5,0.8,1.0);
    out.color2 = float4(0.8,0.5,0.2,1.0);
    return out;
}

What are buffer0,1 & 2? Are they the result of a call to CreateTexture()? (or rather a surface from that texture). If they are, make sure the texture was created with the render target usage flag: D3DUSAGE_RENDERTARGET.

Make sure your card can support rendering to more than one RT. (forgotten how to do this - but I doubt that it won't support them.)

If you've created the buffers correctly, set them correctly, and are writing the correct values out of the pixel shader correctly, then I don't see what could go wrong. What does PIX* say about the MRTS? Are they benig written to, and it';s the displaying of them that's going wrong?

ps: You hopefully made a draw call, right? :)

*PIX is an application in the DirectX SDK. If you've not used it before, you're really missing out :)

Pod
A: 

I finally have the answer now. All I had to do was to set

ColorWriteEnable = red | green | blue;

in the effect file. Everything else was correct. But I don't know why this made it work.

gufftan
A: 

There is a separate color write mask for each target. The default write mask for target 0 is 0xf (all channels enabled), but the default for other targets is 0x0. Overriding this in the effect file is one way (did you want to enable alpha though?), or you can change it with SetRenderState. See the documentation for the D3DRS_COLORWRITEENABLE{1,2,3} states.

Jesse Hall