skip to content

Why do real-time ray tracers split the scene into bottom-level and top-level acceleration structures, and what does each level hold?

level: middleimportance: must knowfreq 42%

answer

  1. split by how often things change
  2. mesh triangles versus placed copies
  3. object space below, world space above
  4. transform the ray, not the triangles
  5. overlapping instance boxes

basics

~20 s

A bottom-level structure holds one mesh's triangles in object space; a top-level structure holds instances, each a transform pointing at a bottom-level structure. Moving objects then rebuild only the small top level, and repeated meshes share one bottom level.

solid answer

~40 s

The split separates work by how often it changes. A **bottom-level** acceleration structure (`BLAS`) is a BVH over one mesh's triangles in that mesh's object space. A **top-level** structure (`TLAS`) is a BVH over **instances**: each holds a transform, a reference to a BLAS and per-instance data such as an ID, a visibility mask and an offset that selects its hit programs. When a ray reaches an instance leaf it is moved into object space by the inverse transform and continues through that BLAS. Rigid motion only changes transforms, so the small TLAS is rebuilt every frame cheaply; static BLASes are built once and shared by every copy of a mesh; deforming meshes refit or rebuild their own. The cost is that overlapping instance boxes send a ray into several trees.

go deeper

for a junior

Recall the two levels and what each holds: one mesh's triangles in the bottom level, placed copies with transforms in the top level.

for a middle

Explain what changes per frame for a moving crate versus a skinned character, and how a ray steps from the top level into one instance's object space.

for a senior

Show judgement on scene layout: when to merge static props into one bottom level, when to split a huge mesh, and how overlapping instance boxes slow traversal.

for a principal

Frame the split as a budget across memory, build time and trace time, and set content rules for instance counts, merging and chunk sizes that keep levels inside it.

## Two levels, two jobs A ray tracer needs a bounding volume hierarchy over the whole scene, but the scene changes every frame in two very different ways. Objects move as rigid wholes (a door swings, a car drives), and a few meshes change shape (a character's skin, a flag in the wind). Rebuilding one hierarchy over every triangle in the level each frame would cost far more than a frame can afford. The **two-level** split, the model the major ray-tracing APIs share, separates the two kinds of change. - A **bottom-level acceleration structure (BLAS)** is a hierarchy over the triangles (or custom primitives) of one mesh, in that mesh's own **object space**. It knows nothing about where the mesh sits in the world. - A **top-level acceleration structure (TLAS)** is a hierarchy over **instances**. Its leaves are placements of bottom-level structures in the world. Some APIs call these primitive and instance acceleration structures; the idea is the same. ## What one instance carries - A **transform**, usually a 3x4 affine matrix, from object space to world space. - A **reference** to the bottom-level structure it places. Many instances may point at the same one. - An **instance ID** that hit programs read to fetch per-object data, such as material parameters. - A **visibility mask** that lets a ray type ignore some instances, for example a shadow ray that skips the first-person arms. - An **offset into the shader binding table**, which selects the programs that handle hits on this instance. - **Flags**, such as treating the instance as opaque so that no any-hit program runs for it. ## How a ray crosses the boundary 1. The ray starts in world space and traverses the top level, testing world-space boxes that bound each instance. 2. At an instance leaf, the ray's origin and direction are multiplied by the inverse of that instance's transform, which puts the ray into the mesh's object space. 3. The ray traverses that instance's bottom level and tests triangles there. 4. Traversal returns to the top level and continues with the next candidate instance, keeping the closest hit so far. Because the direction is transformed but not renormalised, the point at parameter `t` along the world-space ray maps to the point at the same `t` along the object-space ray. Hit distances found in different instances can be compared directly. ## Per-frame update work | What changed this frame | What gets updated | |---|---| | A rigid object moved | its instance transform, then the top level is rebuilt or refit | | An object spawned or was destroyed | an instance added or removed, then the top level is rebuilt | | A mesh deformed (skinning, cloth) | that mesh's own bottom level is refit or rebuilt, then the top level | | Nothing moved (static level) | nothing; the bottom levels were built at load | A top level of a few thousand instances is cheap enough to rebuild every frame, which also keeps its boxes tight. Static bottom levels are built once with the highest-quality settings and are often **compacted** to save memory. A deformed mesh cannot share its bottom level with other copies of itself unless they hold the same pose, so every skinned character carries its own. ## Where the split costs trace speed - **Overlapping instances**: each instance's world box is a box around a rotated object-space box, so a long diagonal beam gets a loose bound. Where many such boxes overlap, a ray enters several bottom-level trees and repeats work. - **Too many tiny instances**: when thousands of small static props are each their own instance, most traversal happens in the top level. Merging clutter that never moves into larger bottom levels usually traces faster. - **One giant mesh**: a single bottom level for a whole level cannot be culled, streamed or rebuilt piece by piece. Splitting it into a few spatial chunks balances this. - **The instance step itself**: moving the ray into each instance's space costs a little per instance entered, which adds up in dense, overlapping scenes. ## Memory The split also saves memory. A forest of 2,000 trees built from three tree meshes needs three bottom-level structures and 2,000 small instance records, not 2,000 copies of the triangles. Level-of-detail variants add a bottom level per variant, still shared by every instance that uses it.

  • A forest uses 2,000 copies of three tree meshes. What do you build, and what changes when wind bends the trees?
    Static trees need three bottom-level structures, one per mesh, plus 2,000 instances in the top level. If wind only sways whole trees rigidly, only instance transforms change. If vertex animation bends branches, each bent tree's geometry differs, so sharing breaks: you either refit per-copy bottom levels, which costs memory and time, or trace a static pose and accept small mismatches between the traced and rasterized trees.
  • Why not give every static prop in a level its own instance?
    Each instance adds a world-space box to the top level and a ray transform whenever it is entered. Thousands of small, overlapping props make rays bounce between many tiny bottom-level trees instead of descending one well-built tree. Merging props that never move into a few spatially compact bottom levels traces faster, at the cost of per-prop culling, streaming and toggling.
  • Why must two characters that share one skinned mesh still have separate bottom-level structures?
    A bottom level stores triangle positions. Skinning writes different vertex positions for each pose, so two characters in different poses have different triangles even though they share a source mesh. Each needs its own bottom level, refit or rebuilt after skinning, while the source mesh's static data can still be shared.

Like a city map that marks 'house type B, rotated thirty degrees, here' instead of redrawing every house: the map is small and quick to redraw when a house moves, while each house type's blueprint is drawn once and reused wherever it is stamped.

  • The top level holds the triangles and the bottom level holds the transforms.
  • Moving a rigid prop means rebuilding its triangle-level structure.
  • Two characters posed differently can share one bottom-level structure because they share a mesh.
  • Traversal transforms every triangle into world space before testing it.
  • Splitting every static prop into its own instance always traces fastest.