# DX11 [DX11] Depth Bug

This topic is 2940 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello,

I have a bug in the depth of my program that causes a very weird looking glitch.

I made a video of the problem here :

Note that in this video, the model is simply rotating clockwise. However, because the depth is "inverted", it seems to change its rotation a few times.

[media]
[/media]

There are 2 bugs, but I think they are linked to each other :

- The part of the model that is displayed is not the closest one, but the one that is the farthest away instead.
- The model gets bigger as it gets away from the camera instead of becoming smaller.

If I invert the depth DepthFunc, the first problem is solved and it is always the closest polygons that are displayed, but the second problem is still present which makes me think that I didn't solve the bug, just worked around.

The problem is that I do not know exactly where to look for the problem, so I don't know exactly what part of the code to show you.

I thought that I had failed my projection Matrix, but I don't see anything wrong with it :

 const float SCREEN_DEPTH = 100000.0f; const float SCREEN_NEAR = 0.1f; fieldOfView = (float)D3DX_PI / 4.0f; screenAspect = (float)screenWidth / (float)screenHeight; D3DXMatrixPerspectiveFovLH(&m_projectionMatrix, fieldOfView, screenAspect, SCREEN_NEAR , SCREEN_DEPTH );

And here is the depth description :

 depthStencilDesc.DepthEnable = true; depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS; 

##### Share on other sites
Your near and far planes are probably too far to have adequate precision in the depth buffer. Try bringing your far plane back to 1000 or so.

##### Share on other sites

- The part of the model that is displayed is not the closest one, but the one that is the farthest away instead.

Looks like the cull mode is wrong. Try to invert it.

##### Share on other sites
Thanks unbird! I didn't quite catch that the cull mode was the cause of this bug, it solved it all. Thanks a lot!

And thank you MJP, I had not thought of the problems my far plane could create, I changed it to a more reasonable value.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 9
• 11
• 15
• 21
• 26