Ordered
The Bayer threshold every other shader dithers with.
- Drawn with
- GLSL + CPU
- Chain
- field → pixelate → ordered → grid → palette
- Code
- @forgeron/shaders: orderedMeta, orderedGlsl, orderedCpu
/01 → What it is
- A value becomes a tone index: on when it beats the matrix at that cell.
- 2×2, 4×4 and 8×8, built by one recurrence (`bayer`, `matrix`). `ditherPath` draws it as a static SVG path at build time; `anvilPath` the logo.
- No blur, no alpha: a gradient is a density of whole pixels.
- Both sides: GLSL and CPU, with the same result. A cell pass.
- CPU against GLSL: exact: 0 pixels differ.
/02 → In the examples
| Example | Chain |
|---|---|
| Background | field → pixelate → ordered → grid → palette |
| Title | tone → ordered → reveal → palette |
| Transition | field → pixelate → ordered → dissolve → palette |
| Progress | constant → pixelate → ordered → hatch → hatch → palette |
| Selection | constant → pixelate → ordered → hatch → palette |
| Feedback | constant → pixelate → ordered → ring → palette |
| Frame burn | front → pixelate → sparks → ordered → palette |
| Lobed burn | front → pixelate → sparks → ordered → palette |
/03 → Versions
- /01 Live
every setting, on "field-ember" - /02 4×4
matrix 4 - /03 2×2
ditherPath(64, 16, (x) => x / 63, 2) - /04 4×4
ditherPath(64, 16, (x) => x / 63, 4) - /05 8×8
ditherPath(64, 16, (x) => x / 63, 8) - /06 Anvil, dither
anvilPath(24, "dither") - /07 Anvil, fade
anvilPath(24, "fade")
/04 → Use it
{
"type": "ordered",
"matrix": 8,
"centered": true,
"origin": "top",
"steps": [
[
0,
1
]
]
}import { orderedMeta, orderedGlsl, orderedCpu } from "@forgeron/shaders";
// orderedMeta: description and params schema (validation, the editor)
// orderedGlsl: the GPU side, for bindChain then glPipeline
// orderedCpu: the CPU side, for bindChain then runCpuimport { ditherPath } from "@forgeron/shaders";
// A ramp from left to right, 64 × 12 cells.
const d = ditherPath(64, 12, (x) => x / 63, 8);
<svg viewBox="0 0 64 12" shapeRendering="crispEdges" fill="currentColor">
<path d={d} />
</svg>import { bayer } from "@forgeron/shaders";
// on when the tone beats the threshold of this pixel
const on = tone > bayer(x, y, 8);{
"$schema": "https://shaders.forgeron.sh/schema/preset.v1.json",
"version": 1,
"name": "field-ember",
"source": {
"type": "field",
"mode": "ember"
},
"passes": [
{
"type": "pixelate",
"size": 4
},
{
"type": "ordered",
"matrix": 8,
"centered": false,
"origin": "bottom",
"steps": [
[
0,
1
],
[
0.86,
0.12
]
]
},
{
"type": "grid",
"gap": 0.16,
"min": 4,
"tone": 0
},
{
"type": "palette",
"tones": [
{
"var": "--bg",
"fallback": "#0a0a0a"
},
{
"var": "--ink",
"fallback": "#ededed"
},
{
"var": "--accent",
"fallback": "#ff4f1f"
}
],
"transparent": []
}
]
}import { builtInPresets } from "@forgeron/shaders";
import { mountPreset } from "@forgeron/shaders/dom";
// WebGL2: every step has GLSL. Validated first.
const handle = mountPreset(canvas, builtInPresets()["field-ember"]);
// later: handle?.destroy();import { builtInPresets, chainOf, runCpu, toRgba } from "@forgeron/shaders";
// The CPU side of every step: RGBA bytes for a PNG, or tone paths for an SVG (toSvgPath).
const rgba = toRgba(runCpu(chainOf(builtInPresets()["field-ember"]), 320, 200, { time: 1.7 }));API → Options
| Option | Type | Default | Description |
|---|---|---|---|
matrix | 2 | 4 | 8 | 8 | Side of the Bayer matrix. |
centered | boolean | true | Thresholds at (m + 0.5) / n² instead of m / n². |
origin | "top" | "bottom" | "top" | Row the matrix starts on. |
steps | [offset, scale][] | [[0,1]] | [offset, scale] per tone above the background: tone k when the value passes k consecutive steps. |