Feature Library

Grown spruce: an evergreen grown from a seed on the GPU, ready to dress

4.58 GPU · 0.36 CPU ms
A still of the Grown spruce: an evergreen grown from a seed on the GPU, ready to dress demo
Still
The live demo starts when it’s in view.Grow from seed (a whorl every spring) · new seeds · the season, fresh snow, wind and the hour · dress the tree · drag to turn round the hillside · Look closer

The HaTac engine’s foliage, lifted out whole in raw WebGPU: a spruce grown from a seed and a plant recipe.

A CPU planner lays out its whorls up the leader and gives every limb a contiguous range of wood; compute shaders grow the limbs with their droop and alternating side shoots, scatter needle sprays over the shoots (a cone of soft shoots round the leader for a straight green tip), add up their area in a grid and bake the crown’s light along four slanted beams, so any turned copy picks its own sun from one bake. All of it advances a budgeted slice a frame. One grown crown is shared by any number of placements; wind sways leader and limbs in the scene and the shadow casters alike; seasons bring a bright spring flush and snow on the tops of the whorls; distance drops side shoots and thins and widens the sprays. Once grown, the crown gives anchors to dress it by: every branch tip whorl by whorl in order round the trunk (with a free-hanging cap point), spaced points on its shell with outward normals, and a seat on the bud, on the CPU and in a GPU buffer, with the wind function to move ornaments with the wood. A small host draws it on a page with no engine; the demo grows a hillside of spruces from seedlings to a dressed tree under sky-atmosphere’s sky, a whorl a spring.

What it costs a frame

4.58 ms
0.36 ms
GPU
4.58 ms
CPU, median
0.36 ms
CPU, 95th pct
0.57 ms
Draw calls
0
Weight
Heavy

Measured 28 November 2026 on RTX 4060 Laptop, 13th Gen Intel(R) Core(TM) i9-13900H, Chrome 158, 1920×1080 at 1×. 600 frames × 3 rounds, median kept (rounds ranged GPU 4.50–4.65, CPU 0.33–0.36 ms). What ran: Alone: one eight-metre spruce (the module’s spruce-tall example, 21,000 needle sprays) grown to full before the measured frames, turning slowly on the module’s own host with 4× multisampling (alpha-to-coverage needles), its ground shade on a floor disc, wind on. Phones: tiers are being measured next.

How steadily it runs on RTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference

Typical frame ?
16.83 ms
1% low ?
55 fps
Varies by ?
±0.48 ms
All metricsRTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference
p50p95p9916.02 ms18.09 ms +
How long each frame took. Most frames sit in the tall bars; a long tail to the right is hitching.

Frames run on a 60 Hz timer (a page demo), so most frames take about one tick, 16.7 ms: the spread around it is what matters.

Frames

Median (p50) ?
16.83 ms
p95 ?
17.78 ms
p99 ?
18.04 ms
Slowest ?
18.20 ms
Mean ?
16.87 ms
Standard deviation ?
0.48 ms
1% low ?
55 fps
0.1% low ?
55 fps
Hitches ?
0 of 600
Over budget ?
0 of 600

Main thread

Long tasks ?
0
Long frames ?
0
Event-loop delay ?
0.1 / 0.6 / 0.8 ms

Input

No input during this run.

Memory

JavaScript heap ?
36.8 → 36.0 MB
Growth ?
-0.86 MB

Browser

JavaScript a frame ?
0.43 ms
All tasks a frame ?
0.99 ms
Layout / style ?
0.00 / 0.00 ms
Main thread busy ?
6%

Garbage collection

Collections ?
3 (3 minor, 0 major)
Pauses ?
4.8 ms in all, longest 1.8

What it needs

Renders with
WebGPUNeeds WebGPU: current Chrome and Edge, Safari 26+, Firefox 141+ on Windows.
Your browser
Checking…Looking for WebGPU
Depends on
NothingNo other packages
With an agent
install("grown-spruce")Your coding agent reads its pitfalls and installs it through the library’s MCP server. Set it up

What it’s for

  1. Conifers in a game or a configurator, grown from a seed and a small JSON recipe instead of modelled
  2. A forest or a stand of hundreds of spruces that share a few grown crowns, each turned and scaled, with distance detail
  3. A dressed festive tree: baubles on the branch tips, lights on the crown, a star on the bud, all moving with the wood in the wind
  4. Seasonal scenes and time-lapses: the spring flush of new tips, snow on the whorls, a tree growing a whorl a year
  5. A garden or tree-farm planner where people pick a seed and a height and see the tree they will get

Pitfalls, in brief

  1. The demo needs WebGPU: the spruce is grown by compute shaders into storage buffers and drawn from them, and the demo’s sky, ground and shadow map are passes of their own.
  2. Call encode once per submitted frame until phase is full, and submit between slices: the dispatch origin is a uniform written for the slice, so two slices of the same tree in one command buffer both read the last one.
  3. Nothing is drawn until the tree is full: draw() returns while it plans, grows, places sprays, bakes and reads its twigs back.
  4. Changing the crown light’s resolution (setQuality with a new bakeResolution) re-places every spray and bakes again: the tree vanishes for those frames, about a dozen at the default allowance.
  5. Map the twig readback on the frame after its copy, never in the same one: mapping before the copy is submitted makes it unavailable to the GPU.
11 more in brief
  1. Below about 1.4 m, place a 1.4 m crown smaller rather than grow a smaller recipe: the needle sprays are sized for a tree (0.3 m), so a 0.3 m recipe is a ball of cards, and the plant kind refuses heights under 1 m.
  2. One grown crown, many placements: share the recipe (and the pipelines, createFoliagePipelines once per target format and sample count) between every tree that may look alike; each new recipe costs its own buffers and growth.
  3. The crown shades itself through its baked light, and the cascades shade the ground, but the needles never sample a shadow map: a tree standing in another’s shadow, or under cloud, keeps its own sunlit side.
  4. Carry the crown’s light in its own frame: the bake is four slanted beams in the crown’s space, and a turned placement picks its sun from them; turning a copy never needs a new bake.
  5. Sample the wind at the twig, before adding a hook: an ornament moved by the wind at its own position swings out of phase with the twig in a close-up.
  6. Choose the seed and the shell spacing before saving ornaments by index: changing either moves anchors to other twigs.
  7. Shortening the leader’s whorls keeps the lower crown’s spray indices (a modulus over the shorter wood would reshuffle the needles of the whole tree); thinning keeps a stable random prefix, so distance removes sprays everywhere evenly, never whole whorls.
  8. Detail levels switch with no fade: past lodDistance (scaled by the placement’s size) a tree drops its side shoots to four-sided tubes and keeps 32% of its sprays, widened, and past 2.5 times that 12%.
  9. Draw the ground shade (draw mode ground) only where the ground is level with the tree’s foot, after the ground: it is a flat quad.
  10. Bind the current particle-light buffer when drawing (the particleLights option is read every draw): a particle system can replace its buffer on a resize.
  11. Single-sampled targets get a hard alpha cut (0.36); multisampled ones alpha-to-coverage with coverage lifted in the smaller mips.
16 pitfalls in full, the hook-up guide, the module source and its tests come with the part.

Where it comes from

From HaTac. Adapted from published work, named below.

Hannes Andersson: The HaTac engine’s foliage module, plant recipes and decisions (built for his game and proven there), and the library’s gpu-foliage it was adapted from; the library’s host and demo.

H. Honda, “Description of the form of trees by the parameters of the tree-like body” (1971); P. Prusinkiewicz and A. Lindenmayer, The Algorithmic Beauty of Plants (1990): The whorled, parameter-driven branching the planner follows: tiers of limbs up a leader, each with its own length, angle and droop.

treesspruceconiferevergreenchristmas treefoliagevegetationforestproceduralgrown from a seedwhorlsphyllotaxisneedle sprayscomputegpu growthbudgetedtime-slicedcrown lightlight volumeself-shadingtranslucencywindseasonsspring flush

Near it in the frame