Jump to content
  • Advertisement
Sign in to follow this  
Arkanoid

Bad mesh intersections.

This topic is 2374 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
I need to change D3DFMT_D16? when i change it to D3DFMT_D32 - program doesn't work.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!