ThinInstances picking performance on Spheres

Hello,

I’m currently trying to implement ThinInstances in my project, using Spheres as instances (~10.000 instances).

I’ve noticed the scene picking became really slow when enabling ThinInstances picking. Interesting enough, reducing the number of faces on the sphere mesh does seem to increase performance by a lot, so I’m assuming the picking logic does some kind of mesh face iteration.

I’m not sure if this is possible - but is there a way to do a ‘light’ picking logic - in which my ray would just pick the Instance position (that’s all I care about in my picking - the instance position), and not do mesh face iterations?

I’ve put together this PG to replicate the issue: Babylon.js Playground
Reducing the number of segments on the Sphere does give very different results.

Another interesing test to do is to set the numParticles to 10, and the sphere segments to 64, it would still cause a pretty big drop in FPS as well.

Thank you.

It should, as the default picking process is testing at the face level. See https://playground.babylonjs.com/#RC2IAH#1 which has 64000 instances but is still fast nonetheless because the primitive is a cube.

You can do the picking yourself instead of using the default one and enable fastCheck to stay at the bounding box level testing. But doing so you will get wrong results depending on the camera position/rotation and the primitive you try to pick:

You can try GPU picking, see for eg GPU picking demo.

2 Likes

Thank you for the suggestions, @Evgeni_Popov .

In my particular scenario I’m going to try the GPU picking since it also helps me uniquely identify the Instance’s properties, not only based on their position (allows for example to offset the items in a grid layout, while still keeping information to what cell the Instance belongs to).