I have downloaded completely different samples with water effects (in XNA) and I've noticed that they all exhibit a common problem: when the camera direction (only the direction, not the position) moves, a noticable and annoying flicker occurs where the water meets terrain. I'm curios to find out more about this. Why does it happen? Does it have a name? And what can I do about it?
-
\$\begingroup\$ Wild guess: maybe your near plane is too close to the camera. This limits the effective resolution of the Z buffer. \$\endgroup\$– JimmyFeb 10, 2012 at 14:01
-
\$\begingroup\$ Could you link to one of these samples? \$\endgroup\$– David GouveiaFeb 10, 2012 at 14:19
3 Answers
It's named Z-fighting. You can google a lot information about it. For example here on wiki. In short: your water and terrain plane are in the same distance from camera (they are coplanar). If you move your camera (direction), float results differ a bit, so sometimes (I mean: some pixels) it chooses water to be drawn, sometimes it chooses terrain.
And you can solve this problem easily - just move your water plane a bit above or under the terrain, if they have the same "height" (they are coplanar).
-
\$\begingroup\$ But the terrain and the water are not "particulary" coplanar. I've tried to put spheres in the water with 1/4 of them abouve the water and got the same effect too? Althogh I may really be plain z-fighting I'm seeing (which I do know about) - I have no clue on how to fix tihs (and neither have the authors of those effects I've tried, I gusee. Or it doesn't bother them...) \$\endgroup\$ Feb 10, 2012 at 13:43
-
1\$\begingroup\$ The above guess is probably the best one given the details we have. We need a picture or video \$\endgroup\$– brandonFeb 10, 2012 at 14:22
-
\$\begingroup\$ No. It is not Z-fighting. If it were Z-fighting I would see it on pixel level. But the effect I asked about (and see in several samples) seems rether to happen on a vertex level. Once I figured out how to do recording I'll be back! \$\endgroup\$ Feb 11, 2012 at 20:47
-
\$\begingroup\$ You can use this online service for recording apps or desktop: screenr.com \$\endgroup\$ Feb 12, 2012 at 8:11
It is floating-point prcision error, you can fix that by not changing view matrix, if it has change only for little, if X or Y mouse rotation is less then 0.1 then use old view.
This problem can also be solved by using a logrithmic z-buffer which can be done in your shader, and is very very easy to implement.
-
2\$\begingroup\$ More details would make this a better answer. \$\endgroup\$– HouseApr 8, 2012 at 15:28