[C++, DX9] Strange Z fighting

Started by
7 comments, last by Ripiz 13 years, 8 months ago
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.
Advertisement
What format is your z-buffer, and what are your near and far clip planes set to in your projection matrix?
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);
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.
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?
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.
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.
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
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.

This topic is closed to new replies.

Advertisement