Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity3d floating point precision limitations

I got a warning from Unity3D Pro that I don't quite understand. I set my player's Transform.position.x to 1000000 in the GUI and it gave me this warning:

"Due to floating-point precision limitations, it is recommended to bring the world coordinates of the GameObject within a smaller range."

Does that mean that my single scene has to be smaller than 1000000*1000000*1000000. Is this considered big enough? I will need multiple scenes if I want a larger world? When a new scene gets loaded, will my player's position be reseted? How do I manage the position data so that it doesn't go out of range?

like image 571
Zening Qu Avatar asked Jun 02 '13 04:06

Zening Qu


People also ask

Is there any way to extend unity's floating point scene size limit?

Is there any real way to extend Unity's floating point scene size limit? Does Unity have plans to improve this? As it stands if you move away from the origin point, at 0 and move between 30,000-50,000 units in any direction the engine can no longer handle graphics or physics because you've gone beyond the floating point's threshold for accuracy.

What is fixed fixed precision in Unity?

Fixed precision is useful for regular colors (as typically stored in regular textures) and performing simple operations on them. Unity’s shader compiler ignores floating point number suffixes from HLSL. Floating point numbers with a suffix therefore all become float.

Does unity plan on doing something with floating point?

That being said, @Joachim_Ante has mentioned once or twice that Unity plans on doing something with floating point (by "making it easier to handle floating origins" were what I remember off the top of my head as his words).

How far away from the origin point does unity support?

I am currently working with a team on a project involving a large scale world. I currently believe Unity supports anything up to 99,999.99 meters away from the origin point (1 Meter = 1 Unity unit). This size gives precision up to 1cm, if I am thinking of this correctly. Up to 9999.999 meters away from origin gives you 1 millimeter precision.


1 Answers

For numbers of magnitude 1,000,000, the step size of IEEE-754 32-bit binary floating-point is 1/16 (.0625). So the next number above 1,000,000 that is representable is 1,000,000.0625.

That might be fine if you have a view where changes of .0625 are not visible to the eye. If the scale of the objects in your world is such that .0625 is much smaller than any object feature, and the view will never zoom in to where differences of .0625 are noticeable to the human eye, then there may be no problem. (However, you may want a little more leeway. Even if object features of that size are not visible, some of the math may be affected, since any calculations of velocity, position, et cetera, cannot use increments smaller than .0625 while you are doing 32-bit arithmetic on numbers of magnitude 1,000,000.)

Compare that to numbers near the origin, say numbers of magnitude 100. At 100, the step size is 1/131072 (.00000762939453125). If you are drawing objects that take advantage of this fine resolution, they will look fine as long as they are near the origin. However, when they move through your scene to places where the coordinates have larger magnitude, they lose resolution.

The basic problem here is the ratio between the size of the scene and the size of the details in the scene. That is what is limited. You can have large coordinates as long as the object features are also large. But you cannot maintain fine object features while the coordinates are large.

like image 84
Eric Postpischil Avatar answered Nov 15 '22 11:11

Eric Postpischil