Bad mesh intersections.

Started by
7 comments, last by TomKQT 12 years, 1 month ago
how to make mesh intersections more smoothly?
94c9589ff690.png
Advertisement
do you mean to render those two objects beside each other w/o any gap? you should do that in 3ds max instead instead, rather than manually modifying the world matrix for individual subsets
Yes in this situation i can do it in 3ds Max, but - in scene will be more polygons. And if for example i have hero, i and it will can go into the water, i cannot do this in 3ds Max....so i need to know how to do it in code for all objects that i'll use.
That problem is known as "Z fighting"; it's caused by the z-buffer (depth buffer) not being precise enough to tell which of the two surfaces is in front.

As above, it's often best to fix the geometry so that this doesn't happen. You can also take measures to increase your depth-buffer precision, such as increasing your 'near plane' value.
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
I need to change D3DFMT_D16? when i change it to D3DFMT_D32 - program doesn't work.
try this instead:

D3DPRESENT_PARAMETERS oD3DPresentParameters = {0};
oD3DPresentParameters.BackBufferWidth = g_pMainFrame->getWindowWidth(); // Width of the back buffer
oD3DPresentParameters.BackBufferHeight = g_pMainFrame->getWindowHeight(); // Height of the back buffer
oD3DPresentParameters.BackBufferFormat = D3DFMT_A8R8G8B8; // Back buffer format
oD3DPresentParameters.Windowed = TRUE; // Windowed
oD3DPresentParameters.hDeviceWindow = g_pMainFrame->getWindowHandle(); // Handle to the main window
oD3DPresentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD; // Swap effect
oD3DPresentParameters.MultiSampleType = D3DMULTISAMPLE_NONMASKABLE; // Multisample type
oD3DPresentParameters.MultiSampleQuality = 1; // Multisample quality level
oD3DPresentParameters.BackBufferCount = 1; // No. of back buffers to use
oD3DPresentParameters.EnableAutoDepthStencil = TRUE; // Auto depth-stencil
oD3DPresentParameters.AutoDepthStencilFormat = D3DFMT_D24S8; // Auto depth-stencil format
and when clearing the back buffer you should clear depth buffer too:

// Clear the surfaces
m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, 0x0, 1.0f, 0);
Yes it works, thanks very much for help smile.png

d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
I need to change D3DFMT_D16? when i change it to D3DFMT_D32 - program doesn't work.


16bit depth buffer isn't really great, but as you noticed, D3DFMT_D32t isn't supported by all graphics adapters. D3DFMT_D24S8 (with stencil buffer) or D3DFMT_D24X8 (without stencil buffer) are very compatible and the depth buffer is 24bit.

But using better depth buffer isn't the only solution. You should be also careful with your projection matrix. You are probably using D3DXMatrixPerspectiveFovLH to create your projection matrix, am I right?
Many people simply set the last two parameters (z_near and z_far) to some "safe" values to be sure everything is visible for the camera, so near to very low value (like 0.0001f) and far to very large value (like 10000.0f). But this can cause z-fighting problems even with a large depth buffer, because those 24bits will be used in the whole range 0.0001f to 10000.0f.
The rule is to set the near value as BIG as possible and the far value as SMALL as possible. The exact numbers depend on the scale of your scene.

This topic is closed to new replies.

Advertisement