skatehumor said:
@joej I too think BVHs would be best suited for this use case. From what I understand they can start to become inefficient if BVs are updated frequently and the tree starts to become unbalanced (since after all you want some sort of balanced tree guarantee otherwise I'd just be traversing the entire list of nodes on every raycast). They also suffer when nodes are very distanced and the BVs start to become large and sparse I think. In any case it'll probably be worth a shot as opposed to a full blown Octree approach.
Yeah, that's all somewhat true but it rarely matters so much. It would matter if you wanted to do a ray traced game, but likely you want stuff like ‘find all objects intersecting this box’ for most, and here tree quality is not so important. I mean, what we want is better time complexity of log(n), and we get this no matter what exact tree we use. All this talk about ‘what's the absolute fastest and coolest acceleration structure’ comes form improving some details, which after that is all that's left to discuss and research further. But it is also a form of nitpicking after the largest profit has already been taken by using just ‘some tree’ (no matter how we call it).
There's infinite details, but it all depends on application and data. If i would write a paper about some new fancy BVH, likely i can beat all the previous methods. Within my specific test case and implementation : )
To give an example, there always were a lot of worries realtime RT would never work because ‘building acceleration structures is too slow’. But that was never true - the simple idea to rebuild TLAS per frame but only refit BLAS as used now in DXR was always known to solve this, even decades ago. Many people were just unaware. The cause is probably the wide adoption and success of quad and octree, which do not support refitting. Games often were about grids, so those structures became the natural first choice for game developers. There's a lot of related confusion, bad tutorials, or even the constant suggestion of ‘trees are not cache efficient and modern HW is super fast, so you are better off doing brute force’ (which is often true ofc.).
But we can make some general statements, to make the choice easy, mostly:
Octree is good if your data is grid aligned cubes, or points with no volume. E.g. Minecraft or particles.
Loose octree is good if objects have different size and volume.
BVH is a generalization over loose octree, removing the dependency on global grid (and the constraint to have exactly 8 children). Thus we can do refitting, making it friendly for realtime update. Ofc. refitting only makes sense if objects stay connected (character skeleton), but it makes less sense for particles which move in all directions independently.
We can even decide to enlarge initial bounds so they bound all animation of a character. This way we do not even need refitting - just transform the tree without any dependencies between levels of the tree - super fast tree update, but slower tracing and queries.
But we always need to rebuild the top levels, because even characters behave like particles if we look at many of them from some distance. Usually that's no problem because we don't have that many dynamic objects. This TLAS rebuild so solves the problem of ‘bad quality trees’.
The free branching factor also helps to tune for best performance and compromise between cache efficient brute force and work efficient tree. E.g. you could decide each node can have 64 children instead just 4 or 8. This means fast iteration of objects in linear memory (if they are sorted to node order), and significantly reducing the number of tree levels to fight cache misses.
Typical downsides of BVH vs. octree:
Need to visit multiple children for a point query, because child bounds may overlap.
Need to test all children if you want to process them in front to back order, e.g. raytracing or occlusion culling.
Need to iterate nodes twice when building - once to find dimension and child count for the new nodes, a second time to sort the objects in.
But those downsides vanish if we have objects of variable size and would so choose a loose octree.
I think BVH is now standard for both collision detection and ray tracing almost everywhere.