Advertisement Jump to content
Sign in to follow this  

OpenGL Direct3D 11 Depth

This topic is 3186 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm having a problem with depth in Direct3D 11. I made a screen shot illustrating my problem here: I've looked around and tried several things, I also made a little test program in OpenGL comparing the function calls related to depth in my Direct3D 11 application etc. It works fine there. My depth buffer format is DXGI_FORMAT_D32_FLOAT. Here's what I'm doing:
D3D11_RASTERIZER_DESC rasterizerDesc;
memset(&rasterizerDesc, 0, sizeof(rasterizerDesc));
rasterizerDesc.FillMode = D3D11_FILL_SOLID;
rasterizerDesc.CullMode = D3D11_CULL_NONE/*D3D11_CULL_BACK*/;
rasterizerDesc.DepthClipEnable = TRUE;
rasterizerDesc.MultisampleEnable = (sampleCount > 1);

result = d3dDevice->CreateRasterizerState(&rasterizerDesc, &d3dRasterizerState);

D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
memset(&depthStencilDesc, 0, sizeof(depthStencilDesc));
depthStencilDesc.DepthEnable = TRUE;
depthStencilDesc.DepthWriteMask = /*D3D11_DEPTH_WRITE_MASK_ALL*/D3D11_DEPTH_WRITE_MASK_ZERO;
depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
depthStencilDesc.StencilEnable = FALSE;
result = d3dDevice->CreateDepthStencilState(&depthStencilDesc, &d3dDepthStencilState);
d3dContext->OMSetDepthStencilState(d3dDepthStencilState, 0);

Render loop:

d3dContext->ClearRenderTargetView(d3dRTV, CLEAR_COLOR);
d3dContext->ClearDepthStencilView(d3dDSV, D3D11_CLEAR_DEPTH, 1.0f, 0);

d3dContext->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset);
d3dContext->IASetIndexBuffer(indexBuffer, DXGI_FORMAT_R32_UINT, 0);

d3dContext->VSSetShader(d3dVS, NULL, 0);
d3dContext->PSSetShader(d3dPS, NULL, 0);

d3dContext->PSSetSamplers(0, 1, &d3dSamplerState);

for (int i = 0; i < numMeshes; i++)
  Mesh& mesh = meshes;
  d3dContext->PSSetShaderResources(0, 1, &mesh.shaderResource);
  d3dContext->DrawIndexed(mesh.numIndices, mesh.firstIndex, 0);

swapChain->Present(0, 0);
Hope someone can solve my little mistake! Thanks!

Share this post

Link to post
Share on other sites
This right here:

depthStencilDesc.DepthWriteMask = /*D3D11_DEPTH_WRITE_MASK_ALL*/D3D11_DEPTH_WRITE_MASK_ZERO;

You're specifying that the depth buffer shouldn't be written to at all, which is why the depth test is always passing.

Share this post

Link to post
Share on other sites
Yeah, I was playing with the values a bit because I was at a loss. But changing it to D3D11_DEPTH_WRITE_MASK_ALL, makes it worse and now the entire world is visible to me. I must've done something stupid somewhere, but I can't find it. :-P

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!