Shaders / Primitives / Constant

Constant

One value in every cell: the ground a pass draws on.

Drawn with
GLSL + CPU
Chain
constant → pixelate → ordered → ring → palette
Code
@forgeron/shaders: constantMeta, constantGlsl, constantCpu
constant source ·
/01 → What it is
  • A flat level; the passes after it (hatch, ring) draw the shapes.
  • The source of the roles that are drawings rather than textures: progress, selection, feedback.
  • Both sides: GLSL and CPU, with the same result.
/02 → In the examples
ExampleChain
Progressconstant → pixelate → ordered → hatch → hatch → palette
Selectionconstant → pixelate → ordered → hatch → palette
Feedbackconstant → pixelate → ordered → ring → palette
/03 → Versions
  • constant source ·
    /01 Liveevery setting, on "ring"
/04 → Use it
/01 → In a preset, with its defaults
{
  "type": "constant",
  "value": 0.5
}
/02 → One side per page
import { constantMeta, constantGlsl, constantCpu } from "@forgeron/shaders";

// constantMeta: description and params schema (validation, the editor)
// constantGlsl: the GPU side, for bindChain then glPipeline
// constantCpu: the CPU side, for bindChain then runCpu
/03 → Preset "ring" (builtInPresets())
{
  "$schema": "https://shaders.forgeron.sh/schema/preset.v1.json",
  "version": 1,
  "name": "ring",
  "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": [
        2,
        1
      ],
      "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()["ring"]);
// 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()["ring"]), 320, 200, { time: 1.7 }));
API → Options
OptionTypeDefaultDescription
valuenumber0.5The value.