010 — Foliage: Alpha Test, Cut-Out Shadows, and 560 Plants on the Steam Deck
Step 18: alpha-tested materials in ARAL, shadows cut to the shape of the leaves, and a Steam Deck measurement with up to 560 plants — 60 fps held, and the cost is in the scene pass, not the shadows
2026-11-16 → 2026-11-17
Until now everything in the reference scene was solid: columns, slabs, rocks. A mountain level needs plants, and plants are made of leaf cards — flat quads whose texture says, pixel by pixel, "leaf" or "nothing". That's alpha test (cutout), step 18. This post covers how it went into ARAL, and above all what it costs on the Steam Deck once there are hundreds of plants on screen.

Alpha test in ARAL
A cutout material is a material that sometimes discards. That one keyword is the whole difficulty: as soon as a
fragment shader can discard, the GPU can no longer decide before shading whether a fragment will write depth, so
the early depth test is lost for that pipeline. Cutout materials therefore get their own path:
- their own queue (
eALPHA_TEST) and a double-sided group in the sort key; - two PBR pipelines, opaque and cutout — opaque materials keep their early-Z;
- dynamic culling, so a double-sided leaf and a single-sided trunk share the pipeline;
- the back of a double-sided material flips its whole tangent frame (N, T and B), as the Khronos reference viewer does. Flipping only the normal would invert the relief of the normal map on the back face.
Shadows in the shape of the leaves (18.5)
The shadow pass had the same problem in reverse: without a discard, each leaf card casts its full quad, and a fern
casts a fan of rectangles. The shadow pipelines were designed for a cutout variant back in devlog 007; it now
exists: shadow_cut reads the UVs and the material's textures, and discards with exactly the same test as the scene
— the sampling function is shared between the two shaders, so a texel that's a hole in the image is a hole in the
shadow.

Alpha blend (glass, smoke) still casts no shadow; that's a separate case.
The test asset
The plants come from one Blender file, foliage_test: a fir, a cliff pine, a dry shrub, dry and green grass tufts,
a fern, and ivy on a rock wall — 14 plants in total once placed in the level. To place them, glTF node names are now
kept in the model, and createInstance(modelId, nodeName, keepLocation, parent) instances one node and its subtree
by name; ProjectO puts each plant on the ground of P0_0 by reading the height under it.
One art fix on the way: the fir needles and the dark leaves had a linear albedo of 0.03, and went completely black at night. They're at 0.11 now, the bark at 0.36.
The Steam Deck measurement
How
Fourteen plants say nothing about cost. ProjectO got --foliage-spam <N>: N sets of plants, the placed one plus N − 1
spread over the P0_0 plaza with a fixed pseudo-random generator, so every run sees exactly the same layout.
--foliage-spam 20 gives 280 plants, --foliage-spam 40 gives 560.
Same protocol as devlog 009: Release Profile build, GPU clock forced high, time of day frozen at 0.40, sun with
3 cascades, MSAA ×4. All values are medians.
The numbers
| zone | no foliage | 14 plants | 280 plants | 560 plants |
|---|---|---|---|---|
gpu.aral.scene | 1786 µs | 1857 | 3368 | 4804 |
gpu.aral.shadow | 479 µs | 488 | 560 | 628 |
| GPU total | 2.86 ms | 2.95 | 4.54 | 6.04 |
CPU frame.work | 0.32 ms | 0.34 | 0.51 | 0.70 |
60 fps held at 560 plants. At 6.04 ms the GPU uses about a third of a 16.7 ms frame.
What it says
- The cost is in the scene pass: about 5.4 µs per plant. Leaf cards overlap — a fir is layers of needles over
layers of needles — and every layer runs the full PBR shader, because the
discardkeeps the GPU from throwing away hidden fragments before shading them. That's overdraw at full price. - Cut-out shadows are cheap: about 0.27 µs per plant, twenty times less. The shadow shader only reads the alpha and writes depth; there's no lighting to pay per layer.
- CPU: +0.4 ms at 560 plants, spread over culling,
scene.updateand command recording. Still not the bottleneck.
A caveat on the resolution
These runs were done in the Deck's desktop mode, and KDE there uses a 135 % scale. The window asks for 1280×800, but the size is taken in logical units: the image ARAL renders is 1728×1080, larger than the screen, which the compositor then shrinks. That's 1.8× the pixels of game mode — and it's why the baseline here is 2.86 ms where devlog 009 measured 2.17 ms.
Since the foliage cost is mostly per-fragment, these numbers are pessimistic. Game mode (gamescope, scale 1) hasn't been measured yet. Whether the window size should be taken in physical pixels under a fractional scale is still to be decided.
What doesn't need doing (yet)
One sub-step was planned "if the image or the measurement asks for it": preserving alpha coverage in the mipmaps.
Today texture() reads mips whose alpha is averaged, so leaves — and their shadows — get thinner with distance. The
measurement doesn't ask for it: the cost is in the overdraw of the scene pass, not in the shadows, and not in the
mips. It stays on the list, for when the image asks.
If foliage ever has to get cheaper, the lever is the overdraw: fewer overlapping layers, or a depth pre-pass so the expensive shading runs once per pixel. At 560 plants and 60 fps, it doesn't have to yet.
Next step
Step 19: fog, by distance and by height. Optional, turned on by the game — a density of 0 switches it off — and it carries the level 2 proof: the P0_0 scene looking better than the Blender capture, from the same angle.