Does Hardware Instancing support Collision?

I was distributing some rocks-like object around the ground using hardware instancing, and I want to make them as some kind of obstacles.

Is adding collision to hardware instanced object possible? Adding collision and rigid body to parent object had nothing happening

Hi @Deanies,

Hardware instancing works directly with the GPU to render multiple object instances. That being said that system knows nothing about your scene hierarchy and entity components.

You will have to manually spawn colliders to enable collision/physics. There are two ways that I think that can be done:

  1. The easiest, spawn an entity with a collider/rigidbody component for each instance (and of course without any model/render component).

  2. If you are spawning too many instances and you want to get away with the cost of adding/updating entities: for static colliders you can potentially study the PlayCanvas collision and rigidbody systems and spawn bodies directly in Ammo.js. That will bypass the need to add a separate entity for each instance.

We do something similar in our Uranus Tools for PlayCanvas: Tools - Solar Games

2 Likes

Thanks for the Answer! My project instance lots of objects so second way would be ideal for my project. I will dig into it.

1 Like

@Leonidas For option 2, don’t you think adding static rigid bodies even directly in ammo.js will cause performance issues for as many as 1000 instances?

I am using hardware instancing for 1000 instances and haven’t added collision due to performance fear. Would love to hear your point of view on it.

1 Like

That’s good thinking! Based on our experience it all comes down to the number of unique shapes used, especially when it comes to mesh colliders.

Boxes and especially spheres are super fast, mesh colliders take time to generate and require a lot of memory.

In Uranus Tools we have a special way that allows you to cache shapes based on a scale step. So if we are spawning 1000 random rocks we set random scales to be rounded on a certain step (e.g. 0.5, 0.75, 1.0, 1.25).

From there we create a single collider shape for each scale step and we reuse it for all instances sharing the same scale.

And given that we can spawn thousands of static colliders, even mesh colliders with no issue. I think in our Solar Island demo we may have close to 15-20K static colliders.

Demo available here: Demos - Solar Games

3 Likes

Does ammo use acceleration structures e.g. bvh or octrees? If so a 1000 box colliders shouldn’t make too much of an impact. That said I’m keen to take a look at porting rapier or physx at some point

1 Like