-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
BVH - add option for expanded AABBs in leaves #55096
Conversation
460440b
to
ff78b7c
Compare
ff78b7c
to
03f15df
Compare
Rebased now #55050 has been merged. BTW, all these PRs will be relevant in 4.x too, but I'll get them all working in 3.x first then will port in case of any differences in 4.x. |
03f15df
to
08a2d6b
Compare
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.
Looks great!
I haven't spotted any regression, and in 2D performance is 20% better in my broadphase test compared to 3.x before the recent BVH fixes, which is kind of expected due to using a higher expansion margin!
All other performance tests I've run have similar results as before, which means the BVH expansion fixes have no measurable cost in these tests.
I've made a little comment for the documentation, but apart from that it should be good to go.
08a2d6b
to
9eb2a57
Compare
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.
I can already approve, it just needs one last tiny change in the documentation.
9eb2a57
to
c94b1f6
Compare
This PR adds a define BVH_EXPAND_LEAF_AABBS which is set, which stores expanded AABBs in the tree instead of exact AABBs. This makes the logic less error prone when considering reciprocal collisions in the pairing, as all collision detect is now taking place between expanded AABB against expanded AABB, rather than expanded AABB against exact AABB. The flip side of this is that the intersection tests will now be less exact when expanded margins are set. All margins are now user customizable via project settings, and take account of collision pairing density to adjust the margin dynamically.
c94b1f6
to
211dc8c
Compare
I've also added a similar note to the render tree |
x = MIN(x, 1.0); | ||
x = 1.0 - x; |
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.
Is there any risk to end up with a negative x
with floating point errors?
If yes, could possibly be changed to something like:
x = MIN(x, 1.0); | |
x = 1.0 - x; | |
x = MAX(1.0 - x, 0); |
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.
No I don't think so, 1.0 is defined precisely in floating point afaik, and even then I'm not sure a negative expansion margin would be a problem in this case. Should be fine I think. (I do this all the time so it better be lol 😁 )
Cherry-picked for 3.4.1. |
This PR adds a define BVH_EXPAND_LEAF_AABBS which is set, which stores expanded AABBs in the tree instead of exact AABBs.
This makes the logic less error prone when considering reciprocal collisions in the pairing, as all collision detect is now taking place between expanded AABB against expanded AABB, rather than expanded AABB against exact AABB.
The flip side of this is that the intersection tests will now be less exact when expanded margins are set.
All margins are now user customizable via project settings, and take account of collision pairing density to adjust the margin dynamically.
Related to #54855
Notes
Although initially this change made the BVH a bit slower, I had noticed that the optimum expansion margin was dependent on how dense the local collisions were. When objects are highly stacked, a low margin is best, because it sends the minimum number of collisions to the physics, which becomes the bottleneck. When objects are more rarely interacting, a higher margin is better because the BVH is the bottleneck. So in this PR it uses a metric which lowers the margin dynamically per object based on how many other objects are paired with it.
This significantly improves performance in situations with stacks of items (circa 30% in my tests so far), which performing mostly as well or better with sparser object placements.
bvh_collision_margin
in all cases. I did notice that the 2d physics settings look a little "busy" - @pouleyKetchoupp should there be a "Godot Physics" section in the 2d physics settings as with the 3d settings?