Optimization for Big and lots of Rigid Bodies

Post Reply
kcjsend2
Posts: 15
Joined: Wed Jun 30, 2021 9:10 am

Optimization for Big and lots of Rigid Bodies

Post by kcjsend2 »

hello.

What I've been doing recently is using a large amount of Terrain Rigid Body.
There are about 1024 * 1024 Height field data used to make Shape, which has caused a FPS decline.
So what I tried was to split the data into several Rigid bodies, which didn't help much.
Is there anything I'm missing?
Perhaps we will be dealing with a larger size of Terrain in the future, but is there an optimization method for this?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Optimization for Big and lots of Rigid Bodies

Post by drleviathan »

I believe the btHeightfieldTerrainShape builds btTriangleShapes as necessary from the regularly spaced heightfield data. That is, when another object gets within proximity for the narrow-phase collision calculation then temporary btTriangleShapes are constructed to allow the collision algorithms to compute the results. An advantage of this behavior is: you can relatively easily update the heightfield data between steps. As long as you properly update the btHeightfieldTerrainShape's bounding box to properly reflect the changed heights, this works, and if you need the dynamic aspect of the terrain then use that shape.

If your terrain never changes shape then you could improve performance by using offline manipulations to reduce the triangle count, load the terrain as a mesh, and use btBvhTriangleMeshShape instead. For best performance make sure your terrain has triangles as big as, or bigger, than your smallest dynamic object, so that your dynamic objects overlap and collide with as few triangles as possible. If you create a giant dynamic object as big as your 20k triangle mesh then... you will experience a very big CPU/memory spike when it produces 20k+ convex-object vs triangle collision pairs. Meanwhile a little marble rolling around on a giant 20k triangle mesh will be fast.
Post Reply