Enable culling of nodes that have an invalid bounding sphere
Jannik Heller <scrawl@...
2015-11-20 01:21:52 GMT
I noticed that OSG is not culling empty nodes. By "empty" nodes, I mean nodes that do not have a bounding
sphere set, so they're by default set to the invalid bounding sphere. isCullingActive() returns false
for invalid bounding spheres, so these nodes are never culled.
Now you may be thinking who uses empty nodes, just use the optimizer to remove them? Well, for example one
prominent use case is when doing mesh skinning - the bone hierarchy is used in the skinning
implementation, but doesn't usually have mesh children attached to it. In some cases you do attach meshes
to a bone (e.g. a character holding an object in his hand), but most bones are used for skinning only. So the
cull visitor is unnecessarily traversing the whole bone hierarchy, and doing expensive
push/popModelViewMatrix in the process. In my game engine I use skinning a lot and noticed a ~10% speed up
of the cull phase with this patch applied. I imagine other OSG applications that use skinning will see
As well, the previous behaviour was inconsistent because invalid bounding spheres will become valid if
you merge them with a sibling's valid bounding sphere. For example, looking at this graph:
-- Node with valid bounds
-- Node with invalid bounds
If "Node with valid bounds" is culled, then the whole Group gets culled. If "Node with valid bounds" is not
culled, then "Node with invalid bounds" is not culled either. This is inconsistent IMO, because the
culling of a node shouldn't depend upon its sibling nodes.
With this patch applied, "Node with invalid bounds" is now always culled.
I tested this patch in my engine as well as the OSG examples. In particular I tested some nodes that rely on the
CullVisitor (ClipNode and LightSource). All seems to be working.
There is a small risk of client applications breaking from the change if they rely on cull callbacks being
called on nodes that have no bounding sphere. If you think the change is too intrusive, we can introduce it
as an option in osgUtil::CullVisitor that would be off by default. Let me know what you think!
Read this topic online here:
osg-submissions mailing list