Skip to content

Support doubles #30

Closed
Closed
@TokisanGames

Description

Update: #232 has added the ability to build Terrain3D with double precision.

To get it working you need to:

  • Build Godot with scons precision=double
  • Regenerate godot-cpp bindings with this new executable
  • Build Terrain3D (which includes godot-cpp) with scons precision=double custom_api_file=YOUR_CUSTOM_FILE

@zuriel13 reported the demo is working fine using Godot 4.2.1 and Terrain3D 0.9.1-dev.

Using a single precision engine, the terrain and shader look fine when moving the camera even 100k units away from the origin. This may break down at extremes though and bears testing.

Shaders do not support double precision, however the engine does include some double emulation. Clayjohn wrote an article describing how to emulate double precision in shaders for positional elements. He writes that the camera and model transform matrices needed to be emulated, and that is now done automatically in the engine.

https://godotengine.org/article/emulating-double-precision-gpu-render-large-worlds/

It's possible that other elements of the shader will need to emulate double precision, but no issues are apparent, yet.

Related to regenerating bindings: godotengine/godot-cpp#1386


Include a build flag that supports doubles in both the shader and C++ where relevant. Probably only locations. This is done in godot source:

//math_defs.h
/**
 * The "Real" type is an abstract type used for real numbers, such as 1.5,
 * in contrast to integer numbers. Precision can be controlled with the
 * presence or absence of the REAL_T_IS_DOUBLE define.
 */
#ifdef REAL_T_IS_DOUBLE
typedef double real_t;
#else
typedef float real_t;
#endif

// Elsewhere
#ifdef REAL_T_IS_DOUBLE
	if (p_feature == "double") {
		return true;
	}
#else
	if (p_feature == "single") {
		return true;
	}
#endif // REAL_T_IS_DOUBLE

10k out
image

1M out, corruption and the mesh jitters all over the place
image

Metadata

Assignees

No one assigned

    Labels

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions