Double Precision

When the player and camera move 10s to 100s of thousands, or millions of units away from the origin using a single precision float engine, things start to break down. Movements, positions, and rendering starts to become jittery or corrupted as the interval between valid values gets larger and larger.

Building Terrain3D with double precision (aka 64-bit) floats allows high precision even at large numbers, but there are some caveats.

For a more detailed explanation, see Large World Coordinates in the Godot documentation.

Caveats

  • This feature is experimental and has had only one user give a positive report so far.

  • There are many caveats listed in the link above. You should read them all before beginning this process.

  • You must build Godot and Terrain3D from source.

  • Terrain3D currently supports a maximum world size of 65.5x65.5km. Although with vertex_spacing, you can expand this up to 100x. You can also have Terrain3D regions around the origin, then have your own meshes or a shader generated terrain outside of that maximum world space.

  • Shaders do not support double precision. Clayjohn wrote an article demonstrating how to Emulate Double Precision in shaders. He wrote that the camera and model transform matrices needed to be emulated to support double precision. This is now done automatically in the engine when building it with double precision. There may be other cases where shaders will need this emulation.

Setup

One user reported success using Godot 4.2.1 and Terrain3D 0.9.1.

To get Terrain3D and Godot working with double precision floats, you must:

  1. Build Godot from source with scons precision=double along with your other parameters like target, platform, etc.

  2. Generate custom godot-cpp bindings using this new executable. This will generate a JSON file you will use in the next step.

  3. Build Terrain3D from source (which includes godot-cpp) using scons precision=double custom_api_file=YOUR_CUSTOM_JSON_FILE

After that, you can run the double version of Godot with the double version of Terrain3D.

Further Reading

See Support Doubles #30 for our Issue that documents implementing support for doubles in Terrain3D.