What it is
A node-graph PCG library, deterministic by construction
Build worlds out of rules instead of files. You write the recipe — scatter points over this ground, thin them out with noise, turn each survivor a random amount, put a tree on every one — and pcg-ts runs it. The recipe is a small graph of nodes; running it is called a cook. Feed it the same seed and you get the same world back, byte for byte, on any machine, forever.
pcg-ts is built for real-time use — cooking is budgeted and cancellable so it can run inside a frame, and the field grammar compiles to WGSL to run on a GPU device when one is there.
Any parameter can vary across space instead of being a constant: a value can be a function of where it lands, resolved per point.
Every random decision flows from a seed through one hash chain, so the same graph and seed produce byte-identical output across runs, platforms, cook orders, and streaming paths. Cooking on a GPU device is the one documented exception, and architecture states its tolerances.
The heavy work moves to the GPU: field expressions compile to WGSL, and instance matrices are composed there and handed straight to three.js — without ever touching the CPU.
It is built to be driven by AI agents as much as by humans: nodes carry machine-readable schemas, graphs serialize to stable JSON, and every error names the node, pin, or param at fault and states the fix.
Foundations
Four concepts the rest is built on
Attribute data model
Attributes live on four domains — point, vertex, primitive, detail — as SoA typed-array columns, with promote and transfer between them. The standard point carries transform, density, bounds, color, and its own seed. A 2-vertex polyline over shared points is an edge, so a network needs no fifth domain.
Deferred fields — Field<T>
A value can be a function of evaluation context, resolved only when it lands on a domain. Node params accept T | Field<T>; noise, trig, and combinators compose into expression trees that also serialize to JSON.
Graph runtime
A pull-based executor with revision-keyed memoization, time-budgeted and cancellable cooking, per-output partial cooks, and serializable subgraphs. Recook an unchanged graph and every node is a cache hit.
Streaming world
Hierarchical levels — 2D or 3D cells, arc sectors along a curve, plus an unbounded level — cook around a viewpoint with hysteresis and LRU eviction. Cell content is provably independent of cook order, path, and evictions.
Architecture
Layered core, optional adapters
A core that imports nothing outside itself, and adapters that depend on it one way only: three.js interop, the WebGPU compiler and device runtime, the worker pool, the CLI. Above that, a streaming runtime that cooks a world around a moving camera in budgeted, cancellable slices — and returns the same result whatever order it cooked in.
Built for agents
Runtime introspection and stable serialization
- Self-describing registry — every node type exposes pins, param schemas, defaults, and prose descriptions at runtime; the node reference is generated from it, never hand-written.
- A command line that closes the loop —
pcg nodes,fields,validate,cook,inspect,render.--jsonpicks a rendering of the same result rather than a separate code path, exit codes are 0 / 1 (failure) / 2 (misuse), andrenderwrites a deterministic top-down SVG that diffs in git. - A vocabulary to reference, not rebuild — 37 named primitives ship as
pcg-ts/primitives, cited from JSON asref: { name, hash? }. A name-only ref upgrades freely; a pinned one hard-errors on mismatch. No mode warns, and no mode cooks a near-miss. - Stable JSON everywhere — graphs, subgraphs, and field expressions serialize to a versioned format that round-trips to byte-identical cooks; serialized form is stable across cooks.
- Errors that state the fix — validation names the offending node, pin, or param and lists the valid alternatives. Error messages are part of the API surface.
- Introspectable execution — cook stats report what cooked, what was cached, and how long it took; determinism makes every run reproducible.
- Agent entry points —
llms.txtcapability map, generateddocs/nodes.md/primitives.md/graphs.mdwith their.jsontwins, three skills that cite every enumerable thing by path rather than inlining it, an authoring guide with recipes, and the user manual, whose second half is written for an agent driving the library programmatically. - Independently audited — each phase was reviewed by a separate agent before it landed, and the defects it found were fixed with regression tests before release.
Examples
Six demos and an editor, live in your browser
Each one needs a host to exist: streaming worlds, a device-resident renderer, a closed loop that measures its own output and corrects, and the editor the single-cook recipes moved into. Click to run.
Behind them sits a corpus of 95 graphs that are data rather than pages: pcg cook graphs/<name>.json. None of them uses dataInput, because its items do not survive serialization and an example an agent cannot run teaches nothing. Most are single-concept; eight are one settlement pipeline — ground and wall, district centres, lots, buildings, roads, plus three edit variants — where each stage is the previous file plus nodes and nothing removed, and the earlier stages cook bit-identically inside the later ones. Every one of them is in the corpus gallery, cooked in the editor and shot from the frame it draws into.
How the racetrack decides what stands beside the road, and where →
How one integer per lantern becomes a colour, a flicker and a bob →
Roadmap
What shipped in each release
Fifteen releases from the first foundation to the current one: the attribute data model and PCG32, then fields, the streaming runtime, the WebGPU compiler and device runtime, subgraphs, the worker pool, and the editor that drives all of it through the same public API this page documents.
