7
\$\begingroup\$

In Kerbal Space Program, a space exploration game made with Unity, Floating origin technique is used to overcome the floating point precision issues. While in map view, the world (a scaled space with miniature celestial bodies) is recentered around the camera every frame so glitches don't occur when viewing unsafely distant planets. But when such planets are observed from an 'unsafe distance' (more than 10 000 units in scaled space), they're still rendered normally. Why don't floating point issues occur?

\$\endgroup\$
6
  • 4
    \$\begingroup\$ I think pictures would help explain the question, I also have a problem that this question assumes a lot of things.. \$\endgroup\$
    – concept3d
    Commented Nov 8, 2015 at 16:25
  • \$\begingroup\$ 10km is only a "large" number if the units being used are meters or smaller. The celestial map could be rendered in a scale of km, 100m, 10m, etc. \$\endgroup\$ Commented Nov 8, 2015 at 17:15
  • 2
    \$\begingroup\$ I don't understand your question. In Kerbal Space Program, the floating origin trick is used precisely to assure that visible bodies are within what you call the safe distance - in a way that only bodies that ceased to be visible are left in the so called unsafe distance. \$\endgroup\$
    – MAnd
    Commented Nov 9, 2015 at 3:07
  • 1
    \$\begingroup\$ @MAnd Originally the camera is near the home planet in map mode. Other parts of the solar system are further away from the camera than the safe distance but are still visible. The Sun, for example, is ~2 200 000 units away even in scaled space, but is still rendered nicely. \$\endgroup\$ Commented Nov 9, 2015 at 10:45
  • 1
    \$\begingroup\$ They're rendered nicely because the shader finally transforms the point in clip space, whose range extends from (-1, -1) to (1, 1). The local space vertex is first transformed into world space, then viewport space and finally screen space (or clip space). And plus the max value of a float (in C# at least) is 3.402823e38 which is quite a lot. \$\endgroup\$
    – EvilTak
    Commented Nov 9, 2015 at 13:09

1 Answer 1

2
\$\begingroup\$

I'm fairly sure floating point rounding errors don't mean that an object will be absolutely rendered incorrectly when far away.

It just means that the probability of the sun being exactly where it is supposed to be is smaller the farther away from the origin it is.

However, you might not be able to notice if the sun is at the wrong place with an error of 10 km for instance. Since the sun jumping between 10 km is hardly noticeable from earth. It wouldn't even move a single pixel.

You also have to take into account that Kerbal uses many cameras to render a single scene. Three, if I remember correctly. One for the cockpit or ship, one for the landscape, and one for celestial objects. These cameras have individual near/far rendering planes.

I hope this answers your question.

This video goes into greater detail: https://youtu.be/mXTxQko-JH0?t=399

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .