I’ve been told that that computeWorldMatrix(true)
becomes expensive in complex scenes. My assumption is that its complexity is based on to how deep the node is in the scene hierarchy: i.e. how many parents contribute to the node’s world matrix. That, if computeWorldMatrix(true)
is called on a node that is a direct, or near, descendant of the scene root, then the computational cost is the same regardless of the complexity of the rest of the scene.
However, I’ve read some things that suggested that there’s more to it. That computeWorldMatrix(true)
may have an effect on other nodes in the scene, making it’s computational cost be based on the entire scene’s complexity, rather than just the node it’s being called on. Perhaps this could be because it sets all parent nodes to “dirty”, triggering re-calculation of their child nodes on the next frame?
Can anyone clear up this uncertainty?
Also, if computeWorldMatrix(true)
does set parent nodes to “dirty”, triggering a lot of recalculations, is there any way to update a node’s world matrix without doing this?
So the first assumption is correct. The cost depends on your descendants only when not forced. No descendant: only cost for the local matrices (which quite a lot already).
When forced the parent will be impacted now and the children during the next render frame.
We do have a lot of cache and countermeasures to reduce the cost but it is still significant.
There is no official way to trigger a wm compute without making it dirty
1 Like
Thank you for this clarification.
We do have a lot of cache and countermeasures to reduce the cost but it is still significant.
It doesn’t sound that bad, though, as long as I organize my hierarchy to keep the nodes that need computeWorldMatrix(true)
near the root, right?
Another clarification, calling computeWorldMatrix(true) on NodeN will have the following impact
- In current frame it will recompute the world matrix on current node and all of its parents, so the complexity is O(d), where d is the depth of NodeN (this aligns with your analysis above)
- On the next frame, when computeWorldMatrix is called default by the render loop, all the children of NodeN will see that the node is not synchronized with its parent, which will force a recomputation of that node (and thus their children will also not be synchronized with their parent) -. Note that if we hadn’t called computeWorldMatrix(true) on NodeN, then its children would skip the recalculation because theyd be syncronized with parent.
So the complexity of forcing recalculation on NodeN increases by # of ancestors (for current frame) and # of descendants (for next frame)
5 Likes