|
||||||||||||||||||
Add Forum to Favorites | Send Topic To a Friend | View Forum FAQ | Track this topic |
Last Thread Next Thread ![]() |
| Proper use of Z buffering |
|
![]() vmware Member since: 3/31/2009 |
||||
|
|
||||
| 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. |
||||
|
||||
![]() Evil Steve Moderator Member since: 6/30/2003 From: Edinburgh, United Kingdom |
||||
|
|
||||
| 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. Steve Macpherson DirectX MVP and Programmer, Firebrand Games |
||||
|
||||
![]() vmware Member since: 3/31/2009 |
||||
|
|
||||
Quote: 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.) |
||||
|
||||
![]() Evil Steve Moderator Member since: 6/30/2003 From: Edinburgh, United Kingdom |
||||
|
|
||||
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. It sounds to me like your card doesn't support 16-bit depth buffers, either at all, or in the current gfx mode. |
||||
|
||||
![]() vmware Member since: 3/31/2009 |
||||
|
|
||||
| In the tutorial you mentioned there is one variable I could not recreate. mode.Format has to be supplied for multiple functions, but I could not get mode. Does it have reference to whether I am in windowed or fullscreen mode? |
||||
|
||||
![]() vmware Member since: 3/31/2009 |
||||
|
|
||||
| Sorry, I have found it in the 1st tutorial. D3DDISPLAYMODE mode; g_pD3D ->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &mode); |
||||
|
||||
![]() vmware Member since: 3/31/2009 |
||||
|
|
||||
| But I still don't understand where fmtBackbuffer comes from. hResult = g_pD3D->CheckDepthStencilMatch(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, mode.Format, fmtBackbuffer, fmtDepths[i]); I have also tried to set that to mode.Format and [i]fmtDepths. None of them worked. |
||||
|
||||
![]() Evil Steve Moderator Member since: 6/30/2003 From: Edinburgh, United Kingdom |
||||
|
|
||||
Quote:fmtBackbuffer is just mode.Format: // Grab the current desktop format D3DFORMAT 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; |
||||
|
||||
![]() vmware Member since: 3/31/2009 |
||||
|
|
||||
| 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. |
||||
|
||||
![]() Evil Steve Moderator Member since: 6/30/2003 From: Edinburgh, United Kingdom |
||||
|
|
||||
Quote:What value are you using for BackBufferFormat? |
||||
|
||||
![]() vmware Member since: 3/31/2009 |
||||
|
|
||||
| I am using D3DFMT_D24X8 for both places. |
||||
|
||||
![]() Evil Steve Moderator Member since: 6/30/2003 From: Edinburgh, United Kingdom |
||||
|
|
||||
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. |
||||
|
||||
All times are ET (US)![]() |
Last Thread Next Thread ![]() |
|