-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
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 broadphase creates objects with updated AABB to avoid extra checks #45319
Conversation
When set_static is called on a newly added object, the forced collision check in BVH set_pairable was using an empty AABB, which caused unnecessary collision checks at the origin, then a call to move was checking again at the right position. These changes ensure broadphase objects are added to the BVH tree with proper AABB so collision checks are correctly done right away. Octree & Basic broadphase trees are not affected by these changes.
Yup this definitely makes sense. The old way of setting them to a zeroed AABB then setting the AABB in a second step is going to needlessly do extra processing. 👍 |
@@ -31,7 +31,7 @@ | |||
#include "broad_phase_octree.h" | |||
#include "collision_object_sw.h" | |||
|
|||
BroadPhaseSW::ID BroadPhaseOctree::create(CollisionObjectSW *p_object, int p_subindex) { | |||
BroadPhaseSW::ID BroadPhaseOctree::create(CollisionObjectSW *p_object, int p_subindex, const AABB &p_aabb) { | |||
|
|||
ID oid = octree.create(p_object, AABB(), p_subindex, false, 1 << p_object->get_type(), 0); | |||
return oid; |
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.
Presumably you could do the same for octree? Not that it matters that much if we do get rid of it, but may as well..
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've tried but it actually makes things slower to just initialize the aabb, because the way it works right now, having an empty aabb to start with avoids extra checks in set_static
and things get checked later in move
.
It should be possible to dig into it and set things properly, but I'm not sure there's going to be a noticeable gain and as you said it's probably not worth it if we start using the bvh instead.
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.
Yeah looks good. I haven't tested but I assume Pouley has.
Thanks! |
Description
When
set_static
is called on a newly added object, the forced collision check in BVHset_pairable
was using an empty AABB, which caused unnecessary collision checks at the origin, then a call to move was checking again at the right position.These changes ensure broadphase objects are added to the BVH tree with proper AABB so collision checks are correctly done right away.
Octree & Basic broadphase types are not affected by these changes.
I'm not doing the same changes in the 2D physics interface because there's no use for them in the 2D broadphase at the moment.
Test Scenario
Test project:
physics_tests.zip
Scene:
res://tests/performance/test_perf_broadphase.tscn
This test adds 125000 non-overlapping objects in physics at once, moves them all then removes them all. It logs timings for the different operations and physics ticks for the following frames.
Test Results
I'm getting almost 30% improvement on adding objects in this test scenario, which makes the dynamic BVH slightly better than Octree when it comes to adding objects.
Detailed results (release_debug):
BVH - Previous version
BVH - This PR
Octree