Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support doubles #30

Closed
TokisanGames opened this issue Jan 28, 2023 · 3 comments
Closed

Support doubles #30

TokisanGames opened this issue Jan 28, 2023 · 3 comments
Labels
enhancement New feature or request low priority Low Priority
Milestone

Comments

@TokisanGames
Copy link
Owner

TokisanGames commented Jan 28, 2023

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

@TokisanGames TokisanGames added the enhancement New feature or request label Jan 28, 2023
@TokisanGames TokisanGames added this to the Polished Version milestone Jan 28, 2023
@TokisanGames TokisanGames added the low priority Low Priority label Feb 3, 2023
@ozzr
Copy link

ozzr commented Feb 14, 2023

Wouldn't just change any float or double property to real_t do the job in c++? And let the engine choose what to use

@TokisanGames
Copy link
Owner Author

Oh I didn't know that was a thing. What about double in the shader?

@TokisanGames TokisanGames added the good first issue Good for newcomers label Jul 17, 2023
@TokisanGames TokisanGames modified the milestones: Future, Beta Oct 19, 2023
@TokisanGames TokisanGames removed the good first issue Good for newcomers label Oct 22, 2023
@TokisanGames TokisanGames modified the milestones: Beta, Stable Dec 16, 2023
@TokisanGames TokisanGames modified the milestones: Stable 1.0.x, Beta 0.9.x Feb 10, 2024
@TokisanGames
Copy link
Owner Author

Double support has been tested and is reported working fine. Updated instructions in the first post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request low priority Low Priority
Projects
Status: Done
Development

No branches or pull requests

2 participants