-
Notifications
You must be signed in to change notification settings - Fork 145
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
Change c++ code to work with doubles #232
Conversation
Don't merge this until I've gone through everything |
You know, thinking about it I think its fine that all instances here are switched to real_t. I was thinking using set_cull_margin(real_t) is a waste of space using a double when only a float is needed. But if we're calling it from gdscript what is coming in is a double anyway. The only concern I have is with saved variables. Say version for instance. If it's saved as a float into Storage. Then later read by a double engine, is it seamlessly converted? If it's saved as a double, can it be opened by a float engine without issue? If version and all of the other data can be read and written by both engines then it's fine to do everything as real_t. Also include a line somewhere like __ready() that prints |
Asked AThousandShips:
Shouldn't be an issue. |
|
src/terrain_3d.cpp
Outdated
@@ -75,7 +75,7 @@ void Terrain3D::_initialize() { | |||
|
|||
void Terrain3D::__ready() { | |||
_initialize(); | |||
LOG(WARN, "Float: ", sizeof(float), " Real_t: ", sizeof(real_t)); | |||
LOG(WARN, "Float: ", Variant(sizeof(float)), " Real_t: ", Variant(sizeof(real_t))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need these in the repo, I just want you to run it once to confirm that building with precision=double does something, and I'd like you to post your results in the comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, Ok
Got it to build, as I said in discord. Let me know if I need to change anything. |
godot-cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove from PR. I will update godot-cpp later. Current commit tag is godot-4.1.1-stable
project/project.godot
Outdated
@@ -12,7 +12,7 @@ config_version=5 | |||
|
|||
config/name="Terrain3D" | |||
run/main_scene="res://demo/Demo.tscn" | |||
config/features=PackedStringArray("4.1") | |||
config/features=PackedStringArray("4.1", "Double Precision") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove from PR. Users can enable this
src/terrain_3d.cpp
Outdated
@@ -75,6 +75,7 @@ void Terrain3D::_initialize() { | |||
|
|||
void Terrain3D::__ready() { | |||
_initialize(); | |||
// LOG(WARN, "Float: ", Variant(int(sizeof(float))), " Real_t: ", Variant(int(sizeof(real_t)))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
src/util.cpp
Outdated
@@ -58,7 +58,7 @@ Vector2 Util::get_min_max(const Ref<Image> p_image) { | |||
} | |||
|
|||
/** | |||
* Returns a Image of a float heightmap normalized to RGB8 greyscale and scaled | |||
* Returns a Image of a real_t heightmap normalized to RGB8 greyscale and scaled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to: Returns a scaled, RGB8 greyscale Image of a heightmap normalized to its heights
oh dear. Will me removing godot-cpp from this PR cause issues in the main branch? The CI is freaking out right now. |
src/terrain_3d_editor.cpp
Outdated
float alpha_clip = (brush_alpha < 0.1f) ? 0.0f : 1.0f; | ||
int index_base = int(src.r * 255.0f); | ||
int index_overlay = int(src.g * 255.0f); | ||
real_t alpha_clip = (brush_alpha < real_t(0.1f)) ? 0.0f : 1.0f; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was there any sort of warning from the compiler comparing real_t brush_alpha and 0.1f?
If not, let's remove all of the literal conversions. I now think we only need the real_t conversions for ints. For floats to doubles it is free and unnecessary, unless there are warnings. Let's remove them all from here down to the last lerp on line 233.
https://stackoverflow.com/questions/13045485/division-of-double-with-a-float
The only need I see is where it is casting dest_index
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were warnings when it came to function parameters; math.lerp didn't like an argument list of mixed floats and real_ts. I can remove the ones outside of those parameters, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add any casts to remove warnings. Otherwise, we don't need it for float to double.
I looked closer at the godot source. Excluding modules & thirdparty code, .h/.cpp lines using float: 10212, real_t: 6091. There are only 2 usages of float in all of the physics servers, none in navigation. Rendering is 99% float, needed only for locations or distance. The other uses are unnecessary. The moviewriter is a new addition and has 3 floats, 0 real_t. So my conclusions are:
This link says float to double conversion on x87 fpu is free, and I've seen that other places as well. So I think for consistency like the physics and navigation servers, we can use real_t everywhere. Let's wrap up this and merge it in. The shader portion can come separately. Please make the following changes:
|
I've addressed the individual comments. I will soon remove explicit conversions, squash (hopefully I don't screw it up this time), and rebase. |
I don't mean removing godot-cpp from your repository, aka, deleting the folder and pushing that change. I mean reverting your godot-cpp to the previous version ( |
Great job, thank you. In the future don't use |
For the record, I never did git merge, I let GitHub do all of that. And, I never found any “merge” actions when I was rebasing.
…On Sun, Oct 22, 2023 at 02:17, Cory Petkovsek ***@***.***(mailto:On Sun, Oct 22, 2023 at 02:17, Cory Petkovsek <<a href=)> wrote:
Great job, thank you. In the future don't use git merge. You can do anything else like rebase, but let github do all merging.
—
Reply to this email directly, [view it on GitHub](#232 (comment)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AC6NJR5KLAXRSOONS3YBIHDYATQD7AVCNFSM6AAAAAA6GYOKROVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZUGA2DCNZXGM).
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
solves half of issue #30 - doesn't touch shader though