Grid
A gap on the right and top edge of each cell.
- Drawn with
- GLSL + CPU
- Chain
- field → pixelate → ordered → grid → palette
- Code
- @forgeron/shaders: gridMeta, gridGlsl, gridCpu
/01 → What it is
- A present pass: it runs last, at output resolution, so the gap is in device pixels.
- Cells under `min` CSS pixels keep no gap.
- Both sides: GLSL and CPU, with the same result. A present pass.
- CPU against GLSL: exact: 0 pixels differ.
/02 → In the examples
| Example | Chain |
|---|---|
| Background | field → pixelate → ordered → grid → palette |
/03 → Versions
- /01 Live
every setting, on "field-ember" - /02 Wide gap
gap 0.3 - /03 No gap
gap 0
/04 → Use it
{
"type": "grid",
"gap": 0.16,
"min": 4,
"tone": 0
}import { gridMeta, gridGlsl, gridCpu } from "@forgeron/shaders";
// gridMeta: description and params schema (validation, the editor)
// gridGlsl: the GPU side, for bindChain then glPipeline
// gridCpu: the CPU side, for bindChain then runCpu{
"$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 |
|---|---|---|---|
gap | number | 0.16 | Share of a cell. |
min | number | 4 | No gap below this many device pixels per cell. |
tone | number | 0 | Tone of the gap. |