Open TP-David opened 6 months ago
vsg::ComputeBounds is not meant to be used on the whole scene graph every frame.
I chose not to implement bounding volumes on all nodes like the OSG does as with modern scene graphs that can contain both compute subgraphs and graphics subraphs, and even the graphics subgraphs may have shaders that move them from their original vertex positions so computation of bounds on the CPU requires extra work to do the equivalent of what the shaders do.
Another factor is most nodes don't actually require culling or make little difference to the end result, and the bounds (vsg::box or vsg::sphere) would consume memory, these two factors actually slow scene graph traversal down. Instead the VSG reserves bounding volumes for CullGroup/CullNode/LOD/PagedLOD and these must be explicitly placed into the scene graph by the developer.
Now these cull nodes all have a bounding sphere associated with them, and the vsg::ComputeBounds by default actually uses them when computing bounds rather than traversing the whole subgraph below them. So while not "caching" the bounding volume it can serve a similar purpose.
You haven't specified why you need/what you use a bounding volume for, it might be that whatever you require can be tackled in different way.
If you really do need to compute the bounds of the whole scene graph then perhaps the new vsg::RegionOfInterst node might be use.
The other alternative is to place a CullGroup/LOD above each of main parts of your scene graph, and if the subgraphs get updated then use ComputeBounds on that subgraph to find out what the new value should be for the cull node. This way the overall scene vsg::ComputeBounds can terminate early by just checking the topmost cull nodes bounds. You also get to leverage the VSG's view furstum/lod culling as part of this as well.
In our application we are calculating bounding volumes every frame/when the camera moves, due to how our scene graph is structured. Moving to VSG from OSG has caused a major slowdown we've discovered.
We've found that the ComputeBounds visitor is not caching bounding volumes, causing them to be constantly re-calculated upon new calls and iterating every triangle in the mesh, unlike OSG.