Shaders / Examples / Frame burn

Frame burn

A rectangle of fire that closes onto a band, or opens out of it.

Drawn with
WebGL
Chain
front → pixelate → sparks → ordered → palette
Code
@forgeron/shaders: builtInPresets()["burn-frame-close"]
front source ·
/01 → What it is
  • A rectangle closes from the whole frame onto a band; outside it the page. Run backwards, the band opens out to the whole frame and lets the picture in.
  • Across the front, a two-ring fringe dithered by the 4×4 Bayer matrix in 4 px cells: outer ring 5 cells of 16 left, inner 11.
  • Embers along the four edges on a slow tick: white hot, ember and red. Here a globe field stands in for the site's village.
/02 → Where Forgeron uses it
SiteWhereSettings
forgeron.shHome, the end of the story: the village burns onto the hero bandburn-frame-close · driven by the scroll
GalleryThis page: the open directionburn-frame-open · not yet on a site
/03 → Versions
  • front source ·
    /01 Liveevery setting of its front source
  • /02 Openthe picture is let in from the band
/04 → Use it
/01 → Driven by the page (the scroll, a clock)
import { builtInPresets } from "@forgeron/shaders";
import { mountPreset } from "@forgeron/shaders/dom";

// Progress comes from the page: the preset redraws when it is set.
const preset = builtInPresets()["burn-frame-close"];
const handle = mountPreset(canvas, { ...preset, source: { ...preset.source, driven: true } });
addEventListener("scroll", () => handle?.set({ progress: scrollY / innerHeight }));
/02 → Preset "burn-frame-close" (builtInPresets())
{
  "$schema": "https://shaders.forgeron.sh/schema/preset.v1.json",
  "version": 1,
  "name": "burn-frame-close",
  "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": "--bg",
          "fallback": "#0a0a0a"
        },
        {
          "var": "--ink",
          "fallback": "#ededed"
        },
        {
          "var": "--accent",
          "fallback": "#ff4f1f"
        },
        {
          "var": "--danger",
          "fallback": "#ff6b81"
        }
      ],
      "transparent": [
        1
      ]
    }
  ]
}
/03 → 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()["burn-frame-close"]);
// later: handle?.destroy();
/04 → 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()["burn-frame-close"]), 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).
ticknumber0.18Seconds per draw.
offsetnumber6Ember depth, cells.
wobblenumber1Wave amplitude, cells.
densitynumber0.5Chance, nearest layer.
falloffnumber0.07Chance lost a layer.
flynumber0.003Flying spark chance.
reachnumber10Flight distance, cells.
tonesnumber[][2,3,4]Levels written: outer, middle, inner.