Glow
A dithered halo around the ember cells, as Blueprint's glow.
- Drawn with
- GLSL + CPU
- Chain
- field → pixelate → ordered → glow → grid → palette
- Code
- @forgeron/shaders: glowMeta, glowGlsl, glowCpu
/01 → What it is
- On tone indices before the palette: the share of glowing cells around a cell, through a binomial kernel of `radius`; the ember of a field sits inside ink, so the halo covers both.
- Separable: a horizontal then a vertical sum, two stages on the GPU.
- Above the Bayer threshold, a background cell takes the halo's tone: whole pixels, never a blur.
- Both sides: GLSL and CPU, with the same result. A neighbourhood pass.
- CPU against GLSL: exact: whole sums over a power of two, 0 pixels differ.
/02 → In the examples
No example uses it yet: only its own built-in preset.
/03 → Versions
- /01 Live
every setting, on "glow" - /02 Wide
radius 4, strength 5, matrix 8
/04 → Use it
{
"type": "glow",
"tones": [
2
],
"over": [
0
],
"tone": 2,
"radius": 2,
"strength": 1.5,
"matrix": 4
}import { glowMeta, glowGlsl, glowCpu } from "@forgeron/shaders";
// glowMeta: description and params schema (validation, the editor)
// glowGlsl: the GPU side, for bindChain then glPipeline
// glowCpu: the CPU side, for bindChain then runCpu{
"$schema": "https://shaders.forgeron.sh/schema/preset.v1.json",
"version": 1,
"name": "glow",
"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": "glow",
"tones": [
2
],
"over": [
0,
1
],
"tone": 2,
"radius": 2,
"strength": 3,
"matrix": 4
},
{
"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()["glow"]);
// 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()["glow"]), 320, 200, { time: 1.7 }));API → Options
| Option | Type | Default | Description |
|---|---|---|---|
tones | number[] | [2] | Tones that glow. |
over | number[] | [0] | Tones the halo may cover. |
tone | number | 2 | Tone of the halo. |
radius | number | 2 | Reach, in cells. |
strength | number | 1.5 | Density. |
matrix | 2 | 4 | 8 | 4 | Bayer matrix. |