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!