Reputation: 308
I'm trying to render to multiple ID3D11RenderTargetView
simultaneously.
But it seems that only the first target is being rendered:
ID3D11RenderTargetView* targets [ 2 ] = { _backbuffer
, _renderToTextureRTV
};
_devcon->OMSetRenderTargets( 2, targets, nullptr );
Depending on which parameter I specify first in my targets
array, will be rendered. The other render target view will not be rendered.
I create my IDXGISwapChain
with D3D11_CREATE_DEVICE_DEBUG
flag and cannot see any error messages related to this function.
I can reproduce the same problem if I specify nullptr
as first targets
element. In this case the second element will not be rendered.
But if I specify nullptr
as the second element, the first element will be rendered correctly.
Why does OMSetRenderTargets
seem to only evaluate the first targets
element?
Edit:
What I'm actually trying to achieve is to render to the backbuffer and to a texture simultaneously. I need to render to a texture, as I want to be able to access the pixel values from the CPU.
I want to render to a 16 bit unsigned image, so I use DXGI_FORMAT_R16G16B16A16_UNORM
for the texture.
For the backbuffer, I need to use a different format suitable for screen display, so I use DXGI_FORMAT_R16G16B16A16_FLOAT
.
For performance reasons, I do not want to element-wise convert between the two and this is the reason why I have two render targets.
Upvotes: 0
Views: 802
Reputation: 370
Is your pixel shader similar to this one? You need to manually set which render target the pixel shader outputs to:
struct Output
{
float4 target0 : SV_Target0;
float4 target1 : SV_Target1;
};
Output PixelShader(float4 pos : SV_Position)
{
Output output;
output.target0 = float4(1.0, 0, 0, 0); //Output to the first rendertarget
output.target1 = float4(0, 1.0, 0, 0); //Output to the second rendertarget
return output;
}
Upvotes: 2