Z-Fighting with water

Started by
4 comments, last by Plerion 11 years, 3 months ago

Hello everybody

Today when i was extending my procedural terrain engine i added water. I dont need big effects with the water so its just a blue plane at water level and some coloring according to its depth. But i have seen a problem when the shore is pretty plain which makes the water and the terrain be nearly coplanar. Expectingly this gives z-fighting and over all looks edgy.

Here is an image showing the effect:

50e05b588ff1c6_IMG_30122012_141549.png

In the internet ive seen the hint that i should use different z-planes for the two objects. So i decided to move the far plane away for the water so that it is nearer (relative) to the camera. That resulted in odd behavior. The water moved up and down with the camera. Next i tried to add a z-offset after the transformation in the shader. With that the water just intersected earlier with the terrain but the border stayed the same.

What techniques are there to avoid that kind of distortion at the edge?

Greetings

Plerion

Advertisement
I guess most of the solutions you're likely to come across are intended to solve different problems. When you have one surface roughly coplanar to another surface but you want one surface always on top (typically decals or shadows), then that is when to use z bias, z offsets or modified projection matrices, etc.

For you, the situation is different, you want your water plane to intersect your land geometry, just with a bit more precision. I can think of a couple of things you could try:

1. You might be able to modify your projection matrix near and far planes to increase your effective Z-resolution. Moving the near plane forward can be particularly effective, especially if it's currently very close to zero.
2. Could you modify your land geometry/height map so that it doesn't end up near zero for too long? e.g. If (vert.y > 0.0f) vert.y += 0.1f else vert.y -= 0.1f
3. You could try a user clip plane when you render your land geometry instead of using the z-buffer. Not sure if that'd give you more precision or not, tbh, but maybe worth a try if you're running out of ideas.

Does the water have to consist of its own geometry? Perhaps you can multi-texture and mask it directly into the ground plane?

What if you just fade the water out when the geom' Z value is close to the water's Z?

Also look into depth bias and slope depth bias

Hey everyone

Thanks for the tips. Im sure with one or more of them ill be able to solve my issues. It obviously already looks way better if the shore is less plain, now i just have to change my terrain generator so that it takes the slope into account if it gets near the water level of the tile.

Plerion

This topic is closed to new replies.

Advertisement