I have some complex mesh which have almost overlapping polygons near the eye and hair.
With the camera at a far distance I get z-fighting.
I noticed that I move the near clip plane from 0.1 to something like 0.6 the z-fighting disappear, which is to be expected.
But why if I change the far clipping plane from 1000, to 100.000 nothing changes?
Is the 0.5 difference in the near plane resulting in a greater rendered area than the 90.000 difference in the far plane?!
https://en.wikipedia.org/wiki/Z-buffering
Short answer for this question is: Yes it does. Closest area to far plane => worst z resolution you get there.
You can try setup with 2 cameras: one draws first your far plane, then another one draws close plane (near - far: 0.1 - 10.0; 10.0 - 1000.0). This will technically increase z-buffer by rendering more stuff (usually more overdraw).
IIRC, z buffer does not store “depth” in linear fashion. Meaning that objects that are close to you have higher zbuffer precision than objects that are far away from you. I don’t remember exact formula (you can look it up on wikipediahttps://en.wikipedia.org/wiki/Z-buffering ), but it involves dividing by Z coordinate. That’s why you have zfighting far away, but not close and that’s why shifting distance by 0.5 has large impact - google “1/x graph”. Z buffer has similar distribution of depth values.
Several years ago, there was alternative technique called w-buffer, which resulted in less artifacts, but afaik right now it is no longer used by pretty much anybody and it is safe to assume that it is not supported by your hardware. In fact, I haven’t heard of anyone even mentioning w-buffer for 10 years.
Right now you can request 24bit zbuffer format (don’t remember how it is done in unity) and see if it works well enough.
Thanks guys.
I don’t need to fix it, as my camera system can handle changing the clipping planes dynamically when needed and a short near clip plane when looking from afar is not needed.
I was just curious why this was happening, so that I know what kind of situation to avoid in the future.
Yeah, the basic rule of thumb is to keep your clip planes as near to the thing you’re looking at as possible. The concept Qwerty mentioned of having multiple cameras to help with this is (I think) a semi-common approach. Your “near” camera can have a fairly high degree of precision, and your “far” camera, used for backdrops and such, can have both a super long view distance and a near-clip distance that’s pushed out a long way to help.