Hey team!
I’m pleased to announce a new feature for you folks to test: The BoundingInfoHelper
!
This class is meant to let you tap into the GPU to compute the bounding box of a list of meshes.
As you know, by default, Babylon will update the bounding box on every frame but only by applying the new world matrix, As the bones and the morph targets are applied on the GPU during rendering the CPU has no clue about how to extend the bounding box to take them in account.
That could be a problem for picking for instance, if you want to quickly select a mesh based on its bounding box (same for collisions, occlusions, etc…).
Up to now the only way to get an accurate bounding box was to call mes.refreshBoundingInfo(true, true)
. That function was not something we recommended using on every frame as it could be very slow if your mesh has a lot of vertices.
That’s why we decided to introduce the BoundingInfoHelper
. That class will also update your bounding info but by using the GPU this time.
For WebGL2, it will use a transform feedback shader.
For WebGPU, it will use a compute shader.
Demo:
- WebGL2: Babylon.js Playground
- WebGPU: Babylon.js Playground (babylonjs.com)
On that specific demo, I’ve got the following results:
- CPU: 38ms
- WebGL2: 15ms
- WebGPU: 10ms
so almost a factor of 400% for compute shader!
Doc: Bones and Skeletons | Babylon.js Documentation (babylonjs.com)
Enjoy!