Shaders / Primitives / Front

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
front source ·
/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
ExampleChain
Frame burnfront → pixelate → sparks → ordered → palette
Lobed burnfront → pixelate → sparks → ordered → palette
/03 → Versions
  • front source ·
    /01 Liveevery setting, on "sparks"
  • /02 Lobedshape "lobed"
  • /03 Openingdirection "open"
/04 → Use it
/01 → In a preset, with its defaults
{
  "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
}
/02 → One side per page
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
/03 → Preset "sparks" (builtInPresets())
{
  "$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": []
    }
  ]
}
/04 → Plain DOM
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();
/05 → Static, at build time
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
OptionTypeDefaultDescription
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.
progressnumber0.5Progress, 0 to 1.
cyclenumber0Seconds per run; 0 holds the progress.
holdnumber0.9Seconds held.
drivenbooleanfalseProgress comes from the page (the input set while it runs).
ringnumber4Cells per ring.
leftnumber0Closes onto: left (rect).
topnumber0.33Closes onto: top (rect).
rightnumber1Closes onto: right (rect).
bottomnumber0.67Closes onto: bottom (rect).
outside"page" | "keep""page"Cover what lies outside the edge, or leave it to the page.
grownumber3Ring growth, cells (lobed).
ampnumber0.18Lobe depth (lobed).