locked
Depth test Problem

    Question

  • After one day of searching and comparing my code with the Direct3D sample from vs2012 I did not found an answer.

    I'm a beginning with DirectX and I can't make my depth test to work properly.

    This is my test project https://s3.amazonaws.com/bitbrusher/3dapp.zip

    Can any one help me find my problem?

    Regards


    Dhiogo Brustolin

    Tuesday, December 11, 2012 12:57 PM

Answers

  • Hi,

    You just have to initialize the DepthStencil state :

    Microsoft::WRL::ComPtr<ID3D11DepthStencilState> DepthDefault;
    
    D3D11_DEPTH_STENCIL_DESC depthstencilDesc;
    ZeroMemory(&depthstencilDesc, sizeof(depthstencilDesc));
    depthstencilDesc.DepthEnable = true;
    depthstencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
    depthstencilDesc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
    depthstencilDesc.StencilEnable = false;
    
    dev->CreateDepthStencilState(&depthstencilDesc, &DepthDefault);
    
    devcon->OMSetDepthStencilState(DepthDefault.Get(), 0)

    Tuesday, December 11, 2012 2:28 PM

All replies

  • Hi,

    You just have to initialize the DepthStencil state :

    Microsoft::WRL::ComPtr<ID3D11DepthStencilState> DepthDefault;
    
    D3D11_DEPTH_STENCIL_DESC depthstencilDesc;
    ZeroMemory(&depthstencilDesc, sizeof(depthstencilDesc));
    depthstencilDesc.DepthEnable = true;
    depthstencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
    depthstencilDesc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
    depthstencilDesc.StencilEnable = false;
    
    dev->CreateDepthStencilState(&depthstencilDesc, &DepthDefault);
    
    devcon->OMSetDepthStencilState(DepthDefault.Get(), 0)

    Tuesday, December 11, 2012 2:28 PM
  • Thank you very much.

    Can you tell me why the VS2012 sample of Direct3D app store doent use this DepthStencilState and works fine??

    Best Regards


    Dhiogo Brustolin

    Tuesday, December 11, 2012 5:24 PM
  • The sample uses a default DepthStencil state (with Depth disabled). It works fine because there is only one cube to draw and the back faces are not drawn (back face culling).

    Anyway you should always set the render states : Rasterizer, DepthStencil, Blend and Sampler.

    Best regards.
    Tuesday, December 11, 2012 7:32 PM
  • For the extremely simple case in the sample, back-face culling is sufficient 'hidden surface removal' to make things appear correct. There are actually a number of differnet algorithms for doing this that don't use a Depth Buffer, but the Depth Buffer (aka z-buffer) solution is the general one most 3D rendering uses today.

    http://en.wikipedia.org/wiki/Hidden_surface_determination

    Tuesday, December 11, 2012 11:01 PM