🔒 Locked
Proper use of Z buffering
Advertisement
Original Post
Hi, Is there anything special I have to take care of when doing Z buffering? First, I displayed one cube, and it appeared properly. But in case of a more composite shape, though the order of vertices are always proper, it occassionally happens that a set of vertices doesn't appear at all, not even if they are not hidden by any others. These are the related settings I have: BackBufferFormat = D3DFMT_UNKNOWN EnableAutoDepthStencil = TRUE AutoDepthStencilFormat = D3DFMT_D16 D3DRS_ZENABLE = TRUE Thanks.
16-bit Z buffers are very imprecise, and some graphics cards (Older NVidia ones) require that the backbuffer and depth buffer are the same format; that means you'll need to have a 16-bit backbuffer on some cards, which looks crappy. But mainly the precision is a big issue for 16-bit depth buffers; 32-bit or 24-bit are far preferable - 16-bit only gives you 65536 uniquer depth values.
Secondly, you need to make sure that your near and far clip planes are as close together as possible, and that your near clip plane is at a non-zero distance (And preferably as far as possible). 70% of the Z-range is used in the first 30% of the scene, since you're more likely to notice Z-artefacts close up than you are at a distance.
Secondly, you need to make sure that your near and far clip planes are as close together as possible, and that your near clip plane is at a non-zero distance (And preferably as far as possible). 70% of the Z-range is used in the first 30% of the scene, since you're more likely to notice Z-artefacts close up than you are at a distance.
Quote:
some graphics cards (Older NVidia ones) require that the backbuffer and depth buffer are the same format
If I set also the backbuffer format to D3DFMT_D16 then the application will exit with an exception.
(But I am still thinking about what you've written because I don't understand everything in practice.)
Quote:Sounds like you're not correctly checking for support of various formats. I've written A Tutorial which covers setting up a depth buffer correctly. You need to call CheckDeviceFormat and CheckDepthStencilMatch before you can attempt to create the device with a depth buffer, otherwise there's a reasonable chance it'll fail.
Original post by vmware
If I set also the backbuffer format to D3DFMT_D16 then the application will exit with an exception.
It sounds to me like your card doesn't support 16-bit depth buffers, either at all, or in the current gfx mode.
Quote:fmtBackbuffer is just mode.Format:
Original post by vmware
But I still don't understand where fmtBackbuffer comes from.
hResult = g_pD3D->CheckDepthStencilMatch(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, mode.Format, fmtBackbuffer, fmtDepths);
I have also tried to set that to mode.Format and fmtDepths.
None of them worked.
// Grab the current desktop formatD3DFORMAT fmtBackbuffer;D3DDISPLAYMODE mode;HRESULT hResult = m_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &mode);if(FAILED(hResult)){ m_strError = L"GetAdapterDisplayMode() failed. Error: " + Util::DXErrorToString(hResult); m_pD3D->Release(); m_pD3D = NULL; return false;}fmtBackbuffer = mode.Format;
This script finds that D3DFMT_D24X8 is the suggested format for me.
But after setting AutoDepthStencilFormat and BackBufferFormat my call to CreateDevice fails.
This is the way I do it:
g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice)))
The error message I get to the output is:
Invalid value for BackBufferFormat. ValidatePresentParameters fails.
But after setting AutoDepthStencilFormat and BackBufferFormat my call to CreateDevice fails.
This is the way I do it:
g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice)))
The error message I get to the output is:
Invalid value for BackBufferFormat. ValidatePresentParameters fails.
Quote:What value are you using for BackBufferFormat?
Original post by vmware
This script finds that D3DFMT_D24X8 is the suggested format for me.
But after setting AutoDepthStencilFormat and BackBufferFormat my call to CreateDevice fails.
This is the way I do it:
g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice)))
The error message I get to the output is:
Invalid value for BackBufferFormat. ValidatePresentParameters fails.
Quote:D3DFMT_D24X8 is a depth-buffer format, it's not usable as a backbuffer format. Try D3DFMT_X8R8G8B8 instead, or use the code from my tutorial.
Original post by vmware
I am using D3DFMT_D24X8 for both places.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement