Shaders / Examples / Feedback

Feedback

A click, a success, an error: a ring of pixels, then nothing.

Drawn with
WebGL
Chain
constant → pixelate → ordered → ring → palette
Code
@forgeron/shaders: builtInPresets()["role-feedback"]
ring pass ·
/01 → What it is
  • A ring spreads from the point, bright at birth and dim at the end, switching cells on and off whole.
  • It dies out on its own: nothing to dismiss, nothing left on screen.
/02 → Where Forgeron uses it
SiteWhereSettings
GalleryThis page (not yet on a site)built-in preset
/03 → Versions
  • ring pass ·
    /01 Liveevery setting of its ring pass
/04 → Use it
/01 → Preset "role-feedback" (builtInPresets())
{
  "$schema": "https://shaders.forgeron.sh/schema/preset.v1.json",
  "version": 1,
  "name": "role-feedback",
  "source": {
    "type": "constant",
    "value": 0
  },
  "passes": [
    {
      "type": "pixelate",
      "size": 4
    },
    {
      "type": "ordered",
      "matrix": 8,
      "centered": true,
      "origin": "top",
      "steps": [
        [
          0,
          1
        ]
      ]
    },
    {
      "type": "ring",
      "cx": 0.5,
      "cy": 0.5,
      "speed": 0.45,
      "width": 2.5,
      "start": 0,
      "life": 1,
      "repeat": 3,
      "tones": [
        3,
        2,
        1
      ],
      "matrix": 8
    },
    {
      "type": "palette",
      "tones": [
        {
          "var": "--bg",
          "fallback": "#0d0d0d"
        },
        {
          "var": "--line-strong",
          "fallback": "#3a1708"
        },
        {
          "var": "--ink-dim",
          "fallback": "#8a3508"
        },
        {
          "var": "--accent",
          "fallback": "#ff6a13"
        }
      ],
      "transparent": [
        0
      ]
    }
  ]
}
/02 → 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()["role-feedback"]);
// later: handle?.destroy();
/03 → 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()["role-feedback"]), 320, 200, { time: 1.7 }));
API → Options
OptionTypeDefaultDescription
cxnumber0.5Centre, left to right.
cynumber0.5Centre, top to bottom.
speednumber0.45Width per second.
widthnumber2.5Half thickness.
startnumber0Second it starts at.
lifenumber1Seconds it lives.
repeatnumber0Seconds between rings.
tonesnumber[][3,2,1]Tone per slice of its life.
matrix2 | 4 | 88Bayer matrix.