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

Lowering the Minimum Unit at Shape3D and Cameras #43547

Merged

Conversation

TokageItLab
Copy link
Member

As for the Margin minimum, it was lowered once in #23472, but it was degraded to 0.04, so I put it back.

The issue is that the minimum unit for Sphere3D was 0.01, even though the minimum unit for primitives like CSGSphere is 0.001. As mentioned in #23472, the minimum unit of 1 cm (2 cm as a diameter) is too large when applying real world scale, as in VR. In addition to that, I've also lowered the minimum unit of camera clipping.

https://www.youtube.com/watch?v=YFwDJ0jQiQg

The scale is so small that the falling speed appears to be faster. Spherical collisions are generally not a problem, but they can get a little out of control when moments are involved, such as cylinder collisions.

@TokageItLab TokageItLab requested review from AndreaCatania and a team as code owners November 14, 2020 22:11
@pwab
Copy link

pwab commented Nov 14, 2020

As we discussed this also in GodotVR/gdleapmotion#13 maybe @BastiaanOlij could be interested in a review too.

@TokageItLab
Copy link
Member Author

Yes, it's true that the current Godot's physics is not very good, and it needs to be improved. That is being discussed in #43073 for 4.0, so we should be actively proposing it. However, the purpose of this PR is to remove the difference between CSG primitives and 3DShape minimums.

@pwab
Copy link

pwab commented Nov 14, 2020

Hey @TokageItLab I'm not sure if my comment was misunderstood. I only wanted to get Bastiaan informed as he is working a lot with VR and was also involved in #23472.
I just somehow saw the relation to the linked issue. Sorry if I got something wrong here.

@TokageItLab
Copy link
Member Author

to @pwab
I'm sorry too, I misread who the comment was directed at.

I anticipate that there is a fundamental problem apart from the problem with minimum units. And the cylinder/capsule collision issue affects the physical bones as well. I think this problem would be better recognized a bit more widely, so I hope Bastiaan will focus his attention on physics 4.0 as well.

@AndreaCatania
Copy link
Contributor

The GJK algorithm, used for collision detection, is cheaper when the two shapes are not overlapping.

When those are overlapping, more calculations are needed to extract the collisions info.

The margin, is used to keep the bodies at a safer distance so to prevent trigger those extra calculations, and keep performance up.

Lowering the margin more than 0.04 is discouraged, and preventing the user to go too lower than 0.01 is a good thing.

If you need to hide this margin you have two valid routes that allow to preserve the margin:

  • Increase the mesh size by the margin.
  • Or scale up your world by 10. In this way the margin will be feel like 4mm so totally ok.

@TokageItLab
Copy link
Member Author

@AndreaCatania

The minimum unit for margin is already 0.001, so it's not a problem to set the default value for margin to 0.04.

However again, the difference between the CSG primitive's minimum unit being 0.001 and Shape3D's minimum unit being 0.01 is obviously strange. Using world scales is not a fundamental solution, and is a major obstacle to projects that involve import processes. If we are going to do that, we should add a feature that can be configured in the preferences as an engine feature.

For now, I've reverted to 0.04 just for the default values.

@BastiaanOlij
Copy link
Contributor

@AndreaCatania scaling up by 10 isn't actually a solution because to keep the physics animation realistic everything also moves 10x as fast and gravity needs to be 10x as high. The end result is that the engine behaves exactly the same asif you have set the margins to a 10th and left the scaling alone.

The problem is that in all the videos and explanations I've seen that suggest this increase of scale, they aren't scaling up all the other factors. Yes the collisions work much smoother and faster, but everything moves as if you're on the moon instead of realistically.

@akien-mga
Copy link
Member

The changed hints seem fine. Could you squash the commits into one? See PR workflow.

@TokageItLab TokageItLab force-pushed the lowering-s3d-and-camera-min-unit branch from 011e2b7 to 61bedbf Compare November 16, 2020 22:36
@TokageItLab
Copy link
Member Author

@akien-mga I squashed it. I apologize for not being familiar with the workflow and I will be careful from now on.

@TokageItLab TokageItLab force-pushed the lowering-s3d-and-camera-min-unit branch from 61bedbf to 4a2aaab Compare November 17, 2020 04:17
@akien-mga
Copy link
Member

No need to apologize, you did nothing wrong :)

@akien-mga akien-mga merged commit 9de18cc into godotengine:master Nov 17, 2020
@akien-mga
Copy link
Member

Thanks! And congrats for your first merged Godot contribution 🎉

@AndreaCatania
Copy link
Contributor

@AndreaCatania scaling up by 10 isn't actually a solution because to keep the physics animation realistic everything also moves 10x as fast and gravity needs to be 10x as high. The end result is that the engine behaves exactly the same asif you have set the margins to a 10th and left the scaling alone.

The problem is that in all the videos and explanations I've seen that suggest this increase of scale, they aren't scaling up all the other factors. Yes the collisions work much smoother and faster, but everything moves as if you're on the moon instead of realistically.

Yes that's right, you should also scale the other parameters (velocity, gravity, forces) 10x. The difference is that with the world scaled up, you feel the margin thinner. Though, you have much more room to account for floating point precision error because you are still using a good margin (in the order of 0.01).

@aaronfranke
Copy link
Member

@AndreaCatania Scaling the world up or down does absolutely nothing to solve floating point precision error. If you double the size of everything, then the numbers will be half as precise (so the effective precision is exactly the same as before).

If the behavior changes at different scales, that's a bug, and isn't caused by floating point numbers, just flawed code somewhere.

@AndreaCatania
Copy link
Contributor

You right, I was wrong mentioning floating point precision error. Though, I was referring more to the physics engine imprecision.
That is also increased scaling the world. The only way to lower the imprecision is increasing the physics Hz.
So yes, scale the world is not a great solution as I thought. You can still tweak the mesh size, maybe using the grow parameter that you have in the Material so to hide the margin.

@BastiaanOlij
Copy link
Contributor

Changing the physics update rate is the only way for this to improve (at the expense of performance as we're increasing the workload).
Scaling the world only works if you do not scale all the other variables but then you get imprecise physics behavour.

Like @aaronfranke says, scale everything by 10x you're right back where you started. A 1meter x 1 meter x 1 meter cube with a 1 cm margin (0.01 meter) will behave exactly the same as a 100cm x 100cm x 100cm cube with a 1cm (1) margin.

@TokageItLab TokageItLab deleted the lowering-s3d-and-camera-min-unit branch May 2, 2022 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants