[D3D11] Depth buffer does nothing

Started by
30 comments, last by 360GAMZ 12 years, 4 months ago
I just tried PIX, and I noticed that my whole depth buffer seems to get cleared to black, not white as I specified.
After rendering, the geometry shows up in white, even if it is VERY near at the camera.

Where do I check if the correct states are bound?

[edit]: I tried to debug one of the pixels of the rendertarget in PIX.
There were many pixels which said "This pixel was eliminated because: It failed the depth test.". So it could test against the depth in some way... But then in a wrong one!
Advertisement
I don't know if you've made the suggested changes and then switched back if it didn't work, but I would keep everything as basic and standard as possible (just until you find the culprit)

1) comment the DepthStencilState desc out
2) d3dDevice->OMSetDepthStencilState( 0, 0 );
3) Not entirely sure what you mean when you say that you have the other viewports disabled (at runtime?) but I would hardcode it so that it only creates one and move

DXUTGetD3D11DeviceContext()->OMSetRenderTargets(1, &RenderTargetView, DepthBuffer->GetDepthStencilView());

to initialization

keep the changes I suggested earlier :
4) pass DXGI_FORMAT_D24_UNORM_S8_UINT as format
5) specify NULL for the second param in CreateDepthStencilView()
6)

Move

DXUTGetD3D11DeviceContext()->ClearDepthStencilView(DepthBuffer->GetDepthStencilView(), D3D11_CLEAR_DEPTH, 1, 0);

so that it is called AFTER

DXUTGetD3D11DeviceContext()->OMSetRenderTargets(1, &RenderTargetView, DepthBuffer->GetDepthStencilView());
DXUTGetD3D11DeviceContext()->OMSetDepthStencilState(DefaultDepthStencilState, 0);
Psst-- did you make sure your depth culling operation (i.e. LESS_EQUAL, GREATER_EQUAL, etc.) is set the right way? If your depth values are reversed, you should just be able to flop the culling direction and it should work normally :)

I ask as the ordering appears pretty consistent-- it's always the farthest object drawn.

EDIT: And, if you're working with a floating-point depth buffer, reversing the depth range/comparison tests can improve overall depth precision anyways, canceling out some aspects of floating-point error due to nonlinear number line whatchamacallit. There's a formal term, but sadly it escapes me at the moment.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.
Back on this. It still isn't working. I'm completely annoyed of depth buffers right now. I almost stopped developing my engine because of this and other problems which stand in my way of doing something else.

16bit_port, I've done everything like you suggested, no change of things.
I even recoded this from scratch, no change.

InvalidPointer: I swap it, the screen gets black. I also swapped the value I clear the buffer with, still black.
If I decrease the clear-value by some specific amount, the screen gets black.

PIX shows everything in pure white color in the depth buffer, no black/gray for near objects.

The debug runtime does say nothing.



This is just the zbuffer. Why can't I get it to work?
Please, someone must have another idea ...
try setting your max depth to one


D3D11_VIEWPORT vp;
vp.MinDepth=0;
vp.MaxDepth=0; <---------
vp.TopLeftX=0;
vp.TopLeftY=0;
vp.Width=SwapChainDesc.BufferDesc.Width;
vp.Height=SwapChainDesc.BufferDesc.Height;

Wisdom is knowing when to shut up, so try it.
--Game Development http://nolimitsdesigns.com: Reliable UDP library, Threading library, Math Library, UI Library. Take a look, its all free.
Quote:
vp.MaxDepth=0; <---------


HOLY CRAP...
Oh my God.. I cannot stop laughing at the picture. It perfectly captures what I can only assume you must be feeling right now and the countless similar situations that I've been through.

I was waiting for your reaction towards the solution and boy, you did NOT disappoint. lol

[Edited by - 16bit_port on October 7, 2010 5:53:38 PM]
Yeah, now I don't know what to post. [smile] I was pretty much like this, indeed. (Had a bad day anyways.)
:)
Wisdom is knowing when to shut up, so try it.
--Game Development http://nolimitsdesigns.com: Reliable UDP library, Threading library, Math Library, UI Library. Take a look, its all free.

This topic is closed to new replies.

Advertisement