Sign in to follow this  
n3Xus

[DX10] Deferred rendering and render to multiple render targets

Recommended Posts

n3Xus    951
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".

Share this post


Link to post
Share on other sites
jollyjeffers    1570
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

Share this post


Link to post
Share on other sites
n3Xus    951
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?

Share this post


Link to post
Share on other sites
Assassin    246
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)

Share this post


Link to post
Share on other sites
n3Xus    951
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?

Share this post


Link to post
Share on other sites
andur    781
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this