Shaders / Primitives / Glow

Glow

A dithered halo around the ember cells, as Blueprint's glow.

Drawn with
GLSL + CPU
Chain
field → pixelate → ordered → glow → grid → palette
Code
@forgeron/shaders: glowMeta, glowGlsl, glowCpu
glow pass ·
/01 → What it is
  • On tone indices before the palette: the share of glowing cells around a cell, through a binomial kernel of `radius`; the ember of a field sits inside ink, so the halo covers both.
  • Separable: a horizontal then a vertical sum, two stages on the GPU.
  • Above the Bayer threshold, a background cell takes the halo's tone: whole pixels, never a blur.
  • Both sides: GLSL and CPU, with the same result. A neighbourhood pass.
  • CPU against GLSL: exact: whole sums over a power of two, 0 pixels differ.
/02 → In the examples

No example uses it yet: only its own built-in preset.

/03 → Versions
  • glow pass ·
    /01 Liveevery setting, on "glow"
  • /02 Wideradius 4, strength 5, matrix 8
/04 → Use it
/01 → In a preset, with its defaults
{
  "type": "glow",
  "tones": [
    2
  ],
  "over": [
    0
  ],
  "tone": 2,
  "radius": 2,
  "strength": 1.5,
  "matrix": 4
}
/02 → One side per page
import { glowMeta, glowGlsl, glowCpu } from "@forgeron/shaders";

// glowMeta: description and params schema (validation, the editor)
// glowGlsl: the GPU side, for bindChain then glPipeline
// glowCpu: the CPU side, for bindChain then runCpu
/03 → Preset "glow" (builtInPresets())
{
  "$schema": "https://shaders.forgeron.sh/schema/preset.v1.json",
  "version": 1,
  "name": "glow",
  "source": {
    "type": "field",
    "mode": "ember"
  },
  "passes": [
    {
      "type": "pixelate",
      "size": 4
    },
    {
      "type": "ordered",
      "matrix": 8,
      "centered": false,
      "origin": "bottom",
      "steps": [
        [
          0,
          1
        ],
        [
          0.86,
          0.12
        ]
      ]
    },
    {
      "type": "glow",
      "tones": [
        2
      ],
      "over": [
        0,
        1
      ],
      "tone": 2,
      "radius": 2,
      "strength": 3,
      "matrix": 4
    },
    {
      "type": "grid",
      "gap": 0.16,
      "min": 4,
      "tone": 0
    },
    {
      "type": "palette",
      "tones": [
        {
          "var": "--bg",
          "fallback": "#0a0a0a"
        },
        {
          "var": "--ink",
          "fallback": "#ededed"
        },
        {
          "var": "--accent",
          "fallback": "#ff4f1f"
        }
      ],
      "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()["glow"]);
// 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()["glow"]), 320, 200, { time: 1.7 }));
API → Options
OptionTypeDefaultDescription
tonesnumber[][2]Tones that glow.
overnumber[][0]Tones the halo may cover.
tonenumber2Tone of the halo.
radiusnumber2Reach, in cells.
strengthnumber1.5Density.
matrix2 | 4 | 84Bayer matrix.