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

Add support for double precision floats #56

Closed
aaronfranke opened this issue Jul 3, 2020 · 1 comment
Closed

Add support for double precision floats #56

aaronfranke opened this issue Jul 3, 2020 · 1 comment
Labels
enhancement New feature or request suggestion Idea or improvement suggestion

Comments

@aaronfranke
Copy link

Double-precision floats are necessary for games that take place on extremely large scales, such as in the vastness of space. There are workarounds, but they all come with issues. If Flax Engine wishes to support extremely large scales, it would make sense to add support for double precision floats.

For further justification on this feature, please see this proposal I made for Godot: godotengine/godot-proposals#892

As for the implementation, it is possible to support compiling with both single and double precision floats at the same time, if done correctly. This can be handled in C# via preprocessor directives by defining an alias, like this:

#if REAL_T_IS_DOUBLE
using real_t = System.Double;
#else
using real_t = System.Single;
#endif

The downside is that this alias definition must be repeated in every C# file. For a more detailed example, see this file in Godot: https://github.com/godotengine/godot/blob/master/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs

@mafiesto4 mafiesto4 transferred this issue from FlaxEngine/FlaxAPI Dec 24, 2020
@mafiesto4 mafiesto4 added the enhancement New feature or request label Dec 24, 2020
@mafiesto4 mafiesto4 added the suggestion Idea or improvement suggestion label Jan 28, 2021
@mafiesto4
Copy link
Member

Added to the master! Can be enabled in a custom engine build by setting this to true:

"UseLargeWorlds": false

Soon there will be proper support for the rendering relative to the camera (work in progress) and implementation of 64-bit coordinates in other systems (audio, physics,..). Then, of course we will add documentation.

By setting UseLargeWorlds=true the Vector2/3/4 types are using double instead of float:

  • C++

    #if USE_LARGE_WORLDS
    // 64-bit precision for world coordinates
    API_TYPEDEF(Alias) typedef double Real;
    #define MIN_Real MIN_double
    #define MAX_Real MAX_double
    #else
    // 32-bit precision for world coordinates
    API_TYPEDEF(Alias) typedef float Real;
    #define MIN_Real MIN_float
    #define MAX_Real MAX_float
    #endif
    // Vector2
    template<typename T> struct Vector2Base;
    API_TYPEDEF() typedef Vector2Base<float> Float2;
    API_TYPEDEF() typedef Vector2Base<double> Double2;
    API_TYPEDEF() typedef Vector2Base<int32> Int2;
    API_TYPEDEF(Alias) typedef Vector2Base<Real> Vector2;
    // Vector3
    template<typename T> struct Vector3Base;
    API_TYPEDEF() typedef Vector3Base<float> Float3;
    API_TYPEDEF() typedef Vector3Base<double> Double3;
    API_TYPEDEF() typedef Vector3Base<int32> Int3;
    API_TYPEDEF(Alias) typedef Vector3Base<Real> Vector3;
    // Vector4
    template<typename T> struct Vector4Base;
    API_TYPEDEF() typedef Vector4Base<float> Float4;
    API_TYPEDEF() typedef Vector4Base<double> Double4;
    API_TYPEDEF() typedef Vector4Base<int32> Int4;
    API_TYPEDEF(Alias) typedef Vector4Base<Real> Vector4;

  • C#

    #if USE_LARGE_WORLDS
    using Real = System.Double;
    #else
    using Real = System.Single;
    #endif

We do have vector types Float2/3/4, Double2/3/4 and Int2/3/4 to explicitly use certain precision and data size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request suggestion Idea or improvement suggestion
Projects
None yet
Development

No branches or pull requests

2 participants