Feature Library

Material bake: recipes to GPU maps, no three.js

1.39 GPU · 0.20 CPU ms
A still of the Material bake: recipes to GPU maps, no three.js demo
Still
The live demo starts when it’s in view.Click a piece, flip through the presets, slide Wear · Drag or arrow keys to turn the view · Look closer

Procedural materials baked on the GPU and drawn in a raw WebGPU app, with no engine and no three.js.

A material is a recipe in the material designer’s format (a base and a stack of layers: noise, cells, tiles, wood, marble, scratches, weave, dents, flakes, scatter, panels with rivets, tread plates and grilles, scales, strata, ripples, drips, derived curvature, painting kernels such as bricks and bolted panels, and whole materials laid over each other). A material set shows every material at once as a stand-in in its mean colour, compiles one layer pipeline for every kind the set uses, bakes one material a frame (one compute pass a layer, then normals, curvature, cavity, horizon occlusion and mips on the GPU) into three compact 8-bit maps, and fades each in. Drawing is one WGSL include: triplanar in each shape’s own space, parallax up close, hex tiling for large surfaces, wear worked out from the shape (bare edges, grime in hollows, dust on top), a palette colour applied as drawn, finishes per object and a style switch (stylized, painterly, flat, toon), all without a bake. A cache keyed by the recipe’s hash keeps the maps for the next start. 39 presets at their real-world sizes, and a small host for a page with no engine: a device, shapes that carry edge data, a lit draw with a shadow and a gallery of material balls.

What it costs a frame

1.39 ms
0.20 ms
GPU
1.39 ms
CPU, median
0.20 ms
CPU, 95th pct
0.33 ms
Draw calls
0
Weight
Moderate

Measured 25 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 1.31–2.45, CPU 0.20–0.37 ms). What ran: Alone: the rounded block wearing worn painted metal, baked once at the tier’s map size before the measured frames, then drawn each frame with its shadow (triplanar reads, wear from the shape, multisampled at 4×) over the studio backdrop. The number is the draw; the bake is reported on the stage. 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.91 ms
1% low ?
55 fps
Varies by ?
±0.48 ms
All metricsRTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference
p50p95p9916.04 ms18.10 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.91 ms
p95 ?
17.77 ms
p99 ?
18.04 ms
Slowest ?
18.12 ms
Mean ?
16.93 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.0 / 0.4 / 0.6 ms

Input

No input during this run.

Memory

JavaScript heap ?
39.5 → 39.2 MB
Growth ?
-0.30 MB

Browser

JavaScript a frame ?
0.26 ms
All tasks a frame ?
0.65 ms
Layout / style ?
0.01 / 0.04 ms
Main thread busy ?
4%

Garbage collection

Collections ?
1 (1 minor, 0 major)
Pauses ?
0.5 ms in all, longest 0.5

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("material-bake")Your coding agent reads its pitfalls and installs it through the library’s MCP server. Set it up

What it’s for

  1. Materials for a raw WebGPU game or tool, from recipes instead of texture files
  2. A whole scene’s surfaces at once: every material shows at once, the maps land one a frame
  3. Worn props and machines: one bake looks right on every shape (edges, hollows, tops)
  4. Recolouring a material per object (team colours, a dress’s palette) with no second bake
  5. One switch from stylized to painterly, flat or toon for every material
  6. A material gallery or picker of balls drawn by the GPU
  7. Baking a material designer’s recipes in an app that ships without three.js

Pitfalls, in brief

  1. The demo needs WebGPU: the bake is compute passes writing storage textures, and the draw is WGSL.
  2. A cold compile costs a pipeline, not a line: on a D3D driver each new pipeline took 1.2 to 1.8 s whatever its size, one after another.
  3. Measure a cold compile with a salt (setMaterialShaderSalt): the GPU driver caches compiled shaders outside the browser profile, so a “fresh profile” run measured 0.1 s for what took 9 s the first time.
  4. Memory: 4 MiB a material at 512² (three rgba8 maps with mips), 1 MiB at 256², and the set’s library is allocated for its whole capacity at once (the demo’s 41 at 512²: 164 MiB).
  5. Nothing waits, so the first frames show stand-ins: each material’s mean colour, roughness and metalness, estimated from its recipe, then its maps fade in over 0.25 s as each lands (one a frame, in the order add() was given first).
16 more in brief
  1. A shader that shades with the set must read nothing for a stand-in: matSurface returns the stand-in before any texture read while the fade is 0, so a waiting surface costs nothing and never shows black.
  2. Wear needs the shape’s own data: matWorn takes an edge value (0 on an edge, 1 a few centimetres onto the face), a hollow value and which way is up.
  3. Wear, tiling, the relief mode, a finish’s glow and motion and the style are drawing values: change them with add() again (same id, same bake key) and nothing bakes.
  4. The palette’s share is a coverage, not a colour: a "palette" colour bakes as white and records how much of the colour it laid; drawn, it is multiplied by the colour you pass for that shape.
  5. A mask’s from is where the layer starts, not where it stops: raising a paint coat’s noise mask from 0.36 to 0.55 to get fewer chips gave more bare metal.
  6. Albedo is stored as its square root (8 bits linear lose dark colours to banding): square it when you read the albedo map yourself.
  7. Pass continuous positions and their screen derivatives (dpdx, dpdy of the point, taken in uniform control flow before any branch) to matSurface: it samples with explicit gradients, and fract() on coordinates or derivatives taken after a branch picks a coarse mip at the joins.
  8. One layer pipeline shares one explicit layout: a pass that leaves its aux maps unread still binds them (auto layouts dropped the unused bindings and the shared bind group failed to validate).
  9. A dispatch may sample one array layer and write another of the same texture, never the same subresource: the merge reads slice 0 and writes slice 1, and the kernels’ blends and remaps need a distinct output slice.
  10. Cache read-backs are 4 MiB each at 512²: the set takes them only after every bake has landed, one every eight frames.
  11. What the presets lose from the designer: frosted glass draws opaque (no transmission), red brick, mossy brick and worn painted metal lose parallax self-shadowing, mossy brick’s moss loses its scattering, woven fabric, leather and toon leaf keep their sheen but lose its roughness, the wet presets are wet through their base values only, and metals read dull without an environment to reflect (the host’s sky reflection is a gradient).
  12. Pass a material’s layer to a shader as an exact integer and convert it with u32(round(x)) (or as a u32): the lift’s host first wrote u32(x + 0.5), and on a D3D backend every odd layer then drew its neighbour’s maps (13.5 rounded to 14, half to even).
  13. Using the kernels on their own (createMaterialKernels): stencils wrap over all N texels (the last and first texel are one sample apart, Sobel and horizon occlusion included); read float32 height with a non-filtering binding and categorical ids with textureLoad; run derive again after editing height, then the tints and mips that depend on it; submit the encoded work before disposing a prepared program (its uniforms must still exist); and budget the arrays at bake resolution (a six-layer 1024² job used 320 MiB).
  14. Fitted faces (matFaceSurface, a recipe’s mapping "structured"): count baked cells, not whole repeats, when sizing a face (a 2.4 m repeat of four columns gives 0.6 m plates, so a 2.3 m face takes four 0.575 m plates), and pass the face’s continuous coordinates and their derivatives so the mip is right across cell joins.
  15. The module’s matSurface was made for machines’ flat faces: on curved shapes its wide three-way triplanar mix ghosts structured patterns (bricks, cells, planks slice into shards along diagonal bands) and its parallax runs on any face one plane dominates, curved or not (bark and crackled ground smear and go to mush on a ball).
  16. The host makes one device for the page: create one set and one renderer on it, dispose the set and the renderer and destroy the device when the page is done.
21 pitfalls in full, the hook-up guide, the module source and its tests come with the part.

Where it comes from

From HaTac. Fully custom code.

Hannes Andersson: The HaTac engine’s material kernels, material build, material set, presets and decisions; the library’s host and demo.

Michael Toksvig, “Mipmapping Normal Maps” (2005): The mips widen roughness by how short the averaged normal gets.

Ben Golus, “Normal Mapping for a Triplanar Shader” (2017): The whiteout blend of the three projections’ normals (draw-wgsl.ts).

Natalya Tatarchuk, parallax occlusion mapping (2006): The parallax march with a secant step between its last two samples (draw-wgsl.ts).

Morten S. Mikkelsen, “Practical Real-Time Hex-Tiling” (JCGT 2022), after Eric Heitz and Fabrice Neyret (HPG 2018): The hex tiling: a triangle grid, an offset and a turn per hexagon, the higher relief on top (draw-wgsl.ts).

Ken Perlin (gradient noise) and Steven Worley (cellular noise): The periodic noise and cells behind most layer kinds, as in material-designer.

materialsprocedural texturestexture bakingcomputewgslraw webgpuno three.jspbrmaterial presetslayer stackrecipestriplanarparallax occlusion mappinghex tilingedge weargrimedustpalettefinishestoonpainterlyflat shadingstyle switchstand-ins

Near it in the frame