[V1]Performance question (lots of static boxes versus mesh)

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
KakCAT
Posts: 32
Joined: Mon Apr 14, 2014 2:08 pm

[V1]Performance question (lots of static boxes versus mesh)

Post by KakCAT » Sun Sep 15, 2019 9:36 am

Hi,

I've been continuing my 3d game sticking to V1 (I think I'm too late on development to move to V2). The game is mostly done with basic shapes (cubes mostly), however there are LOTS of them. The game is quite simple physically talking (several slow moving character controllers across a big scenario, I use bepu mostly as a collision detector)

Lately in order to speed up map creation, I decided to add a component I call "Patch2D". It's basically a 2d tilemap which has 3D presence (each tile of the 2D tilemap is a box or compound of boxes). This of course generates lots of (static) boxes. In example, in the attached test map image, ~4000 boxes are generated.

Image

This leaves v1 needing 5ms/frame while playing the game. My next step was optimizing the patch2D to generate "big boxes" instead of one box per tile. However I decided to test a StaticMesh first instead. There's a huge speedup, around 30x faster.

So my question is: is there anything I should be aware of if I convert the whole scenarios to a big static mesh? Converting the patch2D was easy but converting all the other objects will take some time, and I'd hate to get bitten in the back once the work is done. :)

Also, are the numbers in V2 proportional to these in v1? I mean, meshes being faster than ~4000 boxes.

Thanks!

Norbo
Site Admin
Posts: 4895
Joined: Tue Jul 04, 2006 4:45 am

Re: [V1]Performance question (lots of static boxes versus mesh)

Post by Norbo » Sun Sep 15, 2019 9:45 pm

StaticMeshes won't have any particularly weird gotchas. There's the one-time acceleration structure build cost, but it's not that bad. Dynamic topology modifications (adding/removing triangles) could be an issue since they demand a reconstruction in v1. Dispatching a thread to work on that in the background is a common option. For very large meshes (like terrains), it's common to also chunk it into smaller pieces of a few thousand triangles or whatever tradeoff works out best.

There are also StaticGroups. Same deal as meshes, but for all shape types, not just triangles. StaticGroups don't have boundary smoothing, but that's about it.

The reason for the extra cost is the broad phase. Having thousands of extra collidables being updated and tested every frame gets a bit expensive. That's why a StaticMesh/StaticGroup helps- it bundles thousands of child shapes into a single broad phase entry.

In v2, the broad phase is just dramatically better. On top of that, it puts static or sleeping collidables into a dedicated tree that doesn't require the same frequency of updates and doesn't require self-testing. You can kind of think of it as automatically creating the StaticGroups for you on the fly (and just being an order of magnitude faster by default). There will probably still be some cases where manually batching collidables together will be helpful, but the difference is much, much smaller (and will get even smaller when I get time to do another pass on the broad phase).

KakCAT
Posts: 32
Joined: Mon Apr 14, 2014 2:08 pm

Re: [V1]Performance question (lots of static boxes versus mesh)

Post by KakCAT » Wed Sep 18, 2019 8:29 am

Hi Norbo, thanks for the answer.

I read some cryptic message on twitter about food poisoning. I hope you're feeling better!

My StaticMeshes for my 'Patch2d' are supposed to be "fully static" so no realtime reconstruction is needed, which makes them better.

The StaticGroups (I didn't know about them) sounds very good and easy to integrate into my workflow. Sometimes I have a house which is formed by 30~40 cubes. The house is batched to avoid 30~40 different drawcalls, converting the same boxes into a StaticGroup should be a breeze and should heavily reduce hundreds of broad phase checks. I probably won't need to create a StaticMesh for the whole level with that.

Thanks again!
Kak

Norbo
Site Admin
Posts: 4895
Joined: Tue Jul 04, 2006 4:45 am

Re: [V1]Performance question (lots of static boxes versus mesh)

Post by Norbo » Wed Sep 18, 2019 6:49 pm

I read some cryptic message on twitter about food poisoning. I hope you're feeling better!
I am, thanks! Rolled the dice and got a pretty mild version of whatever-that-was, fortunately.

Post Reply