Sign in to follow this  
Followers 0
Plerion

Z-Fighting with water

5 posts in this topic

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

0

Share this post


Link to post
Share on other sites
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
4

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0