Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I need to read depth buffer from GPU and write it to texture. How this can be done? Here is how texture for depth buffer is created:

depthBufferDesc.Width = screenWidth;
depthBufferDesc.Height = screenHeight;
depthBufferDesc.MipLevels = 1;
depthBufferDesc.ArraySize = 1;
depthBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthBufferDesc.SampleDesc.Count = 1;
depthBufferDesc.SampleDesc.Quality = 0;
depthBufferDesc.Usage = D3D10_USAGE_DEFAULT;
depthBufferDesc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
depthBufferDesc.CPUAccessFlags = 0;
depthBufferDesc.MiscFlags = 0;

m_device->CreateTexture2D(&depthBufferDesc, NULL, m_depthStencilBuffer);

Also, I've got another question: is it possible to bind depth buffer texture as sampler to the pixel shader?

share|improve this question

1 Answer 1

You bind that texture to a depth stencil view and also a shader resource view to sample from it in another shader.

You need to add D3D10_BIND_SHADER_RESOURCE to the depthBufferDesc.BindFlags field.

share|improve this answer
    
I have following settings for stencil depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; and this how I try to obtain resource D3D10_SHADER_RESOURCE_VIEW_DESC srDesc; srDesc.Format = DXGI_FORMAT_R32_FLOAT; srDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; srDesc.Texture2D.MostDetailedMip = 0; srDesc.Texture2D.MipLevels = 1; ID3D10ShaderResourceView* Resource; m_device->CreateShaderResourceView( m_depthStencilBuffer, &srDesc, &Resource ); –  innochenti Mar 18 '12 at 18:30
    
You need to make sure that your formats match up - in this case use DXGI_FORMAT_R24G8_TYPELESS for the SRV desc. –  Darth Satan Jun 16 '12 at 19:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.