Jump to content
  • Advertisement
Sign in to follow this  
mind in a box

DX11 [DX11] Depth-issue for near objects

This topic is 2999 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


I am implementing the LightPrePass at the moment into my engine, and now I have problems with rendering close geometry.
Here is a picture which shows the problem, and I think it has something to do with the depth.

Here are the DepthStencil-States I create:


// Depth test parameters
dsDesc.DepthEnable = true;
dsDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
dsDesc.DepthFunc = D3D11_COMPARISON_LESS;

// Stencil test parameters
dsDesc.StencilEnable = true;
dsDesc.StencilReadMask = 0xFF;
dsDesc.StencilWriteMask = 0xFF;

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

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

// Create depth stencil state
DXUTGetD3D11Device()->CreateDepthStencilState(&dsDesc, &LPP_DepthStencilState);

dsDesc.DepthFunc = D3D11_COMPARISON_EQUAL;
dsDesc.StencilEnable = false;

// Create depth stencil state
DXUTGetD3D11Device()->CreateDepthStencilState(&dsDesc, &Scene_DepthState);

This is how I render them:

DXUTGetD3D11DeviceContext()->OMSetDepthStencilState(LPP_DepthStencilState, 0);

RenderWorld(LPP_DepthStencilState); //Render world
TheScene->Params.SceneInfo.bFirstLightPrePass=false; //Back to normal again

//Render everything which wants to be lighting

DXUTGetD3D11DeviceContext()->OMSetDepthStencilState(Scene_DepthState, 0);
RenderWorld(Scene_DepthState); //Render world

The format is DXGI_FORMAT_R32_TYPELESS for the texture, DXGI_FORMAT_D32_FLOAT for the DepthStencilView and DXGI_FORMAT_R32_FLOAT for the ShaderResourceView.

I haven't got such issues before, so I hope I just missed a little thing.

Share this post

Link to post
Share on other sites
It looks like you incorrectly set the near and far plane. Try setting the near distance to nothing lower then .1 and set the far to a reasonable number nothing massive.

When you have a giant frustum with a near of like . 0001 up to 1000000 it really takes the precision out of depth testing.

Share this post

Link to post
Share on other sites
When I set it from 1 to 1000 nothing changes...

Edit: One wired thing: The normals of the mesh seem to cause it. Sometimes the walls are unaffected, while the ground right under it are distorted.

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!