Shaders / Examples / Progress

Progress

Loading, upload, build: the hatched rail that fills.

Drawn with
WebGL
Chain
constant → pixelate → ordered → hatch → hatch → palette
Code
@forgeron/shaders: builtInPresets()["role-progress"]
hatch pass ·
/01 → What it is
  • The filled part drifts in diagonal hatch, the rest of the rail is a sparse hatch; the area is a rectangle of the frame.
  • The same hatched stripes as the rails of the landing, moving.
/02 → Where Forgeron uses it
SiteWhereSettings
GalleryThis page (not yet on a site)built-in preset
/03 → Versions
  • hatch pass ·
    /01 Liveevery setting of its hatch pass
/04 → Use it
/01 → Preset "role-progress" (builtInPresets())
{
  "$schema": "https://shaders.forgeron.sh/schema/preset.v1.json",
  "version": 1,
  "name": "role-progress",
  "source": {
    "type": "constant",
    "value": 0
  },
  "passes": [
    {
      "type": "pixelate",
      "size": 4
    },
    {
      "type": "ordered",
      "matrix": 8,
      "centered": true,
      "origin": "top",
      "steps": [
        [
          0,
          1
        ]
      ]
    },
    {
      "type": "hatch",
      "tone": 2,
      "over": [
        0
      ],
      "period": 5,
      "width": 2,
      "speed": 8,
      "direction": "down",
      "x0": 0.08,
      "x1": 0.6,
      "y0": 0.4,
      "y1": 0.6
    },
    {
      "type": "hatch",
      "tone": 1,
      "over": [
        0
      ],
      "period": 4,
      "width": 1,
      "speed": 0,
      "direction": "down",
      "x0": 0.6,
      "x1": 0.92,
      "y0": 0.4,
      "y1": 0.6
    },
    {
      "type": "palette",
      "tones": [
        {
          "var": "--bg",
          "fallback": "#0d0d0d"
        },
        {
          "var": "--line-strong",
          "fallback": "#3a1708"
        },
        {
          "var": "--ink-dim",
          "fallback": "#8a3508"
        }
      ],
      "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-progress"]);
// 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-progress"]), 320, 200, { time: 1.7 }));
API → Options
OptionTypeDefaultDescription
tonenumber1Tone of the stripes.
overnumber[][0]Tones the stripes may cover.
periodnumber4Cells between two stripes.
widthnumber2Cells of a stripe.
speednumber0Cells per second.
direction"down" | "up""down"Lean of the stripes.
x0number0Left edge of the area.
x1number1Right edge of the area.
y0number0Top edge of the area.
y1number1Bottom edge of the area.