Jump to content

  • Log In with Google      Sign In   
  • Create Account


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.

  • You cannot reply to this topic
5 replies to this topic

#1 Plerion   Members   -  Reputation: 364

Like
0Likes
Like

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:

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



Sponsor:

#2 C0lumbo   Crossbones+   -  Reputation: 2162

Like
4Likes
Like

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.


#3 eppo   Crossbones+   -  Reputation: 2341

Like
5Likes
Like

Posted 30 December 2012 - 01:58 PM

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



#4 hunpro   Members   -  Reputation: 807

Like
3Likes
Like

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?

#5 Matias Goldberg   Crossbones+   -  Reputation: 3056

Like
2Likes
Like

Posted 30 December 2012 - 06:31 PM

Also look into depth bias and slope depth bias



#6 Plerion   Members   -  Reputation: 364

Like
0Likes
Like

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.



PARTNERS