Shaders / Primitives / Field

Field

The four generator fields of forgeron.sh: ember, globe, dissolve, field.

Drawn with
GLSL + CPU
Chain
field → pixelate → ordered → grid → palette
Code
@forgeron/shaders: fieldMeta, fieldGlsl, fieldCpu
field source ·
/01 → What it is
  • A value per cell from fractal noise: heat from the bottom edge (ember), a lit sphere turning (globe), bands eaten from the left (dissolve), a quiet drift (field).
  • Then `ordered` thresholds it with the 8×8 Bayer matrix: whole pixels, never a blur.
  • The site mounts the same chain compiled at build time (`field.baked.ts`).
  • Both sides: GLSL and CPU, with the same result.
  • CPU against GLSL: within a stated share: the noise is float.
/02 → In the examples
ExampleChain
Backgroundfield → pixelate → ordered → grid → palette
Transitionfield → pixelate → ordered → dissolve → palette
/03 → Versions
  • field source ·
    /01 Liveevery setting, on "field-globe"
  • /02 Embermode "ember"
  • /03 Dissolvemode "dissolve"
  • /04 Fieldmode "field"
/04 → Use it
/01 → In a preset, with its defaults
{
  "type": "field",
  "mode": "ember"
}
/02 → One side per page
import { fieldMeta, fieldGlsl, fieldCpu } from "@forgeron/shaders";

// fieldMeta: description and params schema (validation, the editor)
// fieldGlsl: the GPU side, for bindChain then glPipeline
// fieldCpu: the CPU side, for bindChain then runCpu
/03 → Preset "field-globe" (builtInPresets())
{
  "$schema": "https://shaders.forgeron.sh/schema/preset.v1.json",
  "version": 1,
  "name": "field-globe",
  "source": {
    "type": "field",
    "mode": "globe"
  },
  "passes": [
    {
      "type": "pixelate",
      "size": 4
    },
    {
      "type": "ordered",
      "matrix": 8,
      "centered": false,
      "origin": "bottom",
      "steps": [
        [
          0,
          1
        ],
        [
          0.86,
          0.12
        ]
      ]
    },
    {
      "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()["field-globe"]);
// 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()["field-globe"]), 320, 200, { time: 1.7 }));
API → Options
OptionTypeDefaultDescription
mode"ember" | "globe" | "dissolve" | "field""ember"Which field.