~/satyajit

three-nanite: Nanite's cluster hierarchy in three.js, rebuilt in this page and checked

mdjsonmcp

2026-11-16 · 23 min · threejs · three-js · webgpu · computer-graphics · gpu-driven-rendering

A 2:49 narrated explainer, drawn in code. Every number and picture in it is this article's own; the sources are below.

› transcript

The top number is every triangle in this scene. The yellow one is how many actually get drawn. Each colour is a cluster of about a hundred and twenty-eight triangles, and each one picks its own detail. Hi, I'm Vertie. This is three-nanite. Let's build its hierarchy, then cut it. Take a few neighbouring clusters as a group. The vertices it shares with other groups are locked. Merge them and simplify to half. The outer border cannot move, so it still meets its neighbours. Split the result into half as many clusters, and repeat until one is left. Here is a small hierarchy, the source clusters at the bottom, each row half the one below. A cluster is drawn when its error, projected to pixels, is small enough, and its parent's is not. Move the camera, and the cut follows it. Fine where the camera is close, coarse far away. Now let each child measure its parent from its own bounds. Siblings disagree, and holes open. Every group carries one error and one sphere. The group's error in mesh units, times a constant from the screen height and field of view. Divided by the distance to the nearest point of its sphere. Siblings share that sphere, so they agree. The article's widget does the same thing. With the shared test, the curve never breaks. Switch to own bounds, and three holes open at once. Back to shared, and they close. So I built the whole hierarchy in the page. Twenty-five rocks, each choosing its own cut. The colour is the level. Raise the threshold, and every rock climbs to coarser levels, until only the top of the hierarchy is left. Thirty-two million triangles in the scene. At one pixel, the cut draws about two hundred and twenty-eight thousand. My crack test found no open edges in any cut. Zoom in, and the clusters near the camera get small. Freeze the cut and pull back. Only what was inside the old view was ever drawn. What makes Nanite fast is the other half. Clusters of triangles under thirty-two pixels go to a compute rasteriser. It writes depth and ids with one atomic, and shades each pixel once, afterwards. Nanite streams pages of groups. three-nanite streams whole levels. And it culls hidden clusters, not just hidden props. WebGL2 has no compute shaders, so none of this is there. So the win is drawing fewer triangles, not cheaper ones. Here the yellow number stays under two million. The hierarchy and its cut work in WebGL2. Cheap pixel-sized triangles still need compute. Group, lock, halve. Share the bounds. And try the demo in the article. Every source is in the full article. I'm Vertie. Bye!

Why read this

Hightop 30%

Rebuilds the cluster DAG and its cut in the page with a crack test, reads the repo against Karis 2021, and separates what it copies from what it can't.

  • Runs in a browser
  • Interactive explanations
  • Original analysis

GPUs, kernels & systemsMITPractitioner tool

How this was scored
Is it new?
1 of 3: An incremental tweak
Can I trust it?
2 of 3: Measures key facts from files, code or configs
Can I run it?
3 of 3: Open, permissive, runs on reader hardware with instructions
Will I understand it?
3 of 3: Mechanism carried by interactives built from real code or data
Can I act on it?
2 of 3: A concrete recipe, numbers or comparison
Will it last?
2 of 3: A reference for a year or more
Does it affect many?
1 of 3: A specialist community
Only here?
2 of 3: A teardown or measurement few others did

Score 71 of 100, ranked 152 of 773 rated articles. Each question is answered 0–3 by hand, and a 3 is rare. How articles are scored

On 15 November apekshik posted "I built Unreal Engine's Nanite System in threejs", with a video of a scene whose counter reads 184,407,248 triangles while the "drawn" counter underneath moves between 67,234 and about 1.79 million. The repository is apekshik/three-nanite, MIT, cloned for this piece at b730aac (15 November).

The first 14 seconds of the post's video. The top counter is the whole scene at full detail, the yellow one is what the frame actually draws; the pastel view colours each cluster (video from @apekshik's post on X).

Two weeks ago I went through three.js's own meshlet pipeline, which shipped in r187 and was also called "Nanite-like". That one has the rasteriser half of Nanite and none of the hierarchy. This one is the reverse, and its author says so in a reply under the post: r187 "still picks detail per object from 6 fixed LODs", while three-nanite "does the other half: per-cluster detail from a crack-free hierarchy, and it runs on WebGL2."

That is a claim I can test without trusting anybody's video. The hierarchy is a data structure and a selection rule. So I read the 490-line runtime and the builder, read the Nanite slides it cites, and then wrote the same structure from scratch for this page: a procedural rock, clustered and simplified into a DAG in your browser, drawn as 25 copies that each choose their own cut every frame. It is further down, behind a button.

apekshik/three-nanite@b730aac · snapshot 2026-11-23

Nanite-style virtual geometry (cluster LOD) for three.js: an offline GLB preprocessor and a WebGL2 runtime that works with stock materials.

stars
84
license
MIT
branch
main
forks
11
open issues
0
source
70.7 kB
commit date
2026-11-15
source by language
JavaScript70.7 kB
lodmeshoptimizernanitethreejswebgl

GitHub REST API, 2026-11-23 — branch, createdAt, description, forks, license, openIssues, pushedAt, stars, topics

Why a mesh needs more than one level of detail per object

A GPU's cost tracks the triangles it is handed, and an engine's budget is set by the screen: 1920 by 1080 is about two million pixels. Brian Karis puts Nanite's goal in one line in the SIGGRAPH 2021 course notes: "there are only so many pixels on screen. Why should we draw more triangles than pixels?"

The usual answer is discrete LODs: four or five decimated copies of each mesh and a switch by distance. The switch is per object, so a long wall or a cliff face is as detailed at its far end as at the foot of the camera. And the switch pops, because a whole object changes at once. The fix people reach for, splitting the mesh into tiles with their own LODs, cracks along the seams wherever two tiles pick different levels.

Nanite's answer is to choose detail per cluster of about 128 triangles, from a hierarchy built so that any mix of levels it allows is watertight.

Clusters, groups and the locked border

The build is a loop, and page 46 of Karis's course notes draws it better than I can:

Three panels. Left: four adjacent clusters of four triangles each, coloured yellow, red, green and blue, labelled 'Pick group of N clusters'. Middle: the same outline as one grey simplified patch, labelled 'Merge and Simplify', with an orange arrow pointing at its outer boundary, 'Boundary unchanged'. Right: the patch split into two clusters, orange and purple, 'Split into N/2 clusters'. Under each panel a DAG: four leaf nodes, then one parent, then two parents each connected to all four leaves.
The build step: group neighbouring clusters, merge and simplify them to half the triangles with the group's outer boundary held fixed, then split the result into half as many clusters. Every new cluster is a parent of every old one in the group (Karis, Stubbe and Wihlidal, Nanite: A Deep Dive, SIGGRAPH 2021, course notes page 46).

Spelled out, as the slides give it and as meshoptimizer's clusterlod.h implements it:

  1. Split the source mesh into clusters of at most 128 triangles.
  2. Group neighbouring clusters. The vertices a group shares with any other group are locked.
  3. Merge each group's triangles and simplify to half, never moving a locked vertex.
  4. Split the simplified triangles into clusters again. Each new cluster remembers the group that produced it; each old cluster remembers the group that consumed it.
  5. Repeat on the new clusters until one is left.

The lock is what makes mixing levels safe. A group's outer edge is exactly the same polyline before and after simplification, so a coarse version of one group meets the fine version of its neighbour without a gap. The price is that locked edges cannot simplify. If the same edges stayed locked at every level they would pile up as dense seams (Karis calls it "dense cruft"). They don't, because the groups are re-formed at every level: an edge on a group border at level 3 is usually inside a group at level 4 and gets simplified there. That regrouping is also why the structure is a DAG and not a tree. In the slide's own example, both new clusters are parents of all four old ones.

Karis groups clusters with a graph partitioner (minimum edge cut, so as few locked edges as possible), and the streaming slides put groups at 8 to 32 clusters. three-nanite's builder uses meshoptimizer's WASM build for the clustering and simplification, and writes its own grouping because the JS build lacks meshopt_partitionClusters: heavy-edge matching on shared boundary vertices, up to about 16 clusters per group. When edge collapse stalls on UV seams it falls back to vertex clustering (simplifySloppy) and doubles the recorded error, as clusterlod.h does.

One rule picks the cut

Each group gets an error when it is built: how far, in mesh units, the simplified triangles can sit from the ones they replaced. At run time that error is projected to pixels from the camera. With a vertical field of view θ\theta, a viewport HH pixels tall and a group bounding sphere of centre cc and radius rr:

epx=e⋅K∥c−pcam∥−r,K=H2tan⁡(θ/2)e_{\text{px}} = \frac{e \cdot K}{\lVert c - p_{\text{cam}} \rVert - r}, \qquad K = \frac{H}{2\tan(\theta/2)}

Subtracting the radius measures from the nearest point the group could occupy, the worst case. Then a cluster is drawn when

epx(group that made it)≤τ  <  epx(group that consumed it)e_{\text{px}}(\text{group that made it}) \le \tau \;<\; e_{\text{px}}(\text{group that consumed it})

for a threshold τ\tau in pixels. Source clusters have no producing group (error zero) and the last cluster has no consumer (error infinite), so each path from the root to a leaf crosses the threshold somewhere. Page 70 of the notes writes the same test as ParentError > threshold && ClusterError <= threshold.

Two conditions make it work, and both are enforced at build time.

The widget below is a hierarchy small enough to draw whole: a curve cut into 32 clusters of four segments, paired and halved five times. Move the camera along it and the cut shifts, fine near the camera and coarse at the far end. Then switch the parent test to "own bounds", where each cluster projects its parent's error from its own sphere instead of the parent's. Siblings at different distances now reach different answers, and holes open where neither the parent nor one of its children is drawn.

In one dimension a pair always becomes one cluster, so the widget's hierarchy is a tree. The rule is the same on a DAG. Recorded, it looks like this: the camera moves right, the threshold goes up to 8 px, and then the switch to own bounds opens three holes at once.

The widget above, recorded while it is driven: shared parent test, then own bounds (three holes at 8 px), then shared again.

A DAG built in this page

The demo below runs the whole thing in your browser when you press the button. It generates a rock (an icosphere subdivided eight times and pushed around by seeded noise: 1,310,720 triangles, or 327,680 on a phone), builds the DAG with meshoptimizer's WASM clusterizer and simplifier, and draws 25 copies of it. Each copy picks its own cut every frame by the rule above.

What it does, in the files under components/articles/three-nanite/:

On my M1 Max, headless Chromium (software WebGL through SwiftShader) built the 1.31M rock in 3,679 ms: 20,683 clusters in 2,566 groups over 15 levels, down to a 78-triangle root. In Node the same build takes about 3 s, and the 327,680-triangle rock about 0.75 s. At the starting view (the demo's frame was 718 by 404 CSS pixels in a 1280-pixel-wide window) the 25 copies hold 32,768,000 triangles, and the cut draws:

τ\tautriangles drawnclustersshare of the scene
0.5 px597,6584,9331.8%
1 px227,5501,8960.69%
2 px74,1706280.23%
4 px25,9202290.08%
16 px4,382450.01%

At 16 px all 25 copies are drawn with 4,382 triangles.

Choosing that cut took 2.2 to 2.7 ms per frame on the CPU, because the flat form tests all 20,683 clusters of every visible copy. three-nanite walks the DAG from the root instead and touches only the groups near the cut; its report puts selection at 0.4 to 1.2 ms for 96 props. The frame times SwiftShader reports say nothing about a GPU, so I don't quote them.

Before drawing anything I wrote a crack test. For 8 camera distances, 4 directions and 5 thresholds it selects the cut, collects every triangle, and counts edges used by only one triangle. The rock is closed, so a crack-free cut has none. All 160 cuts on the 327,680-triangle rock came out at zero open edges and zero monotonicity violations, with up to five levels mixed in one cut. The 1.31M rock passed the same 160. The test did find something else: up to 25 edges in a cut are shared by three or more triangles, which are folds the simplifier leaves at coarse levels. three-nanite's report saw the same thing on its props (up to 608 such edges).

Here is the demo recorded in clusters mode: an orbit, a zoom, then the cut frozen while the camera pulls back, so you can see what was chosen for the close view. Near surfaces got small clusters. Everything outside the old view, whole rocks and the parts of rocks past the frame's edges, was culled by the frustum test and never drawn. There is no back-face or occlusion test, so the far side of a visible rock is still in the cut.

The demo above, recorded in headless Chromium: orbit, zoom, freeze the cut, pull back. The counters are the demo's own; the frame-time line is hidden because a recording on a virtual clock has no meaningful frame time.

And in levels mode, with τ\tau swept from 0.5 to 16 px and back. Blue is the source mesh, warm colours are coarse levels, grey the top of the hierarchy.

Levels mode while the threshold moves. A near rock and a far rock sit at different levels at the same threshold, and one rock spans several levels at once.

What it does not do is most of the list below: no streaming (everything is built and resident), no occlusion culling, no triangle budget, no textures, no visibility buffer or software rasteriser, and the DAG is built at load instead of offline. All levels together hold 2,621,320 triangles, twice the source, and each cluster gets its own copy of its vertices because BatchedMesh copies every geometry into its own range: 1,788,623 vertices for a 655,362-vertex rock.

What three-nanite builds

The repository has two halves.

The preprocessor (src/build.js, three-nanite build model.glb out/) runs in Node on meshoptimizer's WASM. It merges every triangle mesh in a GLB, builds the DAG as above, writes four discrete LODs as a baseline, and lays the file out coarsest level first, so "everything down to level L" is a prefix of each buffer. three-nanite verify runs a brute-force crack test from 7 camera positions at 5 thresholds. On the author's six test props (1.85M to 1.97M triangles each, AI-generated, not in the repo) the build takes 4.1 to 6.5 s and gives about 30,000 clusters in 2,200 groups over 13 to 15 levels, per docs/REPORT.md.

The runtime (src/clod.js, 490 lines, three as the only dependency) is where the trick is. ClodBatch extends THREE.Mesh and sets isBatchedMesh = true, then fills BatchedMesh's private fields (_multiDrawStarts, _multiDrawCounts, _indirectTexture, _matricesTexture) itself. three's renderer takes it for a batched mesh and issues one WEBGL_multi_draw call per asset, and stock materials fetch each range's instance matrix through gl_DrawID. That is why MeshStandardMaterial works unchanged. It is also why the README warns that a later three release can break it: tested on 0.186.1 and 0.187.0. My demo gets the same single call through BatchedMesh's public API instead, at the cost of copying vertices per cluster and paying three's per-instance bookkeeping.

ClodSelector.select() walks the group DAG from the root per instance, with frustum tests on groups and clusters, and the same two-sided test as mine (gF[o + 4] * K > t * d means "still too coarse, refine"). Beside that it has a budget, streaming and occlusion culling, and my demo has none of them:

A field of procedural props, rope knots, fluted columns and boulders, coloured by hierarchy level: the nearest boulders show pink and purple patches among blue, the far props are pale cyan and green.
three-nanite's demo scene coloured by hierarchy level, with its three procedural models (a boulder, a rope knot and a fluted column, 262k triangles each). Levels mix within a single boulder (three-nanite README, docs/images/demo_levels.jpg).

What the 184 million means

The counter in the post is the sum of every prop at full detail; nothing close to that is ever drawn. The report's measured scene is 96 props of two types, 182,548,704 source triangles in docs/bench/igpu.json, and at a 2 px threshold it draws 1.66M to 2.86M triangles between 3 m and 50 m, and 0.25M at 300 m. The video's scene has six prop types and 184,407,248 triangles, and reading frames eight per second through the busiest stretch, the drawn counter peaks at 1,791,044. So "under 2 million" matches the video. It does not hold for every view of the report's own scene, where the 300-frame flight at 2 px runs from 0.88M to 3.31M.

Seconds 17 to 31 of the post: the full field at about 1.0M to 1.79M drawn, then one hoist up close at about 83k to 126k (video from @apekshik's post on X).

The rest of the post holds up against the README, with three softenings:

The half it can't copy

This is the paragraph the post itself gets right: "WebGL2 has no compute shaders, so the win here comes from drawing far fewer triangles, not from making each one cheaper."

A 1 px threshold asks for triangles about one pixel across. A hardware rasteriser is built for bigger ones: it shades pixels in 2 by 2 quads, so a triangle that covers one pixel still pays for four, and Karis lists "pixel quad inefficiencies from dense meshes" among the reasons for Nanite's design. Nanite's answer is in the same slides: clusters whose triangles have edges under 32 pixels are rasterised by a compute shader, which Karis reports as "3x faster than hardware on average". The compute rasteriser does its depth test with a 64-bit InterlockedMax into a visibility buffer, depth in the high bits and the visible cluster and triangle index in the low ones, and materials are shaded afterwards, once per pixel. The demo frame in the talk rasterises 25,041,711 triangles from 199,420 clusters.

WebGL2 has none of that: no compute, no image atomics. The report measured what that costs. On the integrated AMD GPU it used, a PBR material at 1080p cost about 8 ms per million drawn triangles, against roughly 3 ms per million for the full-density mesh, because there most triangles are smaller than a pixel and get rejected before shading. The widget below is the report's single-crate table with my arithmetic on top: screen size, triangles per pixel and the GPU time at that rate.

From 12 m out, every mode in the report draws more triangles than the crate has pixels on screen. At 200 m a 1 px cut still draws 12k triangles for a crate about 11 pixels tall. The DAG cannot go below its root cluster, and the stored error at the top is pessimistic (fallback errors are doubled), so the pixel rule alone never gets far props down to game counts. Nanite absorbs that with the software rasteriser and, for tiny instances, visibility-buffer impostors. three-nanite absorbs it with the budget mode, which on the report's 96-prop scene keeps frames at 6 to 11 ms on that GPU by letting the effective error float as high as 32 px. The cost of that is in the report's own capture:

Two views of the same prop field side by side. On the left, drawn at a fixed pixel threshold, hoists and crates have crisp frames. On the right, under a 300,000-triangle budget, the hoists' thin arms have collapsed into blobs and a concrete barrier is crumpled.
Pixel threshold on the left, a 300k-triangle budget on the right at an effective 11 px: thin parts collapse and textures smear once the coarse levels come from the vertex-clustering fallback (three-nanite, docs/REPORT.md, budget_300k_at_11px.jpg).

WebGPU is where the other half could live, and parts of it already do. three's r187 VisibilityBufferDrawingPipeline, which I read for the meshlets article, has a compute rasteriser for small triangles and a visibility buffer, packing depth and an id into 32 bits for atomicMax because WebGPU core has no 64-bit atomics. It picks detail per object from a flat chain of six LODs. three-nanite's examples/webgpu.html runs the same ClodBatch under WebGPURenderer, where, the report says from reading three's source, the backend loops drawIndexed once per range in JavaScript. The report measured that at 7.5 ms for 2.03M triangles in 17,000 ranges on an RTX 5090, against 5.7 ms in WebGL2: same ballpark, not faster. Nobody has put the DAG and the compute rasteriser in one browser renderer yet.

Nanite, stage by stage

StageNanite (Karis 2021)three-nanitethree r187 meshletsThis page's demo
Clusters128 triangles128 triangles64, padded128 triangles
HierarchyDAG, groups re-formed per level, borders lockedDAG, same recipe via clusterlod.hflat chain of 6 whole-mesh LODsDAG, same recipe, my grouping
Detail chosenper cluster, GPU, BVH over groupsper cluster, CPU DAG walkper object, GPUper cluster, CPU, flat test
Crack-free mixingyesyes, testedno mixingyes, tested
Rasterisercompute for edges under 32 px, hardware abovehardware onlycompute or hardwarehardware only
Visibility buffer64-bit, materials deferredno, forward shading32-bit packingno, forward shading
Occlusiontwo-pass HZB per clusterone pass, whole instances, stale depthoptional HZBnone
Streaming128 KB pages of groups, root page residentwhole levels by HTTP Range, no evictionnonenone, built at load
Budgetnone: chases pixel errorscene-wide triangle budgetnonenone
Data sizeabout 11.4 bytes per input triangle in the talkabout 36 bytes per input trianglesmallbuilt in memory

The data-size row is the one that decides most real uses. A 1.9M-triangle prop becomes about 67 MB of uncompressed hierarchy (25 MB of vertices, 42 MB of 32-bit indices), close to the source GLB's size, which the author also said in a reply. The report's own recommendation for its game was to use the builder as an automatic decimator and keep props at about 60k triangles (about 3 MB each) when the DAG is shipped.

Would I use it

For what it claims, yes. The hierarchy and the cut are right, and they are the part of Nanite that is easy to get subtly wrong: I got zero cracks only because the rule shares the parent's bounds, which the widget above shows breaking in one click. On reality-capture meshes, a few million triangles of photogrammetry per room, per-cluster detail is exactly what you want: the near wall fine, the far corner coarse, no hand-made LODs.

I would not ship it as is for anything that has to run on integrated graphics or in Firefox. Without the software rasteriser, a pixel threshold buys you pixel-sized triangles that the hardware handles badly, so in practice the threshold sits at 4 to 8 px or under a budget, and at that point it is a very good continuous LOD system rather than Nanite. The README says Firefox has no WEBGL_multi_draw, so three falls back to one draw call per cluster, and the library has no other path yet. The private-field BatchedMesh trick will need patching on some future three release. And the files are big.

The next step I'd want is the merge the author suggested himself: this DAG feeding three's WebGPU compute rasteriser. Until then, read the README's "What it does not do" before the video. It says more plainly than the post what is missing.

Cite this article

For attribution, please use the following reference or BibTeX:

Satyajit Ghana, "three-nanite: Nanite's cluster hierarchy in three.js, rebuilt in this page and checked", ai.satyajit.si, November 2026.

bibtex
@misc{ghana2026threenanite,
  author = {Satyajit Ghana},
  title  = {three-nanite: Nanite's cluster hierarchy in three.js, rebuilt in this page and checked},
  url    = {https://ai.satyajit.si/articles/three-nanite},
  year   = {2026}
}
share