How does a bounding-volume hierarchy speed up frustum culling of a city with tens of thousands of buildings, and when is a flat array faster?
answer
- three outcomes per node
- fully inside means stop testing
- pass down the planes still straddled
- cache misses vs SIMD over contiguous bounds
basics
~20 sA hierarchy tests a node's bounds once: outside rejects the whole subtree, fully inside accepts it with no further tests, and only straddling nodes recurse with the planes they still cross. A flat SIMD array often wins for moving objects.
solid answer
~50 sGroup nearby buildings into nodes whose bounds enclose their children. Each node test has three outcomes: **outside** any one plane rejects the whole subtree, **inside** all six accepts every descendant without further tests, and **intersecting** recurses. A child only needs to test the planes its parent straddled, so the renderer passes a **plane mask** down the tree; remembering which plane rejected a node last frame and testing it first adds temporal coherence. Spheres are the cheapest bound, boxes fit buildings tighter, and many renderers test a sphere first and a box only if needed. A **flat array** of bounds in structure-of-arrays layout, tested many objects per SIMD instruction across a few threads, is often faster for tens of thousands of objects, and it is far simpler for objects that move every frame, because a tree must be refit or rebuilt and walking it costs cache misses.
code
pseudocode · 19 linesfunction cullNode(node, frustum, mask):
for each plane index p in mask:
d = signedDistance(frustum.plane[p], node.sphere.centre)
if d < -node.sphere.radius:
return // outside one plane: skip the subtree
if d > node.sphere.radius:
mask = mask without p // fully inside this plane: children skip it
if mask is empty:
acceptAllInstances(node) // inside all planes: no further tests
return
if node.isLeaf:
for each instance in node.instances:
if not outsideAnyPlane(instance.sphere, frustum, mask):
accept(instance)
else:
for each child in node.children:
cullNode(child, frustum, mask)
// first call: cullNode(root, frustum, all six planes)go deeper
Recall that a hierarchy groups objects under shared bounds, so one test can reject or accept a whole group.
Walk through the three outcomes, the plane mask a parent passes to its children and the sphere-versus-box trade-off.
Argue from measurements: pointer chasing and refits against SIMD over flat arrays, and a split design with static trees and flat lists of movers.
Decide which culling data layout the engine standardises on, so static and dynamic content follow one documented rule and every new system feeds the same visible list.
## The problem A city level holds tens of thousands of buildings, props and street furniture. Testing every bounding volume against the six frustum planes every frame is simple, but most of the city is behind or beside the camera, and testing those objects one by one is wasted work. A **bounding-volume hierarchy** (a tree whose every node stores a bounding volume enclosing all of its children) lets the renderer reject or accept large groups with one test. The geometric test itself, a sphere or a box against one plane, is ordinary intersection maths; the culling design is what is tested, in what order and with what shortcuts. ## Three outcomes per node Testing a node's bounds against the frustum gives one of three answers: - **Outside**: the bounds are entirely on the outside of at least one plane. Nothing below can be visible, so the whole subtree is skipped. - **Inside**: the bounds are entirely on the inside of all six planes. Everything below is inside too, so every descendant is accepted without a single further test. - **Intersecting**: the bounds straddle one or more planes. The renderer recurses into the children. The second outcome is as valuable as the first: a city block in the middle of the view needs one test, not one per building. ## Plane masks and coherence Because a child's bounds lie inside its parent's bounds, a child is automatically inside every plane its parent was fully inside. The renderer therefore passes down a **plane mask**, a six-bit set of the planes still straddled, and each child tests only those. Deep in the tree, most nodes test one or two planes instead of six. A second trick exploits **temporal coherence**: store, per node, the plane that rejected it last frame and test that plane first this frame. A node that was outside usually still is, and the first test settles it. ## Which bounding volume | Bound | Test cost | Fit | Note | |---|---|---|---| | Sphere | one signed distance per plane | loose for long or flat shapes | rotation-invariant, cheap to update | | Axis-aligned box | a few operations per plane | tight for axis-aligned buildings | must be recomputed when an object rotates | | Oriented box | more per plane | tight for rotated shapes | rarely worth it for culling | A common compromise is to test the sphere first and the box only when the sphere straddles a plane. One trap is conservative rather than wrong: a large sphere just outside a **corner** of the frustum is not entirely outside any single plane, so a per-plane test keeps it. The object is drawn and clipped away. That costs time but never shows an error; an extra test against the frustum's corners or edges can tighten it when the waste matters. ## When a flat array wins Tree traversal chases pointers, mispredicts branches and misses the cache, and a tree must be **refit** (bounds recomputed bottom-up) or rebuilt when its contents move. A flat array of bounds in **structure-of-arrays** layout (all centre x values together, then all y values, and so on) lets one SIMD instruction test four, eight or sixteen objects against a plane, streams through memory linearly and splits trivially across threads. For tens of thousands of objects that is often faster than a tree, and for objects that move every frame it is much simpler. A practical design often mixes the two: 1. a hierarchy built offline for the static city, grouped by spatial proximity so whole blocks are rejected at once; 2. a flat SIMD-friendly list for vehicles, pedestrians and other moving objects; 3. both feeding the same list of visible instances for the next stage, occlusion culling and then submission. The right choice is measured, not assumed: count nodes visited, tests performed and time per frame for both layouts on the real level.
- Why does a per-plane test keep a sphere that lies just outside a frustum corner?Near a corner the sphere straddles two planes without being entirely outside either one, so no single plane rejects it. The test is still conservative: the object is drawn and clipped away. If such cases waste real time, add a test against the frustum's corner points or edges, or use a tighter box.
- How do you keep a culling hierarchy valid when some objects move?Keep static objects in a tree built offline and put moving objects in a separate flat list, or refit the tree each frame by recomputing bounds bottom-up. Refitting is cheap but loosens bounds as objects drift apart, so a tree with many movers needs periodic rebuilding.
- A node fully inside the frustum still needs its children tested.
- A hierarchy is always faster than a flat list of bounds.
- A sphere outside the frustum is always rejected by a per-plane test.
- Children must retest all six planes, whatever their parent's result.
- Moving objects can stay in a static culling tree without refitting.