1
\$\begingroup\$

For now i know what i must use OMSetDepthStencilState. In the beginning i must create two states and change them every time i need another. For now i have this and it doesn't work, i.e. objects rendered in order i draw them:

D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
depthStencilDesc.DepthEnable = TRUE;
depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
depthStencilDesc.StencilEnable = FALSE;
depthStencilDesc.StencilReadMask = 0xFF;
depthStencilDesc.StencilWriteMask = 0xFF;

// Stencil operations if pixel is front-facing
depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

// Stencil operations if pixel is back-facing
depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

ID3D11DepthStencilState *m_DepthStencilState;
HR(m_Device->CreateDepthStencilState(&depthStencilDesc, &m_DepthStencilState));
m_ImmediateContext->OMSetDepthStencilState(m_DepthStencilState, 0);
\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Change

depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;

to

depthStencilDesc.DepthFunc = D3D11_COMPARISON_ALWAYS;
\$\endgroup\$
2
  • \$\begingroup\$ in theory, together with DepthEnable = FALSE it should turn off depth buffer, but it doesn't work without setting its state and if set it either. I need first to make it work. \$\endgroup\$
    – Yola
    Dec 11, 2014 at 12:02
  • 1
    \$\begingroup\$ You may want to look at DirectX Tool Kit CommonStates helper. It creates some depth-buffer state objects that handle standard depth, read-only depth, and no-depth. \$\endgroup\$ Dec 13, 2014 at 19:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .