Jump to content
  • Advertisement
Sign in to follow this  
Ripiz

[C++, DX9] Strange Z fighting

This topic is 2859 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

I've made simple water and noticed this problem only now. Don't know how to explain it so made little video: http://dl.dropbox.com/u/2637453/clip0007.avi
It's not very good quality but I hope it'll explain what's the problem.

Anyone know how to fix this? Terrain's neither water's height doesn't change, and this happens only when camera moves so I'm unsure why this happens.

Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
I think this is Z buffer format, not 100% sure.
dx_PresParams.AutoDepthStencilFormat = D3DFMT_D16;

Near place is 1, and far plane 100000. I guess too much?
D3DXMatrixPerspectiveFovLH(&m_Projection, D3DX_PI/4, (float)800/600, 1, 100000);

Share this post


Link to post
Share on other sites
Quote:
Original post by Ripiz
I think this is Z buffer format, not 100% sure.
dx_PresParams.AutoDepthStencilFormat = D3DFMT_D16;

Near place is 1, and far plane 100000. I guess too much?
D3DXMatrixPerspectiveFovLH(&m_Projection, D3DX_PI/4, (float)800/600, 1, 100000);
Definitely. For a 16-bit z-buffer, you'll want to use 1.0f and 1000.0f, and even that will probably have artifacts at high resolution.

I'd recommend going for D3DFMT_D24X8 or D3DFMT_D32 if it's supported, and bringing your far clip plane as close as you can - I wouldn't put it further than 10000.0f, even with a 24-bit or 32-bit z-buffer.

Share this post


Link to post
Share on other sites
With 1000 I can't see next building, my models are pretty big. Out of curiosity I tried 100 and bug persists. I guess problem somewhere else 0.o

Any idea what might cause this?

Share this post


Link to post
Share on other sites
1.0f - 100000.0f is definitely too high, but I don't think it's the cause of this problem. Instead of decreasing the value of zfar you could also increase the value of znear, this has the same effect (doubling znear has the same effect as halving zfar). But your bug doesn't look like z-fighting to me, if it was z-fighting you would get jagged edges. Not water that jumps up and down all the time. Maybe you're accidentally updating the camera position after you draw the terrain but before you draw the water, that would cause similar problems.

Share this post


Link to post
Share on other sites
No I call UpdateCamera() only then RenderScene(). Terrain has it's Matrix setup on program startup which I never change, and water is const array of 4 vertex to make quad. I set world matrix to identity before drawing water too.

Share this post


Link to post
Share on other sites
This could also be caused by precision problems in the transformation, but that only happens when the camera is very far away from the origin or when the models are extremely big (e.g. if you're using a single quad for the entire map and your map is really big). Try creating a smaller map (not just scaling, that doesn't work) or drawing a smaller quad of water to see whether this solves your problem.

If the camera is causing this, you should read this:
link

Share this post


Link to post
Share on other sites
Ahh thanks, making water smaller helped. Lowered x and y values by 10 times. Height of water was small (-6) so I didn't expect to have any problems, and made x/y large so it covers whole map, but seems it causes problems after all, will have to set matrix to players position now.

Thanks again.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!