- Home /
Problem with simple water over terrain
Starting with a terrain I've created via an imported heightmap, I'm trying to fill in the ocean areas using simple water (as per Unity documentation). However when I add simple water to the scene, I can see the underlying terrain flash through the simple water as I move the camera around. It's worse when I move the camera at some angles, and better with other angles.
How far is the "underlying terring" from the water surface. You might be experiencing Z-fighting
What Ben said. Either raise the water or lower the ground and see if that helps. Also, a screenshot could help.
I understand what you all are saying about z-fighting and I think you're probably right. I'm starting with real geo data for my heightmap, and although I see a defined 'ridge' on the coastlines of my heightmap, it doesn't look very high. How much of a height difference between flat and where my terrain starts should I see after importing it to avoid z-fighting with water? Would a screenshot of my heightmap or the terrain in unity be more useful in diagnosing the issue?
@FramnkRulez any distance between water and ground of about .1 or more will prevent z-fighting. Gives us a pic of the problem please.
@ampoterik That's not entirely correct. The depth buffer is exponential, meaning that inaccuracy increases at range. If you want to go all out for the $$anonymous$$imum value to prevent z-fighting, you will need to calculate the accuracy of the z buffer at the maximum distance of objects.
For instance, a offset of 0.1 will not suffice at preventing z-fighting at a distance of 90000 units and a maximum view distance of 100000 units (over-estimated guess) ;)
Answer by Benproductions1 · Jul 18, 2013 at 04:21 AM
Hello,
I will try to explain why your problem happens before I give solutions.
(basically) Every rendering engine, determines which points on an object are closer to the camera by using the depth-buffer (or Z-buffer). This Z-buffer is per-pixel and a value between 0 and 1. 0 is for a point that lies on the near-clip plane of the camera, while 1 is on the far plane camera.
The Z-buffer does not scale linearly between the near and far clip planes.
It scales exponentially, meaning that the further away a rendered point is, the more inaccurate the Z-buffer becomes.
This means that at close distances, a point on your water may have a smaller Z-buffer value than the same point on your terrain, however as you move the camera away, these values become the same, because of the previously mentioned inaccuracy. In cases where two objects, at points have the same depth-buffer value you get the Z-fighting (depth-fighting) effect.
The only way to fix this, is to either increase the distance between the two objects, or change the accuracy of the depth-buffer (by changing the near/far-clip planes).
Hope this helps,
Benproductiosn1
Your answer
![](https://koobas.hobune.stream/wayback/20220613110206im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Water4Simple & Water4Advanced internal LOD issue 1 Answer
How to make rain pools 3 Answers
Collision is glitchy 1 Answer