Infinite far clip plane distance

Hi, is that possible to have an infinite far clip plane distance or something close to infinite without losing details?

Not really, the depth buffer encode distance from near to far using 32bit data, you can cheat a bit with logarithmic depth buffer by distributing the precision differently, but ultimately, you have to fit within that. You can also cheat by stacking cameras, ie each camera render a non overlapping range.

The far clip has little to do with the overall precision of the depth buffer, at least for a perspective camera. That’s much more a factor of the near depth. A lot of game engines that aren’t Unity already use an infinite far plane by default because it doesn’t really affect the usable depth precision that much. Indeed a near clip of 0.5 and a far clip of infinity has a better usable depth range than a near clip of 0.000001 and a near clip of 1000.

Also Unity’s use of an reversed depth buffer on anything not OpenGL means the depth precision already very closely matches the ideal logarithmic, which solves a lot of the problems that Unity 4.0 and early versions of Unity 5 had, especially since on almost all platforms that use OpenGL you can now use Vulkan or Metal and get the benefit of the reversed depth buffer.

The only place you’re still stuck is on OpenGLES 2.0 devices, since the reversed depth buffer trick doesn’t work with OpenGL due to how it’s projection matrices work compared to literally all other graphics APIs. (OpenGL was basically the first, and everyone quickly realized it was wrong and didn’t follow its example).

The biggest problem with the infinite far clip plane is that Unity’s c# code seems to have a problem with using infinite far planes. In fact if you try to set one on a camera the editor or game will crash. I think you can set a custom projection matrix with an infinite far plane if you construct the matrix yourself, but this might still crash the engine, I haven’t tried. So you can’t have a truly infinite far plane. You can set it to a really, really large number though. Too large and Unity will crash again though, so you’ll have to play with it some. A few hundred million should be fine, it seemed like getting into the many billions trillions probably gets too close to infinity.

2 Likes

This is a really interesting topic, I was considering to use stacked cameras with different clipping planes for each camera in order to render up to 10k away. Although it sounds like maybe thats not necessary at all, that I can safely just increase the far plane.

Has anyone else been exploring this in the newer versions of Unity?