Custom broadphase filter for city-sized world, need advice

Post Reply
User avatar
romanshuvalov
Posts: 4
Joined: Fri May 06, 2016 5:36 pm

Custom broadphase filter for city-sized world, need advice

Post by romanshuvalov »

Greetings. I have:

1) City-sized world with top-down view.
2) World is logically "flat", I mean there are no multi-level constructions where a lot of objects stack on each other, but there are btHeightfieldTerrainShape() surface and 3D stuff (jumping etc).
3) 90% of objects are static (buildings etc).
4) World is divided by blocks for visual frustum culling, but I think it can be useful for physics optimizations. I only need perform action around the player (in player's block and neighborhood blocks). Every other block should be frozen, in fact these blocks are hidden by long distance and/or by frustum culling and I shouldn't waste CPU for calculating physics in these blocks.

As I understand, broadphase is responsible for initial collision tests. However I could manually "turn off" huge chunks of objects and save some CPU time. How should I do it? I think I need something like custom collision filtering (btOverlapFilterCallback), but more "powerful" so engine will not only skip these useless blocks but will not touch them at all. Any suggestions?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Custom broadphase filter for city-sized world, need advice

Post by drleviathan »

My first bit of advice would be to just try it out with all objects and see if you really do have a performance problem. If you have 10k object or less and your target hardware platform has plenty of RAM and CPU resources you might not have any problems. Maybe load objects into the world as necessary but don't bother to remove them when they go out of view: would make for simple code and if the performance is good enough then your job is done.

Although you would be loading "blocks" of terrain for render culling it may be that Bullet will perform OK if you were to load the whole terrain as one big object, or as a few big objects that are still larger than your visual blocks. I don't have much experience using btHeightfieldTerrainShape but I know btTriangleMeshObject performs fine with several thousand triangles when the mesh is much larger than the dynamic objects walking around on it. However, if you have a big dynamic object that happens to overlap with a few thousand triangles of a btTriangleMeshObject all at once then Bullet's performance will suffer and you would be Doing It Wrong.

If your world has a lot of static objects but those objects are guaranteed to never move then you could just call collisionWorld->setForceUpdateAllAabbs(false) for a simple optimization, as mentioned in more detail in other forum threads.

If you already have culling working for your render pipeline then you could just use the same logic to add/remove objects Bullet's collision world and everything should work out fine... as long as all dynamic objects are added AFTER all of the nearby static objects they need for collisions. The cost of adding/removing a btCollisionObject to the btCollisionWorld scales as O(N) and should remain unnoticeable until you have several tens of thousands of objects in the broadphase.
hyyou
Posts: 96
Joined: Wed Mar 16, 2016 10:11 am

Re: Custom broadphase filter for city-sized world, need advice

Post by hyyou »

+1 drleviathan :lol:

I heard a rumor that btAxisSweep3 and bt32AxisSweep3 is faster than the generic one "with a limitation that it requires a fixed world size".
It is in Sweep and Prune (SAP) in http://www.bulletphysics.org/mediawiki- ... Broadphase

^Edit: Erwin doesn't think so. Thus, please ignore my words.
Last edited by hyyou on Wed Jan 10, 2018 2:07 am, edited 1 time in total.
User avatar
romanshuvalov
Posts: 4
Joined: Fri May 06, 2016 5:36 pm

Re: Custom broadphase filter for city-sized world, need advice

Post by romanshuvalov »

You are right, performance is high enough. After ~15k static objects my frame rate dropped significantly, however, I'm not sure if it's bullet's fault or not.

Anyway, I've decided to load objects on the fly (player will never reach ~50..70% of all objects) and I believe this is all solution I need.

Thanks.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Custom broadphase filter for city-sized world, need advice

Post by Erwin Coumans »

The btDbvtBroadphase should be pretty fast in general, faster than btAxisSweep3/bt32AxisSweep3 and better raycast / aabb cast acceleration.

Bullet updates all AABBs, including the static object. You can use world->setForceUpdateAllAabbs(false) to improve performance.
Post Reply