Skip to main content
GameDev.net gamedev.net
🔒 Locked

32-bit Depth Buffer?

Started by StephenTC Aug 6, 2007 at 9:09 AM 10 replies 7.1k views
Original Post
StephenTC
StephenTC
Hey everyone, So I'm curious... Is it possible to create a D3DFMT_D32 depth-stencil buffer? The most I've ever seen done is D3DFMT_D24S8 or D3DFMT_D24X8 (think it's x) and then D3DFMT_D16. What has to be present for 32-bit depth buffers to work? I'm trying to implement it over-top a system that was using D3DFMT_D24S8 (and drop the stencil buffer) but it doesn't seem to be valid when I call the CheckDepthStencil function. Thanks everyone! Stephen Timothy Cooney
Evil Steve
Evil Steve
Quote:
Original post by StephenTC
So I'm curious... Is it possible to create a D3DFMT_D32 depth-stencil buffer? The most I've ever seen done is D3DFMT_D24S8 or D3DFMT_D24X8 (think it's x) and then D3DFMT_D16. What has to be present for 32-bit depth buffers to work? I'm trying to implement it over-top a system that was using D3DFMT_D24S8 (and drop the stencil buffer) but it doesn't seem to be valid when I call the CheckDepthStencil function.
D3DFMT_D32 is a 32-bit depth buffer, with 0 stencil bits. D3DFMT_D24S8 is 24-bits depth, 8-bits stencil, and D3DFMT_D24X8 is 24-bit depth buffer, with 8 bits unused.

Your card has to suppotr whatever format you're trying to use, and it also has to support that format in conjunction with your backbuffer. Last time I looked, a lot of cards don't support 32-bit depth buffers, since 24-bit is usually enough, and you can't have a stencil buffer with that.

EDIT: Looking at the caps spreadsheet that comes with the SDK (Microsoft DirectX SDK\Samples\C++\Direct3D\ConfigSystem\CardCaps.pdf), no recent hardware at all supports 32-bit depth buffers.
StephenTC
StephenTC
Unfortunately for us, 24 bit isn't enough :p, large area to render. I have a NVidia 7950 which is right before the 8 series so I'm assuming that it should work. I'm thinking that maybe the actual display-mode I'm choosing earlier on is messing making the D32 incompatible. Can anyone provide insight as to what might make the D32 format incompatible?
StephenTC
StephenTC
Wow, thanks Evil. I opened up that PDF and I think my head exploded :p. That was exactly what I was looking for though. Does anyone know where I can find a more in depth Card Capabilities pdf somewhere? I could really use something like this for a few other things I'm working on. (I might just post this in a new thread).
Evil Steve
Evil Steve
Quote:
Original post by StephenTC
Unfortunately for us, 24 bit isn't enough :p, large area to render.
There's various tricks to get around this, such as changing the near and far clip planes between rendering objects.

What exactly are you rendering that requires more than 24 bits of depth buffer? It's likely that 32 bits isn't going to be enough either, because of the way the depth buffer is made up; depth values aren't uniform, there's something like "the first 90% of the depth value ranges constitute the first 10% of the distance between the near and far clip planes".
Gagyi
Gagyi
Getting device capabilities is hard... Most of the drivers lie about the capabilities...
Actually, I don't use stencil, and I'm not oging to, so i try to make a D3DFMT_D32 z-buffered device. If I cant, I try to make a D3DFMT_D24X8 or a D3DFMT_D16. That way, i have the biggest zbuffer i can have.

And about the distances... You have to push the near plane as far as you can! If you push it twice as far, you will get twice the resolution on far objects. (so dont place it to 1 cm far, but to 10 cm far or further)
-----------------------------------"After you finish the first 90% of a project, you have to finish the other 90%." - Michael Abrashstickman.hu <=my game (please tell me your opinion about it)
StephenTC
StephenTC
Unfortunately, we can't push our Z-buffer any further. It's already pretty tight :p. We are rendering a HUGE (6 kilometers one side) map.

Thanks for the information though,
Stephen Timothy Cooney
Krohm
Krohm
Quote:
Original post by Gagyi
And about the distances... You have to push the near plane as far as you can! If you push it twice as far, you will get twice the resolution on far objects. (so dont place it to 1 cm far, but to 10 cm far or further)

Quote:
Original post by Gagyi
Unfortunately, we can't push our Z-buffer any further. It's already pretty tight :p. We are rendering a HUGE (6 kilometers one side) map.
I want to bonk again on Gagyi' suggestion.
Pushing far the znear plane is the way to go.
Consider most people will tend to have their heads AT LEAST half a meter from any object. The eye-nose distance is already a few centimenters so make sure you don't set you znear in the millimeters range.
Previously "Krohm"
Promit
Promit
The basic thing you want to do is push your near plane out. The depth resolution is controlled by the far/near ratio (or the logarithm of it or something like that).

Alternately, linearized depth may be an appropriate solution for what you're trying to do. The depth buffer is typically high precision close to you and lower precision as distance increases. Linear Z changes this so that the precision is even throughout the range. With some tweaking, this can work out a whole lot better than the usual Z setup.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Adam_42
Adam_42
If the linear depth isn't going to work then you need to change the near and far z during rendering, and render the scene repeatedly.

The way to do this is really quite simple, all you need to decide is your starting zFar, and your maximum zFar / zNear ratio:

0. Clear screen (or draw skybox).
1. Set zFar to the maximum you need
2. Set zNear = zFar / ratio
3. Clear z-buffer
4. Render scene (culling to that adjusted frustum).
5. Set zFar = zNear
6. If zNear isn't close enough yet go back to step 2

I'd think that in most cases you'll find that two passes round the loop are enough, but you can get as much resolution as you need using that method, even with a 16-bit z-buffer.
ET3D
ET3D
Quote:
Original post by StephenTC
Unfortunately, we can't push our Z-buffer any further. It's already pretty tight :p. We are rendering a HUGE (6 kilometers one side) map.

The way I see it, if you're rendering a terrain far into the distance, you will want to use an LOD system for performance, and that is likely to reduce Z fighting in the distance.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.