collision masks and bullet broadphase

sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

collision masks and bullet broadphase

Post by sparkprime »

Collision masks are a fairly weak but simple method of choosing which objects should collide. The near callback allows a much finer degree of control.

I'm wondering if any of the broadphases make use of the masks to allow more efficient search for collision pairs. E.g. using some kind of SAP where objects that do not collide are not in the same axis list, or keeping different kinds of objects in different lists. I haven't though much about whether these ideas would work, but it seems like the sort of optimisation that one should make if possible.

If this isn't used or isn't workable, there doesn't seem to be any reason to try and use collision masks at all since near callbacks are more powerful.

Any thoughts?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: collision masks and bullet broadphase

Post by Erwin Coumans »

sparkprime wrote:Collision masks are a fairly weak but simple method of choosing which objects should collide. The near callback allows a much finer degree of control.

I'm wondering if any of the broadphases make use of the masks to allow more efficient search for collision pairs. E.g. using some kind of SAP where objects that do not collide are not in the same axis list, or keeping different kinds of objects in different lists. I haven't though much about whether these ideas would work, but it seems like the sort of optimisation that one should make if possible.

If this isn't used or isn't workable, there doesn't seem to be any reason to try and use collision masks at all since near callbacks are more powerful.

Any thoughts?
There are two parts of the problem:
a) search for pairs
b) overlapping pair management (add/remove pairs).

For the search of pairs, Bullet provides several broadphases, in particular btAxisSweep3 and btDbvtBroadphase have been very well optimized. If you think you can improve performance, you are invited to make a contribution.

Masks are used to avoid cost of pair management, adding, searching/sorting and removing potential overlapping pairs.

The collision dispatcher that calls the near callback while iterating over all overlapping pairs, happens later in the collision pipeline. Usage of masks earlier in the pipeline prevent creating of those pairs in the first place.

Hope this helps,
Erwin
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: collision masks and bullet broadphase

Post by sparkprime »

I doubt I can improve any of the broadphases, that area is very well-trodden :)

If I understand what you say correctly, masks (as opposed to filtering via near callback) improve performance not in the broadphase stage (i.e. not in btbvt, axis sweep, etc) but in the next stage - pair management - which is common to all broadphases. The near callback is after the pair management, so it is better to use masks if possible, but not for the reasons I originally thought.

thanks for the clarification
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: collision masks and bullet broadphase

Post by sparkprime »

I think it's not possible to use masks in the SAP broadphase because if:

A collides with B

B collides with C

Then A,B,C either need to be in the same axis list, which is the same as it is currently implemented, or A and C are on their own axis lists and B is duplicated across the two lists which would increase the amount of sort work.

The only time I see it working out is if the graph defined by the "collides with" relation has disconnected regions, but then this could be achieved by having completely separate worlds. Except that separate worlds would not allow dynamics constraints between the "disconnected" bodies, but I can't think of a use case for that.