• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Z-Fighting with water

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1Plerion  Members

Posted 30 December 2012 - 12:20 PM

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:

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

### #2C0lumbo  Members

Posted 30 December 2012 - 12:53 PM

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.

Edited by C0lumbo, 30 December 2012 - 12:54 PM.

### #3eppo  Members

Posted 30 December 2012 - 01:58 PM

POPULAR

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

### #4hunpro  Members

Posted 30 December 2012 - 02:34 PM

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

### #5Matias Goldberg  Members

Posted 30 December 2012 - 06:31 PM

Also look into depth bias and slope depth bias

### #6Plerion  Members

Posted 30 December 2012 - 06:36 PM

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

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.