Multiple Depth Rendering

Started by
3 comments, last by wiselogi 11 years, 10 months ago
I am trying to find a way, how to optimalize my code and becuase i have to render scene depth from more viewpoints, i though, i can just render scene once and render depths to rendertargets.

I am curious, if it's really possible :)

I have tried to pass buffer with four ViewProjection matrixes, i transformed position with all matrices and in a pixel shader, i just divided positions with W component and store them in rendertarget.

Unfortunately :) every rendertarget contain same data, but different depths only. that's wrong.

I hope, there is a solution for that to avoid multiple scene renderings just becuase i need depth maps :)

Thank you very much

DirectX 11, C++

Advertisement
I don't think that this way would work, or at least has any benefit. The reason is, that the depthbuffer is the fastest way to determine the visibility of single pixels. When you render simultaneously to multiple render targets, then you need to handle the visibility problem on your own. This will render many hardware performance features like early-z-rejection, hi-z etc. obsolete.
One possibility is to use render target arrays, and use the geometry shader to amplify your geometry and send it to multiple viewports. This is demonstrated in the CubeMapsGS sample in the SDK. However this is generally slower in terms of GPU performance, due to the geometry shader amplification. But it can decrease CPU overhead, so it can be worth it if you're CPU-bound.
The reason of your results is because with a VS and a PS you can only select ONE rendertarget to rasterize. So, although you are passing all the ViewProj matrices to the Pixel Shader, you selected only one to perform the rasterization, the others you are passing through TEXCOORDS semantics. So, indeed, you are going to get only different ( and meaningless) dephts in the other render targets and the same image, because you selected to rasterize only one of the Views.

As MJP said, the solution is to rasterize multiple views using the Geometry Shader, you gonna pass all your ViewProj matrices and output each one to a different render target. Just like the CubeMapGS as MJP pointed.

Then you can get all your depths in a single pass. Remember that enabling GS yields in a overhead for the GPU, you have to do some profiling to see if it is worthy.

Regardin Ashaman73 concern, that won't happen in this case, each rendertarget will have a depth test of it's own and there will be no visibility problem.
Thinking on this more, I came up with an approach you can use UAVs(D3D11) to avoid GS overhead. I never did this approach, so, fellow forum users, pointing pitfall on this would be useful, although I dont see any (yet).

Lets assume you have three depth buffers to compute. The idea here is to perform your own depth buffer operation manually, using only VS and PS.

1. Bind 2 UAVs to the PS stage
2. Make sure any frustum culling you are doing on the CPU is aware and considering all ViewProj's in the single pass now. Disable any backface culling you might be doing at Hull Shader ( if it is enabled ).
2. Pseucode below

[source lang="csharp"]//lets say UAV[1-2] are your UAVs and ViewProj[1-2] are your ViewProj matrices.
//inPos3D is your 3D position that came from VS

//initialize all your UAVs with '1'
//disable early-z culling

PS()
{
float4 pos1 = mul(inPos3D, ViewProj1);
float4 pos2 = mul(inPos3D, ViewProj2);

pos1.xyz /= pos1.w; pos2.xyz /= pos1.w;

float currentDepth1 = sample(pos1.xy,UAV1); //samples UAV1 at screen pos pos1.xy.
//pos1.xy might not be on the screen, in that case you do nothing
float currentDepth2 = sample(pos2.xy,UAV2);

if(currentDepth1 > pos1.z)
{ //write currentDepth1 at UAV1 at pos1.xy}

if(currentDepth2 > pos2.z)
{//write currentDepth2 at UAV2 at pos2.xy}

//do other stuff
}[/source]
At the end, each of the UAVs are going to have your desired depth buffer

The third depth buffer you dont need a UAV, you gonna use the regular pipeline depth test.

This topic is closed to new replies.

Advertisement