Direct3D dpeth complexity visualization

0

I'm a begginer at Direct3D :D

I tried to visualization depth complexity with stencil buffer Visualization, but it looks something wrong.

Look closely hills in this picture you can know what I'm talking about. If the camera move left, depth complexity increase, while it decrease if move right.

Please see my code and tell me what I did wrong.

first I made 2 depthstencilstates. DepthComplexityWriteDSS used to write depth complexity in stencil buffer and DepthComplexityCheckDDS used to visualization depth complexity.

//
// DepthComplexityWriteDSS
//
D3D11_DEPTH_STENCIL_DESC depthComplexityWriteDesc;
ZeroMemory(&depthComplexityWriteDesc, sizeof(D3D11_DEPTH_STENCIL_DESC));
depthComplexityWriteDesc.DepthEnable = true;
depthComplexityWriteDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
depthComplexityWriteDesc.DepthFunc = D3D11_COMPARISON_LESS;

depthComplexityWriteDesc.StencilEnable = true;
depthComplexityWriteDesc.StencilReadMask = 0xff;
depthComplexityWriteDesc.StencilWriteMask = 0xff;
//front
depthComplexityWriteDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthComplexityWriteDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
depthComplexityWriteDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_INCR;
depthComplexityWriteDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
//back
depthComplexityWriteDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthComplexityWriteDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
depthComplexityWriteDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_INCR;
depthComplexityWriteDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

device->CreateDepthStencilState(&depthComplexityWriteDesc, &DepthComplexityWriteDSS);

//
// DepthComplexityCheckDDS
//
D3D11_DEPTH_STENCIL_DESC depthComplexityCheckDesc;
ZeroMemory(&depthComplexityWriteDesc, sizeof(D3D11_DEPTH_STENCIL_DESC));
depthComplexityCheckDesc.DepthEnable = true;
depthComplexityCheckDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
depthComplexityCheckDesc.DepthFunc = D3D11_COMPARISON_LESS;

depthComplexityCheckDesc.StencilEnable = true;
depthComplexityCheckDesc.StencilReadMask = 0xff;
depthComplexityCheckDesc.StencilWriteMask = 0xff;
//front
depthComplexityCheckDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthComplexityCheckDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
depthComplexityCheckDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthComplexityCheckDesc.FrontFace.StencilFunc = D3D11_COMPARISON_EQUAL;
//back
depthComplexityCheckDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthComplexityCheckDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
depthComplexityCheckDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthComplexityCheckDesc.BackFace.StencilFunc = D3D11_COMPARISON_EQUAL;

device->CreateDepthStencilState(&depthComplexityCheckDesc, &DepthComplexityCheckDSS);

Next I set depthstencilstate with DepthComplexityWriteDSS and then draw hill, water, cylinder. (I think it's not important process)

Last, at camera position I drew boxes that colored for each depth complexity .

//draw boxes
activeTech = Effects::BasicFX->Light0Tech;
activeTech->GetDesc(&techDesc);
for (UINT p = 0; p < techDesc.Passes; ++p)
{
    md3dImmediateContext->IASetVertexBuffers(0, 1, &mBoxVB, &stride, &offset);
    md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0);
    md3dImmediateContext->RSSetState(RenderStates::NoCullRS);

    //first box
    XMMATRIX world = XMMatrixTranslation(mEyePosW.x, mEyePosW.y, mEyePosW.z);
    XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
    XMMATRIX worldViewProj = world * view * proj;
    mBoxMat.Diffuse = XMFLOAT4(reinterpret_cast<const float*>(&Colors::Blue));
    Effects::BasicFX->SetWorld(world);
    Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose);
    Effects::BasicFX->SetWorldViewProj(worldViewProj);
    Effects::BasicFX->SetMaterial(mBoxMat);

    md3dImmediateContext->OMSetDepthStencilState(RenderStates::DepthComplexityCheckDSS, 1);
    activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
    md3dImmediateContext->DrawIndexed(mBoxIndexCount, 0, 0);

    //second box
    mBoxMat.Diffuse = XMFLOAT4(reinterpret_cast<const float*>(&Colors::Green));
    Effects::BasicFX->SetMaterial(mBoxMat);

    md3dImmediateContext->OMSetDepthStencilState(RenderStates::DepthComplexityCheckDSS, 2);
    activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
    md3dImmediateContext->DrawIndexed(mBoxIndexCount, 0, 0);

    //third box
    mBoxMat.Diffuse = XMFLOAT4(reinterpret_cast<const float*>(&Colors::Cyan));
    Effects::BasicFX->SetMaterial(mBoxMat);

    md3dImmediateContext->OMSetDepthStencilState(RenderStates::DepthComplexityCheckDSS, 3);
    activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
    md3dImmediateContext->DrawIndexed(mBoxIndexCount, 0, 0);

    //fourth box
    mBoxMat.Diffuse = XMFLOAT4(reinterpret_cast<const float*>(&Colors::Magenta));
    Effects::BasicFX->SetMaterial(mBoxMat);

    md3dImmediateContext->OMSetDepthStencilState(RenderStates::DepthComplexityCheckDSS, 4);
    activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
    md3dImmediateContext->DrawIndexed(mBoxIndexCount, 0, 0);

    //fifth box
    mBoxMat.Diffuse = XMFLOAT4(reinterpret_cast<const float*>(&Colors::LightSteelBlue));
    Effects::BasicFX->SetMaterial(mBoxMat);

    md3dImmediateContext->OMSetDepthStencilState(RenderStates::DepthComplexityCheckDSS, 5);
    activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
    md3dImmediateContext->DrawIndexed(mBoxIndexCount, 0, 0);

    md3dImmediateContext->RSSetState(nullptr);
    md3dImmediateContext->OMSetBlendState(0, nullptr, 0xffffffff);
    md3dImmediateContext->OMSetDepthStencilState(nullptr, 0);

}

Thank you for reading this post.

c++
direct3d
depth
asked on Stack Overflow Oct 5, 2019 by ghoflvhxj • edited Oct 5, 2019 by AbdelAziz AbdelLatef

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0