# Depth Stencil Texture array to render cube depth map in one pass

7 replies to this topic

### #1SuperPixel

Valued Member

• Members
• 306 posts

Posted 29 August 2012 - 03:20 PM

Hi all,

I'm wondering if it's possible to create 6 depth stencil surfaces for a cube depth map and then render

into them in the geometry shader in one pass using SV_RenderTargetArrayIndex.

I want to just bind the depth stencil part and not the render target part, since I'd like to disable color writes during shadow map generation, so there's no point in passing any render target.

I would do deviceContext->OMSetRenderTargets( ...,..., cubeDepthStencilMapView );

I would expect that if I do something like this in the geometry shader:

struct GS_OUTPUT{
float4 Pos : SV_Position;
uint	cubeDepthMapIndex : SV_RenderTargetArrayIndex;
};

...
for( uint i=0;i<6;++i){
cubeDepthMapIndex = i;

}
...


It will index the correct depth stencil surface even if there is no render target bound ? ...
I can't think that I have to create 6 depth stencil view and 6 render target view when the only thing that I need is just depth (moreover, color writes disabled make the rendering faster).

Can anyone confirm this possibility ?

### #2SuperPixel

Valued Member

• Members
• 306 posts

Posted 30 August 2012 - 05:51 PM

Obviously I need to disable color writes on all the 6 depth stencil buffer (I bind one depthstencilview created as a texture2Darray resource, I assume that will be mapped on the first 6 slot like if I was setting 6 render targets ... am I correct in assuming this ?) ...

should I create a blend state with color writes disabled on all the 6 render target ? currently I do somehting like:

fdkGfxSetRenderTarget(device,NULL,mDeferredData->mPointLightShadowMapBufferId);



and the blend state created like:

//additive blend state desc
FdkGfxBlendStateDesc bsDesc;
ZeroMemory(&bsDesc,sizeof(FdkGfxBlendStateDesc));
bsDesc.independentBlendEnable				= false;
bsDesc.alphaToCoverageEnable				 = false;
bsDesc.renderTarget[0].blendEnable		   = true;
bsDesc.renderTarget[0].srcBlend			  = FDK_BLEND_ONE;
bsDesc.renderTarget[0].destBlend			 = FDK_BLEND_ONE;
bsDesc.renderTarget[0].srcBlendAlpha		 = FDK_BLEND_ONE;
bsDesc.renderTarget[0].destBlendAlpha		= FDK_BLEND_ZERO;
mDeferredData->bsId						  = fdkGfxCreateBlendState(device,&bsDesc);
//create
bsDesc.renderTarget[0].destBlend			 = FDK_BLEND_ZERO;
mDeferredData->bsNoColorWritesId			 = fdkGfxCreateBlendState(device,&bsDesc);


should I disable blending as well ? I dont set the other renderTarget[1],renderTarget[2] ... up to 5 becaouse I ZeroMemory the structure so I expect that blend enable is 0 and renderTargetWriteMask too.
However my application is damn slow ! So something strange happens and I think I did something wrong ... If I try debug in pix the app crashes ... :/

Any Idea ?

### #3SuperPixel

Valued Member

• Members
• 306 posts

Posted 03 September 2012 - 02:21 PM

Any hint ? I can't think that I need a render target array of color along with the depth stencil one if I have to just render shadow data...

### #4Alienizer

Member

• Members
• 435 posts

Posted 03 September 2012 - 04:18 PM

Well, either nobody knows, or they are on vacation! I sure don't know the answer.

### #5SuperPixel

Valued Member

• Members
• 306 posts

Posted 04 September 2012 - 07:20 AM

Alienizer, on 03 September 2012 - 04:18 PM, said:

Well, either nobody knows, or they are on vacation! I sure don't know the answer.

It's quite a simple question, I guess there is just some messiness concerning the parameters setting somewhere. In general I just wanted to verify that the basic creation process was correct.

The question is: Is it possible to create depthStencilView created as an array resource to render into its array element using SV_RenderTargetArrayIndex, without the need of a render target view (so render target view is set to null).
I need this to render a simple shadow cube map and I need obviously just depth (so color writes are disabled -> faster rendering ).

### #6SuperPixel

Valued Member

• Members
• 306 posts

Posted 04 September 2012 - 09:49 AM

From "Programming Vertex, Geometry and Pixel shaders":

There are some things to keep in mind though: As of Direct3D 10, you can
only set one depth stencil surface to the device at any given time. This
means that you need to store the depth values in the color data of the
render targets. Fortunately, D3D10 pixel shaders let us to handle
arbitrary values (including colors) as depth via views to typeless
resources, so this isn’t a problem.

I'm actually using DX10.1 so I think that might depend on that.

If that is the problem: Isn't slower generating the shadow map with color writes on ? Maybe in dx11 I can bound more than one depth stencil view ...

tbh on the internet I've found some people outputting linear depth in world space or view space to get more precision out of it and in that case a color buffer was compulsory if you don't want z/w hiperbolic falloff

Any thoughts on this ?

### #7Alienizer

Member

• Members
• 435 posts

Posted 05 September 2012 - 02:51 AM

Sorry, but I am not an expect at this at all. I too ask questions on this board and there are a few very knowledgeable guys who answer, but I think they are not around right now, back to school etc. you know! I just thought to reply since nobody else did so you don't think you are getting ignored!

### #8SuperPixel

Valued Member

• Members
• 306 posts

Posted 05 September 2012 - 09:43 AM

Alienizer, on 05 September 2012 - 02:51 AM, said:

Sorry, but I am not an expect at this at all. I too ask questions on this board and there are a few very knowledgeable guys who answer, but I think they are not around right now, back to school etc. you know! I just thought to reply since nobody else did so you don't think you are getting ignored!

Hi,

no probs, the thing is that I made a mistake myself . When we use a cubemap we output radial distance from the light not depth (which we could if we decide to not to go for cubemaps but for 6 spot lights to approximate the environment surrounding the point light).

So, my question was wrong in the first place.

Since I decided to use cubemaps for spot light then I MUST use render target in order to write color along with depthstencil to have depth test.

So sorry for my question

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users