Hatch
Diagonal stripes of whole cells that drift: the rail of the landing.
- Drawn with
- GLSL + CPU
- Chain
- constant → pixelate → ordered → hatch → palette
- Code
- @forgeron/shaders: hatchMeta, hatchGlsl, hatchCpu
/01 → What it is
- A cell is striped when (x ± y + the drift) mod `period` is under `width`; the area is a rectangle given as shares of the frame.
- In the Progress and Selection examples.
- Both sides: GLSL and CPU, with the same result. A cell pass.
- CPU against GLSL: exact: 0 pixels differ.
/02 → In the examples
/03 → Versions
- /01 Live
every setting, on "hatch" - /02 Selection
period 6, width 1, up
/04 → Use it
{
"type": "hatch",
"tone": 1,
"over": [
0
],
"period": 4,
"width": 2,
"speed": 0,
"direction": "down",
"x0": 0,
"x1": 1,
"y0": 0,
"y1": 1
}import { hatchMeta, hatchGlsl, hatchCpu } from "@forgeron/shaders";
// hatchMeta: description and params schema (validation, the editor)
// hatchGlsl: the GPU side, for bindChain then glPipeline
// hatchCpu: the CPU side, for bindChain then runCpu{
"$schema": "https://shaders.forgeron.sh/schema/preset.v1.json",
"version": 1,
"name": "hatch",
"source": {
"type": "constant",
"value": 0
},
"passes": [
{
"type": "pixelate",
"size": 4
},
{
"type": "ordered",
"matrix": 8,
"centered": true,
"origin": "top",
"steps": [
[
0,
1
]
]
},
{
"type": "hatch",
"tone": 1,
"over": [
0
],
"period": 4,
"width": 2,
"speed": 6,
"direction": "down",
"x0": 0.08,
"x1": 0.6,
"y0": 0.4,
"y1": 0.6
},
{
"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()["hatch"]);
// 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()["hatch"]), 320, 200, { time: 1.7 }));API → Options
| Option | Type | Default | Description |
|---|---|---|---|
tone | number | 1 | Tone of the stripes. |
over | number[] | [0] | Tones the stripes may cover. |
period | number | 4 | Cells between two stripes. |
width | number | 2 | Cells of a stripe. |
speed | number | 0 | Cells per second. |
direction | "down" | "up" | "down" | Lean of the stripes. |
x0 | number | 0 | Left edge of the area. |
x1 | number | 1 | Right edge of the area. |
y0 | number | 0 | Top edge of the area. |
y1 | number | 1 | Bottom edge of the area. |