[DX10] Deferred rendering and render to multiple render targets

Started by
8 comments, last by n3Xus 15 years, 4 months ago
I'm trying to get deferred rendering running but I'm stuck at multiple render targets. To prevent too many draw() calls I want to render to multiple render targets in one pass. How exactly do I do that? Should I use ID3D10Device::OMSetRenderTargets and put the number of render targets as the 1st parameter? If that is so, how can I create such an ID3D10RenderTargetView that is made up of render targets with different formats? Is this even possible? How does one usually do this for deferred rendering? Or am I totally missing something? Well the "main" question I'm asking is how to render to multiple render targets in one "draw-call-pass".
Advertisement
Quote:Original post by n3Xus
Should I use ID3D10Device::OMSetRenderTargets and put the number of render targets as the 1st parameter?
Yup, pretty much all there is to it - provided your views and resources are configured accordingly. Remember to check that you're not binding a resource that is also bound as an input.

Your application code handles the array side of things, unlike texture arrays where the API has a specific concept of a texture array...

Quote:Original post by n3Xus
can I create such an ID3D10RenderTargetView that is made up of render targets with different formats? Is this even possible?
From MSDN:
Quote:A pixel shader can be used to render to at least 8 separate render targets, all of which must be the same type (buffer, Texture1D, Texture1DArray, etc...). Furthermore, all render targets must have the same size in all dimensions (width, height, depth, array size, sample counts). Each render target may have a different data format.

You may use any combination of render targets slots (up to 8). However, a resource view cannot be bound to multiple render-target-slots simultaneously. A view may be reused as long as the resources are not used simultaneously.
(emphasis mine)


hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Thanks,

but I'm also having problems how to make this work in code.
Here is the problem: I don't know how to create a ID3D10RenderTargetView with different formats. I'm confused at this part:
device->OMSetRenderTargets(numOfRenderTargets,rtView,NULL);

So here rtView is an array of all the render targets I want to bind, so I guess this must mean I have to do something special when creating the ID3D10RenderTargetView array, but I'm not sure what-the main problem now is that I don't know how to create such an array of ID3D10RenderTargetView.

So when I call
device->CreateRenderTargetView(texture2d,&descRT,&rtView)

must I use rtView in more than one device->CreateRenderTargetView call so an array of render targets will be created?

You want an array of RT Views, each of which can have an array of texture slices (from the same texture).

ID3D10RenderTargetView* pRTViews[8] = {NULL, NULL, NULL, ... }

CreateRenderTargetView(rtTex1, &pRTViews[0])
CreateRenderTargetView(rtTex2, &pRTViews[1])

OMSetRenderTargets(numViews, pRTViews, pDSView)
Assassin, aka RedBeard. andyc.org
Yeah, that's what I wanted :D I never thought of doing that although it's so simple...
I have another question now that I got multiple render targets running: how to output a different shader effect to them?
SO I'd like to output the normals to one of them, the world position to another and the color to the third one.
Right now I render my model with the shader that outputs the normals, how would I make it output it's color and world position at the same time to the other two render targets so I won't have to redraw the entire scene 3 times?
bump
bump
Quote:Original post by n3Xus
I have another question now that I got multiple render targets running: how to output a different shader effect to them?
SO I'd like to output the normals to one of them, the world position to another and the color to the third one.
Right now I render my model with the shader that outputs the normals, how would I make it output it's color and world position at the same time to the other two render targets so I won't have to redraw the entire scene 3 times?


Just output multiple values from your pixel shader. Write what you want in render target 0 to SV_Target0, render target 1 to SV_Target1, and render target 2 to SV_Target2. For example:

struct PS_OUTPUT
{
float4 Diffuse : SV_Target0;
float4 Normal : SV_Target1;
float4 Position : SV_Target2;
};

Then you can output all 3 of these in one pass.
Thanks a lot, works like a charm!

This topic is closed to new replies.

Advertisement