Jump to content

  • Log In with Google      Sign In   
  • Create Account


DirectX11 Depth test


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 EdKeens   Members   -  Reputation: 103

Like
0Likes
Like

Posted 18 January 2014 - 12:24 PM

Hello,

I'm trying to enable depth testing for windows phone 8 app I'm coding, but with no success. I've followed this article but it doesn't work for me, objects are just put in front of previously rendered objects. Here's my initialization code:

// Create a depth stencil view.
CD3D11_TEXTURE2D_DESC depthStencilTDesc(
    DXGI_FORMAT_D24_UNORM_S8_UINT,
    static_cast<UINT>(m_renderTargetSize.Width),
    static_cast<UINT>(m_renderTargetSize.Height),
    1,
    1,
    D3D11_BIND_DEPTH_STENCIL
    );

ComPtr<ID3D11Texture2D> depthStencil;
DX::ThrowIfFailed(
    m_d3dDevice->CreateTexture2D(
        &depthStencilTDesc, 
        nullptr,
        &depthStencil
        )
    );


CD3D11_DEPTH_STENCIL_DESC depthStencilDesc;
// Set up the description of the stencil state.
depthStencilDesc.DepthEnable = true;
depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;

depthStencilDesc.StencilEnable = true;
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;

ComPtr<ID3D11DepthStencilState> state;
DX::ThrowIfFailed(
    m_d3dDevice->CreateDepthStencilState(
    &depthStencilDesc,
    state.GetAddressOf()
    )
    );

m_d3dContext->OMSetDepthStencilState(state.Get(), 1);

CD3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc(D3D11_DSV_DIMENSION_TEXTURE2D, DXGI_FORMAT_D24_UNORM_S8_UINT, 0);
DX::ThrowIfFailed(
    m_d3dDevice->CreateDepthStencilView(
    depthStencil.Get(),
    &depthStencilViewDesc,
    &m_depthStencilView
    )
    );

And then I run this before each draw call

// Clear depth buffer
m_d3dContext->ClearDepthStencilView(
    m_depthStencilView.Get(),
    D3D11_CLEAR_DEPTH,
    1.0f,
    0
    );

// set render target
m_d3dContext->OMSetRenderTargets(
    1,
    m_renderTargetView.GetAddressOf(),
    m_depthStencilView.Get()
    );


Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS