Editor →

Real-time procedural content generation for TypeScript — deterministic by construction, WebGPU accelerated, in the browser and Node, with optional three.js interop.

← every dot here comes from this number.

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.

6,122tests, all green
61registered node types
37named primitives
64field-grammar functions
0required dependencies
v0.17MIT · ESM · strict TS

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.

The module layers and the cook path, in two figures →

Built for agents

Runtime introspection and stable serialization

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.

The pcg-ts editor. Across the top, the wordmark on a white plate, a graph glyph beside the word EDITOR, a graph picker reading “compose several primitives into a scatter”, seed 1023, and icon controls for the render and the node canvas; the status line under it reads 60 fps, cook 11.5 ms, 4 of 4 cooked and cached, 541 points and 541 instances. A curated knobs card on the left offers tabs for scatter, mask and size, with points at 700 and spacing at 0.8 m. Four connected nodes run across the middle — scatter-even, mask-by-noise, random-scale and spawnInstances — floating over the cooked result behind them: a few hundred green conifers gathered into clumps and clearings over a dark ground plane.editoropen any corpus graph and edit it live — palette, inspector, a curated knobs panel, JSON round-trip, shareable links, and a cook path you can switch between the CPU and two GPU paths A landscape of scattered instances streaming around a moving camera, with a panel showing cooked and evicted cell counts.infinite worldhierarchical streaming around a moving camera — with a GPU toggle showing combinator-authored fields reaching the device A spiral galaxy of tens of thousands of coloured star points around a bright core, with a panel showing streamed star cells.galaxyan infinite deterministic spiral galaxy — streamed star cells, click any star to visit its planets A streamed world of tall teal spires drawn from GPU-composed matrices, beside a panel reading 40 live cells, 16,800 instances drawn, 1.0 MiB of matrices held on device and 0 B uploaded.gpu worlda streamed world whose instance matrices are composed in WGSL and drawn straight from that buffer — toggle to the CPU path and watch the readbacks appear The racetrack demo, shown small: a circuit drawn as a pale ribbon seen from above, its whole lap lined on both verges with hundreds of small green wireframe boxes and spanned overhead in places, with the driven view of the road running away beneath it. A controls-and-readout panel fills the left edge, too small at this size to read.racetrackroadside art placed along a spline the page was handed — six legibility rules run as a bounded fixed point, with every repair reporting how much it had to do The road demo, shown small: the same circuit as the racetrack card, drawn as a pale ribbon from above with the driven view beneath it — but the verges carry one evenly spaced row of identical small boxes per side instead of varied art. A controls-and-readout panel fills the left edge, too small at this size to read.roadthe same page with none of the placement rules in it — one spline, one sweep, one evenly spaced row per side, shot at the same station so the difference between the two pictures is exactly what the rules add The cave demo, shown small: a warm-lit rock interior of smooth bulging walls and dark openings receding into shadow, lit from the camera. A controls-and-readout panel fills the left edge, too small at this size to read.caveone node with no inputs makes the whole world: meshFromField contours a noise into triangles, and the level cuts space into CUBE cells rather than the flat ones every other world here uses — each cube is contoured knowing nothing of its neighbours, and the seam you cannot find between any two of them is the claim being demonstrated The lanterns demo, shown small: a few thousand small glowing octahedra of many different hues hanging in a drifting sheet over a dark ground grid, thinning toward the horizon. A controls-and-readout panel fills the left edge, too small at this size to read.lanternsone u32 per instance is the whole interface between a graph and a shader — the graph settles where each lantern hangs and the seed it carries, the page derives colour, pulse and bob from that integer and a clock the graph never sees; switch the id source to the f32 copy and watch the colour wheel collapse

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.

What shipped in each release →