I’m happy to announce a new feature coming for Babylon 8 wave (but as usual already there for you to test ;)): GPU Picking
In a nutshell, instead of using the CPU to scan through all the geometries to intersect with the picking ray, GPU Picking is relying on the GPU to create a picking texture. This means rendering the scene with a unique color per mesh and then finding what color is below the mouse.
The main advantage is performance of course.
Sample code:
var picker = new BABYLON.GPUPicker();
picker.setPickingList(spheres);
scene.onPointerObservable.add(() => {
picker.pickAsync(scene.pointerX, scene.pointerY, scene, false).then(mesh => {
if (mesh) {
text1.text = mesh.name;
} else {
text1.text = "";
}
});
});
I like this kind of optimisation (fast picking using custom render pass). Reminds me about some work I did creating some artificial datasets for ADAS, we where rendering ID maps like this, in order to extract object segmentation. Watch out with AA, if by mistake it’s enabled, then the ID map is dead
About the function wrapping this new feature, does it mean that the output is only the mesh ID ? (no pickedPoint)
This is a great new feature. Regarding that pg, would it be possible to expose an onlyBoundingInfo to scene.pick? I modified the prototype in this pg to set it to true, and think it might be a useful option for when exact pick point/faceID aren’t required, and where an inexact pick is acceptable.
In my case (Digital Twin) we have a lot of same objects, mainly chairs and tables (rendered as instances of course) and I was so happy when I started to read this topic because picking is a bottleneck in my app at this time.
To be more precise why I’m a bit sad after reading the GPU picking docs is because we use the vertex colors this way and it’s quite common in games to fake AO as well:
fastCheck is a different parameter and doesn’t do the same thing - that just returns on the first mesh hit - it still iterates through all the triangles though (try it in that pg, it’s much slower).
I integrated most of the feedback and went to change one thing: you have to provide the list of objects everytime. The picker will not try to figure out which object to pick