heftyfunseeker
heftyfunseeker

Reputation: 81

Multiple Render Targets in DirectX9

I'm trying to implement very basic deferred shading in DirectX9. I have the ability right now to only use 2 render targets (The back buffer and another texture). So I can render the normals or the depth but not both. My question is can someone explain how to render to more than one texture target. I was under the impression I could just use something like the code below. It only works if the indexes are zero which probably means one of the surfaces is not being written to.

d3dDevice->SetRenderTarget(0, surfaceDepth);
d3dDevice->SetRenderTarget(1, surfaceNormal);

I get this message: Direct3D9: (WARN) :Can not render to a render target that is also used as a texture. A render target was detected as bound, but couldn't detect if texture was actually used in rendering.

I know there is probably a few things that could be related to this message...I guess if someone could explain how to use multiple render target indexes correctly. Also do you change the technique for each render target. Right now my shader has a "normal technique" and a "depth technique" and the "post process technique" for the pipeline.

Thanks for your time.

here is some more code:

SetTransforms();
d3dDevice->SetRenderTarget(0, surfaceDepth);
HR(d3dDevice->Clear( 0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, 0xff000000, 1.0f, 0));
scenes[sceneIndex]->setTechnique("depthTech");
scenes[sceneIndex]->render(dt);

d3dDevice->SetRenderTarget(1, surfaceNormal);
HR(d3dDevice->Clear( 0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, 0xff000000, 1.0f, 0));
scenes[sceneIndex]->setTechnique("normalTech");
scenes[sceneIndex]->render(dt);

Upvotes: 2

Views: 3372

Answers (2)

Darthman
Darthman

Reputation: 457

Your question made me discover this issue more intensively.

That's what I found:

first you must check your D3DCAPS9.NumSimultaneousRTs. Is it more then 1? All rendertargets must be SAME resulution and bit depth, but can be different formats. You can not use any antialiasing.

Upvotes: 2

heftyfunseeker
heftyfunseeker

Reputation: 81

You just say set d3dDevice->SetRenderTarget(n, surface) for all targets where n is the target number and then you set the technique that outputs to a multiple render target structure in the pixel shader

Upvotes: 2

Related Questions