Feature Library

Brush tips with world-anchored patterns

0.78 CPU ms
A still of the Brush tips with world-anchored patterns demo
Still
The live demo starts when it’s in view.Paint with a mouse, a finger or a pen · two fingers or the middle button pan · click, then the wheel zooms · 1–5 tips

Five brush tips as pure functions of a point: a soft circle, a square that turns, a ragged edge that tears, a mottled cloud and a speckle of spots.

What it costs a frame

0.78 ms
GPU
not used
CPU, median
0.78 ms
CPU, 95th pct
1.82 ms
Draw calls
0
Weight
Moderate

Measured 13 November 2026 on RTX 4060 Laptop, 13th Gen Intel(R) Core(TM) i9-13900H, Chrome 157, 1920×1080 at 1×. 600 frames × 3 rounds, median kept (rounds ranged CPU 0.73–0.86 ms). What ran: Measured painting by itself: a looping stroke laid at about 25 dabs a frame, cycling through the five tips every 3 s, while the view pans and zooms slowly; the canvas is cleared when it reaches 60 tiles. Idle, nothing is drawn. Phones: tiers are being measured next.

On every machine it was measured on
MachineGPU msCPU msCPU p95
RTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900Hreference · measuring toolnot timed0.781.82
apple · Apple A19 Proin a browser tab · 16 November 2026not timed1.622.24
Intel Arc 140V (Xe2-LPG) · Intel Core Ultra 7 258Vin a browser tab · 15 November 2026not timed0.681.16

Bars against one 16.7 ms frame. A browser-tab run is timed in a visible tab without the tool’s scripted input, so read it as close, not exact.

What it needs

Renders with
Canvas 2DA 2D canvas: every current browser.
Your browser
Runs hereNo WebGPU needed
Depends on
NothingNo other packages

What it’s for

  1. A paint or sketch tool on the web
  2. Terrain, splat-map and ground-material painting in a level editor
  3. Masks with torn or speckled edges (dirt, wear, gravel)
  4. Brushes in a map or diagram editor
  5. A preview under the pointer that matches the dab exactly

Pitfalls, in brief

  1. The pattern must be sampled at the world point, not at the offset from the dab’s centre.
  2. Size the pattern from the brush’s set size (patternRadius), not from each dab’s: pen pressure changes the dab’s radius every few pixels, and a pattern that scales with it no longer lines up between dabs.
  3. The pattern is sized by the brush (patternScale): a big ragged brush tears in big pieces.
  4. Ragged tears where the falloff is weak, so a hard ragged brush (hardness 1) has almost no rim to tear.
  5. Evaluate a dab once per tile it overlaps, in world coordinates, and only over the texels it can reach (brushReach: a square’s corners reach √2 past its radius).
6 more in brief
  1. A preview under the pointer should call the same brushInfluence (or sample the same pattern bytes on the GPU, as the source does) at the same world points; a drawn circle or an icon of the tip lies about what the dab will lay.
  2. Space dabs along the path by distance (a share of the radius), not one per pointer event: a fast mouse leaves gaps and a slow one piles dabs up.
  3. Mouse buttons report a pressure of 0.5 while pressed and many touch screens 0 or 1: read pressure only from pens (pointerType "pen"), or a mouse paints at half strength.
  4. A stroke’s undo is the tiles as they were at its first dab.
  5. End a stroke on lostpointercapture as well as pointerup and pointercancel: an up the canvas never sees leaves the stroke open, and the next mouse move paints with no button down.
  6. patternData builds both patterns on first use (two 128 × 128 passes, a few milliseconds): call it once at load if the first dab must not wait.
11 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.

Mulberry32, by Tommy Ettinger: The small seeded generator that builds both patterns, as in the source (public domain).

brushbrush tippaintingstampdabpatternworld spacetexturenoisevalue noisepen pressurepointer eventsstylustilesinfinite canvaspan and zoomundoterrain paintingno dependencies

Near it in the frame