- Home /
largest reasonable camera view distance?
What is the largest far clip plane that could be feasable for a game, prior to getting some kinds of bugs with camea view? i.e. a giant spacecraft on long distance terrain, 28 000 view distance is too much?
Answer by Eric5h5 · Jul 24, 2014 at 02:42 AM
It depends on what you're doing exactly, but normally 28K is way too large and can result in zbuffer precision issues. Typically 1-2K is the most you'd want to use. You can use techniques such as more than one camera to deal with long view distances.
Thanks. You would change between a long range and a short range camera depending on view distance? Is that equivalent to changing the clip plane variable on the camera?
It sounds as if the screen could be devided into squares, and distance within the squares could be checked so that each one is rendered with a camera of the corresponding clip plane? :)
I know this has been a while (over 2 years), but as one of the first result on Google where searching for long range view in Unity, I think an answer should be given here.
There's 2 "layers" to consider to build a long-range view system in Unity.
The first layer is whenever an object is close enough to be seen and interacted in the view. This is controlled with the LOD system and doesn't requires much scripting if any depending on what you wish to do. There's the documentation (well, the beginning of it) : https://docs.unity3d.com/$$anonymous$$anual/LevelOfDetail.html
The second layer is more complex as its used to overcome what Eric5h5 explained which is Zbuffer precision issues (or also known as float precision issues) as positions are calculated via floats which are always 32bits values and, in computing, 32bits values equals up to 7 digits (regardless of the decimal position) so between either 9999999 and 0,000001.
Floats precision issues is related to the ability for a computer algorithm to not double check the last 2 or 3 last digits of a 32 bits data when it's set as not important. This means that if you use a float that is 9999999, the computer can interpret it as anything between 9999999 and 9999900 (and, if the memory is lacking which is not rare during memory spikes in video games, even down to 99999000!) If you ever wondered why the position or rotation of an object in unity seems to not be a perfect number like if you put 5 and it always become 4.999472... that's an example and it's can be avoided by switching the value to a pure number unrelated to both the imprecise and wanted result (so switching to 8, then 5 will reset the imprecision).
But, as you might have guessed, doing this in UI and in scripts is different.
So, the trick in video games to allow displaying huge worlds is to create and display 2x the same worlds at different sizes and rendering them both at the same time in the right order.
So, in other words, you got 1 HUGE detailed world that is only rendered at up to 1-2k in distance. Then again, if you wish to avoid precision issues with the positioning, you would have to consider the concept of zeroing the camera's target position (or the ship/whatever the camera is looking at) so... ins$$anonymous$$d of moving the ship/character inside an "universe", you're moving the universe around the object that is focused on by the camera. Then you use a 2nd camera with a different movement speed that only see long range low level stuff (like planets, suns, etc.) and not the close stuff.
You make sure both camera are in the right order of rendering : Render the fake long range camera first, then the high detailed short range camera over with Only Depth activated (and no skybox on the short range one). If you set the things right, it will display long and short range stuff correctly.