In a scene with destructible, deforming meshes, when do you refit a bottom-level acceleration structure instead of rebuilding it, and what quality does a refit lose?
answer
- same tree, new boxes
- correct but slower to trace
- topology change rules out refit
- surface area heuristic
- stagger rebuilds across frames
basics
~20 sRefit when a mesh keeps its triangle list and deforms modestly, like a skinned character: recomputing boxes bottom-up is cheap but keeps the old grouping, so boxes bloat and overlap. Rebuild when topology changes or that bloat makes traces too slow.
solid answer
~50 sA **refit** keeps the tree's nodes and leaf contents and recomputes every box bottom-up from the new vertex positions: one linear pass whose cost does not depend on how far vertices moved. It stays correct, but the grouping was chosen for the old pose, so as triangles travel their boxes grow and overlap and rays visit more nodes. A **rebuild** chooses a new grouping: a high-quality `SAH` build traces best but costs the most, and a fast build sorted along a space-filling curve is cheaper but traces slower. A fracture that adds triangles cannot be refit at all; pre-fractured rigid chunks avoid that by moving only instance transforms. A sound policy refits deforming meshes every frame, tracks a quality metric such as SAH cost against its value after the last build, and rebuilds past a measured threshold, spreading rebuilds over frames.
code
pseudocode · 12 lines-- nodes are stored so that every child has a larger index than its parent
function refit(bvh, positions):
for i from bvh.nodeCount - 1 down to 0:
node = bvh.nodes[i]
if node.isLeaf:
node.bounds = emptyBox()
for tri in node.triangles:
for v in tri.vertexIndices:
node.bounds = union(node.bounds, positions[v])
else:
node.bounds = union(bvh.nodes[node.left].bounds,
bvh.nodes[node.right].bounds)go deeper
Recall that a refit only resizes boxes while a rebuild makes a new tree, and that the refit is the cheaper of the two.
Explain why a refit stays correct but gets slower to trace as a mesh deforms, and why a fracture that adds triangles forces a rebuild.
Lay out a per-mesh policy: refit every frame, measure quality decay, rebuild with a fast builder past a threshold, and spread rebuilds across frames.
Treat dynamic acceleration structures as a content budget: how many deforming or fracturing meshes a scene may hold before chunked rigid destruction becomes the rule.
## Two ways to update a bottom-level structure A bottom-level acceleration structure is a bounding volume hierarchy over one mesh's triangles. When the mesh deforms, for example a skinned character walking or a wall bulging before it breaks, the old boxes no longer enclose the triangles, and the structure must be updated before rays are traced against the new positions. There are two ways to do it. - A **rebuild** constructs a new tree from scratch: it chooses again which triangles group together and where each split goes. - A **refit** (often called an update) keeps the existing tree, with the same nodes and the same triangles in each leaf, and only recomputes the boxes from the new vertex positions, from the leaves up to the root. A refit is one linear pass over the nodes, and its cost does not depend on how far the vertices moved. A high-quality top-down rebuild partitions the triangles again at every level, which costs about `N log N` and needs more scratch memory. ## What a refit keeps, and what it loses A refit is always **correct**: every box still encloses its triangles, so rays find exactly the same hits. What it loses is **quality**, meaning how quickly rays get through the tree. - The grouping was chosen for the pose at build time. If a character crosses an arm over its chest, a leaf that held forearm triangles now sits inside the torso's box, and both boxes grow. - When neighbouring triangles move apart, their shared box stretches across the gap. A wall bulging outward can stretch some boxes across much of the mesh. - Bloated boxes overlap their siblings more, so rays enter more nodes and test more triangles. The trace slows even though the update was cheap. - The common APIs require a structure to be built with an option that allows later updates, which can make it a little larger or slower to trace than one built without it. ## Build quality against build time Builders trade construction time against the quality of the tree. Top-down builders often score a candidate split with the **surface area heuristic (SAH)**: `cost = C_trav + (SA(L) / SA(P)) * N_L * C_isect + (SA(R) / SA(P)) * N_R * C_isect` Here `SA` is a box's surface area, `P` the parent, `L` and `R` the two children, `N_L` and `N_R` their triangle counts, and `C_trav` and `C_isect` the relative costs of a node step and a triangle test. The ratio `SA(child) / SA(parent)` estimates how likely a ray that hits the parent box is to hit the child box as well, for rays spread uniformly in position and direction. | Option | Cost to produce | Trace speed | Typical use | |---|---|---|---| | High-quality SAH build | highest | best | static meshes, built once at load | | Fast build (triangles sorted along a space-filling curve) | low | lower | meshes rebuilt every frame or every few frames | | Refit | lowest, linear | decays as the mesh deforms | skinned meshes between rebuilds | ## Destructible content - **Fracture changes topology.** If a mesh breaks at run time into shards with new triangles, the triangle list changes. A refit needs the same primitives in the same leaves, so it cannot follow, and the mesh needs a rebuild. - **Pre-fractured chunks are rigid.** If the wall is authored as separate chunks that fly apart as rigid bodies, each chunk can be its own instance. Their bottom levels never change; only their instance transforms in the top level move. - **Debris that deforms**, such as bending steel panels, is the expensive case: it needs a refit every frame and a rebuild whenever its quality has decayed. ## A practical policy 1. Build static meshes once with the high-quality option, then compact them. 2. Refit skinned and deforming meshes every frame after their vertices are written. 3. Track a quality metric per mesh, such as the SAH cost after each refit compared with its value right after the last rebuild. 4. Rebuild a mesh with the fast builder when that ratio passes a threshold chosen by measurement, or on a fixed schedule for meshes known to deform heavily. 5. Spread rebuilds across frames, so that fifty deforming meshes never all rebuild on the same frame. When these builds run relative to the rest of the frame's GPU work, on which queue and behind which synchronization, is a GPU submission question. This policy only decides which kind of update each mesh gets.
- How would you decide at run time that a refitted mesh needs a rebuild?Compute a cheap quality score after each refit, such as the SAH cost or the summed surface area of interior nodes, and compare it with the value recorded right after the last rebuild. When the ratio passes a threshold found by measuring trace time on real content, queue a rebuild. Meshes known to deform heavily, such as cloth, can simply rebuild on a fixed schedule.
- Fifty destructible props deform during an explosion. How do you keep their updates from spiking one frame?Refit all of them every frame, because refit is linear and cheap, but rebuild only a few per frame in round-robin order, picking the ones whose quality has decayed most. Use the fast builder for those rebuilds. Props far from the camera can be refit less often or dropped from traced effects, and fragments that become rigid can move to instance-only motion.
- Why build static level geometry with the slowest, highest-quality option?A static bottom level is built once and then traced by millions of rays every frame for the whole session, so any extra build time is paid once while better traversal is paid back every frame. Compacting it afterwards also returns the memory the builder over-allocated.
- A refit produces the same tree a full rebuild would for the new pose.
- A refit can follow a fracture that adds new triangles to the mesh.
- Always use the highest-quality build, even for meshes rebuilt every frame.
- Rigid debris chunks need their bottom-level structures refit while they fly.
- A refit gives wrong hits once the mesh has moved far from its build pose.