Shaders / Primitives / Dissolve

Dissolve

Cells switch to one tone in Bayer order: a pixel transition, never a fade.

Drawn with
GLSL + CPU
Chain
field → pixelate → ordered → dissolve → palette
Code
@forgeron/shaders: dissolveMeta, dissolveGlsl, dissolveCpu
dissolve pass ·
/01 → What it is
  • As the progress grows, the cells whose Bayer threshold is under it take `tone`; with `cycle` the progress goes there and back.
  • Dissolve into a transparent tone and the page under the canvas shows through: the Transition example.
  • Both sides: GLSL and CPU, with the same result. A cell pass.
  • CPU against GLSL: exact when held; tolerance 0.5 % of pixels on a cycle (measured 0).
/02 → In the examples
ExampleChain
Transitionfield → pixelate → ordered → dissolve → palette
/03 → Versions
  • dissolve pass ·
    /01 Liveevery setting, on "dissolve"
  • /02 Heldprogress 0.5
/04 → Use it
/01 → In a preset, with its defaults
{
  "type": "dissolve",
  "tone": 0,
  "over": [],
  "progress": 0.5,
  "cycle": 0,
  "matrix": 8
}
/02 → One side per page
import { dissolveMeta, dissolveGlsl, dissolveCpu } from "@forgeron/shaders";

// dissolveMeta: description and params schema (validation, the editor)
// dissolveGlsl: the GPU side, for bindChain then glPipeline
// dissolveCpu: the CPU side, for bindChain then runCpu
/03 → Preset "dissolve" (builtInPresets())
{
  "$schema": "https://shaders.forgeron.sh/schema/preset.v1.json",
  "version": 1,
  "name": "dissolve",
  "source": {
    "type": "field",
    "mode": "field"
  },
  "passes": [
    {
      "type": "pixelate",
      "size": 4
    },
    {
      "type": "ordered",
      "matrix": 8,
      "centered": false,
      "origin": "bottom",
      "steps": [
        [
          0,
          1
        ],
        [
          0.86,
          0.12
        ]
      ]
    },
    {
      "type": "dissolve",
      "tone": 0,
      "over": [],
      "progress": 0.5,
      "cycle": 3,
      "matrix": 8
    },
    {
      "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()["dissolve"]);
// 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()["dissolve"]), 320, 200, { time: 1.7 }));
API → Options
OptionTypeDefaultDescription
tonenumber0Tone taken.
overnumber[][]Tones that may dissolve; none: all.
progressnumber0.5Share dissolved.
cyclenumber0Seconds for a round trip; 0 holds the progress.
matrix2 | 4 | 88Bayer matrix.