TechniquesReskin seam for 2D games and visual apps
A contract that lets one simulation wear any number of looks.
What it costs a frame
- GPU
- 0.43 ms
- CPU, median
- 0.69 ms
- CPU, 95th pct
- 1.38 ms
- Draw calls
- 0
- Weight
- Moderate
Measured 15 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 GPU 0.43–0.90, CPU 0.34–0.69 ms). What ran: Measured with Chart on the left and Lantern on the right, both on WebGPU and split half and half: about 300 to 500 instances a side in three layers, the field, the lights, glow and three bloom levels on the right, a stone dropped every 0.45 s so rings bend the field; both sides timed by their own timestamp queries. Phones: tiers are being measured next.
| Machine | GPU ms | CPU ms | CPU p95 |
|---|---|---|---|
| RTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900Hreference · measuring tool | 0.43 | 0.69 | 1.38 |
| apple · Apple A19 Proin a browser tab · 16 November 2026 | 7.50 | 0.96 | 1.54 |
| Intel Arc 140V (Xe2-LPG) · Intel Core Ultra 7 258Vin a browser tab · 15 November 2026 | 1.31 | 0.62 | 0.98 |
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
- WebGPUNeeds WebGPU: current Chrome and Edge, Safari 26+, Firefox 141+ on Windows.
- Your browser
- Checking…Looking for WebGPU
- Depends on
- NothingNo other packages
What it’s for
- A 2D game whose art can be swapped (themes, seasons, an accessibility look, a retro mode) without touching its rules
- One simulation shown in several looks at once: a comparison, an editor preview, a split screen
- A dashboard, map or visual app that draws thousands of marks in one instanced call, with a Canvas 2D fallback that draws the same frame
- Night scenes in 2D: lamps, lanterns and beams that light what is near them, with glow and bloom
- Pixel art from sprites and code-drawn shapes alike, on a coarse grid that keeps every pixel the same size
- Rules that are tested, replayed and networked on their own, because nothing in them draws
Pitfalls, in brief
- The rules must not import anything that draws, and the walk must not change the state.
- Hand the same event list to every view, and drain it once: view.build() reads events, it never empties the rules’ list.
- setSkin() drops the effects in flight: they were made by the old skin’s handlers in its colours.
- Skins animate by the view’s own clock, which only moves in build().
- A palette given to extendSkin() replaces the base’s, and the borrowed draw functions read it: it must carry every slot they use.
11 more in brief
- A WebGPU canvas can never become a Canvas 2D one: getContext() returns null for the second kind.
- Instance sizes are half-sizes, and shapes point along +x before rotation, on both backends.
- The outline of a shape drawn with fill below 1 is 17% of its shorter half-size: right for marks and boats, far too thick on a big rectangle.
- With
pixelset, the lit and glow layers are drawn on a grid of k device pixels per art pixel, k rounded to a whole number so every pixel is the same size. - Canvas 2D cannot tint a sprite without per-pixel work: it draws sprites untinted.
- Canvas 2D leaves out the picture warp, and its bloom is three halvings of the glow canvas scaled back up, close to but softer than the WebGPU backend’s three-level filter.
- A WebGPU device can be lost (a driver reset, a sleeping laptop, another tab’s crash). render() then returns false for good: set onLost (or check lost) and move to createFlatBackend on a canvas of its own, and say so.
- A canvas wider or taller than the device’s maxTextureDimension2D cannot be drawn into. requestGpu() asks for the adapter’s own limit (often 16,384), and the backend draws a larger frame smaller and lets CSS stretch it.
- The light layer multiplies the lit layer only where
lightingis on, and glows are added. - render() returns false while the GPU is still busy with the last frame: keep the frame dirty and draw again next time, or a change is lost.
- The field and the lit layer share a rgba8unorm target: colours above 1 clip there.
Where it comes from
From HaTac. Fully custom code.
Mark Jarzynski & Marc Olano, Hash Functions for GPU Rendering (JCGT, 2020): PCG, the integer hash behind every seeded number in TypeScript and the dither in WGSL.
Inigo Quilez, 2D distance functions: The standard box, regular polygon and triangle distances the shape shader uses, and the gradient-normalised ellipse estimate.


