Front
A moving edge, a rectangle or a lobed ring, as the level the dither reads.
- Drawn with
- GLSL + CPU
- Chain
- front → pixelate → sparks → ordered → palette
- Code
- @forgeron/shaders: frontMeta, frontGlsl, frontCpu
/01 → What it is
- Writes a distance to the edge and a life; `sparks` reads them for the embers.
- A rectangle closing onto a band, or a lobed ring from the centre, in both directions; looping, or driven by the page (`driven`, then `set({ progress })`).
- Both sides: GLSL and CPU, with the same result.
- CPU against GLSL: tolerance 3 % of pixels (measured 0 to 0.014 %): the distance is float.
/02 → In the examples
| Example | Chain |
|---|---|
| Frame burn | front → pixelate → sparks → ordered → palette |
| Lobed burn | front → pixelate → sparks → ordered → palette |
/03 → Versions
- /01 Live
every setting, on "sparks" - /02 Lobed
shape "lobed" - /03 Opening
direction "open"
/04 → Use it
{
"type": "front",
"shape": "rect",
"direction": "close",
"progress": 0.5,
"cycle": 0,
"hold": 0.9,
"driven": false,
"ring": 4,
"left": 0,
"top": 0.33,
"right": 1,
"bottom": 0.67,
"outside": "page",
"grow": 3,
"amp": 0.18
}import { frontMeta, frontGlsl, frontCpu } from "@forgeron/shaders";
// frontMeta: description and params schema (validation, the editor)
// frontGlsl: the GPU side, for bindChain then glPipeline
// frontCpu: the CPU side, for bindChain then runCpu{
"$schema": "https://shaders.forgeron.sh/schema/preset.v1.json",
"version": 1,
"name": "sparks",
"source": {
"type": "front",
"shape": "rect",
"direction": "close",
"cycle": 4.2,
"hold": 0.9,
"ring": 4
},
"passes": [
{
"type": "pixelate",
"size": 4
},
{
"type": "sparks",
"tick": 0.18,
"fly": 0.003
},
{
"type": "ordered",
"matrix": 4,
"centered": false,
"origin": "top",
"steps": [
[
0,
1
],
[
1.5,
0
],
[
2.5,
0
],
[
3.5,
0
]
]
},
{
"type": "palette",
"tones": [
{
"var": "--bg",
"fallback": "#0a0a0a"
},
{
"var": "--line",
"fallback": "#2b2b2b"
},
{
"var": "--ink",
"fallback": "#ededed"
},
{
"var": "--accent",
"fallback": "#ff4f1f"
},
{
"var": "--danger",
"fallback": "#ff6b81"
}
],
"transparent": []
}
]
}import { builtInPresets } from "@forgeron/shaders";
import { mountPreset } from "@forgeron/shaders/dom";
// WebGL2: every step has GLSL. Validated first.
const handle = mountPreset(canvas, builtInPresets()["sparks"]);
// 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()["sparks"]), 320, 200, { time: 1.7 }));API → Options
| Option | Type | Default | Description |
|---|---|---|---|
shape | "rect" | "lobed" | "rect" | A rectangle closing onto a band, or a lobed ring from the centre. |
direction | "close" | "open" | "close" | Burn the picture away, or let it in. |
progress | number | 0.5 | Progress, 0 to 1. |
cycle | number | 0 | Seconds per run; 0 holds the progress. |
hold | number | 0.9 | Seconds held. |
driven | boolean | false | Progress comes from the page (the input set while it runs). |
ring | number | 4 | Cells per ring. |
left | number | 0 | Closes onto: left (rect). |
top | number | 0.33 | Closes onto: top (rect). |
right | number | 1 | Closes onto: right (rect). |
bottom | number | 0.67 | Closes onto: bottom (rect). |
outside | "page" | "keep" | "page" | Cover what lies outside the edge, or leave it to the page. |
grow | number | 3 | Ring growth, cells (lobed). |
amp | number | 0.18 | Lobe depth (lobed). |