[DX11] Depth Bug

Started by
2 comments, last by ArthurD 12 years, 6 months ago
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;



Thanks for your time reading this, any help is welcome!
Advertisement
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.

- 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.

Not sure about your other problem. Rather sounds like a bug in your camera/view logic.
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.

This topic is closed to new replies.

Advertisement