Wobbly Physics

Was gonna post this in the physics section but it’s a support forum so I thought this was more reasonable.

Inspired by this thread I actually played around a bit with the physics engine to see how rigidbodies behave at incredibly low y coordinates as they experience floating point accuracy degradation.

At y=-100,000 we see the lighting starts to have problems:

At -500,000 the cube mesh (collider and rendered) will start to jump around. Here we see it’s grown a little tumor on the top left, and the top right corner is starting to warp noticably:

At -5,000,000 our cube ceases to be a cube and the camera is having problems just with the skybox:

As it passes into -100,000,000, only one cube face renders at all:

We can turn it back into a 3d shape again by simply scaling the transform up to 10 units, but the renderer is still having serious problems:

At this point the rigidbody’s velocity is massive, but the cube wont move anymore. I’m guessing this is because the velocity, though large, is still less than the smallest increments between values as per the massive exponent scaling up the mantissa.

I assume it will never actually reach float.NegativeInfinity unless you set the velocity directly, because if the velocity is say, -10,000,000, accelerating by -1ms^-1 will still result in -10,000,000. So it’s not the position stopping it, it’s the velocity (which will never grow).

Anyway thought that was interesting so there you go :stuck_out_tongue_winking_eye:

3 Likes

Unity uses single precision physics engine. Because of this, recommended distance around origin (meanign coordinate range) is around ± 10 kilometers. Meaning ± 10000 units. Your exampel has 500000 units and 5000000 units. Of course it is going to have porblems.

Use origin shifting if you need those kind of coordinates.
–edit–

Also see this proof of concept example I wrote:

@neginfinity Oh I had no doubt it’d have problems, in fact I cringed as I did it. The point of it was to see if falling rigidbodies ever actually reach floating point limits. My assumption, as was @BoogieD 's, was that it would, even though incrementing by just one on the mantissa will increment the value by a large number of units. Turns out it actually wont reach float.NegativeInfinity (fitting username by the way).

Also that demo is pretty sweet, I’m guessing you’re moving around using vectors of doubles, and scaling it down a whole bunch so it still works in 4 byte precision territory?

I’ve been thinking about a slightly different system where large regions are partitioned into integer coordinates, and within that region is the scene. It’d be pretty similar to just using double precision vectors, as ints and floats are both 32 bits.

IIRC, when I was last trying to use floats on planetary scales, spaceships were starting to shake roughly around 300000…500000 coordinates, like in your test.

Since rigidbody position most likely is calculated using something like “position += vt + a t* t*0.5”, when coordinates are large, added value will be too small to make an impact (t will be something like 0.02, because physics run at fixed steps)

Yes, but I’m also using stacked cameras to render distant objects. 4 stacked cameras, IIRC. Also, visual proxies. The demo is available on github, you could grab it and tear it apart. The thing is I didn’t implement some things there, like double precision torque handling, because it was written in a hurry over course of an evening or so. There is object hierarchy support, though and planest are moving around each other using newtonian physics.

The idea was to render distant planets far beyond normal zfar range and have them occlude smaller objects properly.

Ah, good old displacement formula =) I always assumed it was something like “v += a * t” followed by “position += v * t”.
And yea, the rounding down of small changes is what I was guessing at the end of the root post.

The camera stacking is interesting, I was thinking a while back how games like Elite: Dangerous have such massive distances while also having large speeds. It’s got support for VR too, so depth information needs to be carried over as well. Might be possible to just put everything except the closest layer into a RenderTexture and stick that at the far clip plane like @kode80 did with his clouds. Probably not even noticeable in VR at that point.

An interesting thought as to how many years until everything moves to double. Has to happen sooner or later. I wonder if there’ll be both for a while, or just a move in one unity version? Certainly you come across more and more people reaching the limits of single and asking.

When it’s affordable!

2 Likes

This. Once the average hardware is no longer severely crippled for double versus single we’ll see it. Right now even the top end hardware is taking 32 times as long to process them and latest advances have been in the opposite direction (FP16).

2 Likes

That’s a hellish hit to process doubles. Nails it firmly at the door of the hardware manufacturers.

Most games don’t need it so it’s an unnecessary overhead.

More like most game are made to fit the limit, all those open world game happening need it, and now we are moving to galactic scale games (Ubi has two of them, there is 3 major space games, etc …)…

1 Like

I get the feeling we’re in a Big Game Bubble more than anything, honestly. AAA has been long training people that they offer the “biggest” experiences for a while now and this is the culmination of that. I imagine if there’s enough high-profile failures that bubble will burst pretty quick.

Well not after Horizon and Zelda BOTW, no man’s sky is doing better than some would want to think and Elite is cruising, witcher 3 has also raised a standard, GTA is showing no current sign of fatigue and red dead 2 is hype to hell right now.

It’s really the quality of the design, the big loser is UBI soft, which experience a lot of backlash and sharp decrease (still healthy) in the profile of his licenses.

A decade, perhaps?Basically, double precision has inferior performance on GPUs, so to move to double precision, you’ll need ALL gpu manufacturers to switch to it. This can’t happen quickly.

Most games don’t need doubles, and large scenes can be rendered without them.