MarkovJunior (Rewrite-Rule Generation)
A probabilistic programming language for grid generation: sequences of pattern-rewrite rules, optionally guided by inference toward goal states, with WFC available as one of its node types.
Also known as MarkovJunior, probabilistic rewrite rules
In the family Procedural generation, constraint-based synthesis
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | None found | No built-in MarkovJunior rewrite-rule generator. |
| Unity | None found | |
| Unreal 5.7 | None found | |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
A model is a tree of nodes executed over a grid of colours. A rewrite node has an input pattern and output pattern, like 'RB -> WW'; at each step it picks a random matching location and rewrites it. Nodes are composed with sequential, Markov (repeat until nothing applies) and one-shot semantics, giving growth processes, maze carvers and flood fills. Inference nodes use constraint propagation and search to steer rewriting toward a goal state, such as a path connecting two points, rather than hoping random rewriting finds it. Also includes a WFC node and a convolution node. Models are XML descriptions running in a C# interpreter that renders 2D and 3D output.
When to choose it
Reach for it when
- prototype a dungeon or maze generator with readable rules
- grow voxel structures from simple pattern rewrites
- grid generation with goals like a path from a to b
- procedural content without an example to imitate
- generate grid patterns guided by constraints
Choose it when you want to prototype grid-based generators quickly (mazes, dungeons, voxel buildings, growth patterns) with explicit, readable rules and goal inference. Prefer Wave Function Collapse when you have an example to imitate, and BSP Dungeon Generation or L-Systems when a hand-written recursive procedure is clearer than a rule database.
Field marks
- Rule order and node semantics are subtle: a misplaced Markov node can loop forever or terminate immediately
- Inference can fail to find any solution, leaving the run in an unsolved state
- Output is grid-bound; exporting to meshes needs an extra meshing step
- Random rewriting without inference often misses global goals like connectivity
Presets
MarkovJunior — discrete symbol rewrite grid (left) vs sculpted dungeon tile architecture (right)
{
"P_GRID_RES": 16,
"P_RULE_STAGE": 0.78,
"P_ANIM_RATE": 0.85,
"P_SPLIT": 0.46
}Show GLSL (116 lines)
const float P_GRID_RES = 16.0; // P Grid Resolution [10.0, 26.0, 2.0]
const float P_RULE_STAGE = 0.78; // P Rewrite Progress [0.1, 1.0, 0.02]
const float P_ANIM_RATE = 0.85; // P Rewrite Sweep [0.0, 2.5, 0.05]
const float P_SPLIT = 0.46; // P Symbols / Tiles [0.0, 1.0, 0.02]
float hash21(vec2 p) {
p = fract(p * vec2(127.1, 311.7));
p += dot(p, p + 34.5);
return fract(p.x * p.y);
}
// Deterministic MarkovJunior-style multi-stage grid symbol classifier:
// Returns symbol ID: 0=void/black, 1=corridor/white, 2=room/gold, 3=river/cyan, 4=wall/crimson
float evalMarkovCell(vec2 cell, float stage) {
// Stage 1: Growing orthogonal maze corridors from central seed
vec2 macro = floor(cell * 0.5);
float h = hash21(macro);
float isCorrX = step(0.5, mod(cell.y, 2.0)) * step(0.32, h);
float isCorrY = step(0.5, mod(cell.x, 2.0)) * step(h, 0.68);
float sym = max(isCorrX, isCorrY);
// Stage 2: Room-carving rewrite rule (B-W-W -> R-R-R) in seeded chambers
vec2 roomCell = floor(cell / 5.0);
vec2 roomLocal = mod(cell, 5.0);
if (hash21(roomCell + 7.3) > 0.45 && roomLocal.x >= 1.0 && roomLocal.x <= 3.0 && roomLocal.y >= 1.0 && roomLocal.y <= 3.0) {
if (stage > 0.35) sym = 2.0;
}
// Stage 3: Winding river rewrite rule cutting through grid
float riverX = floor(sin(cell.y * 0.38) * 2.2 + 0.5);
if (abs(cell.x - riverX) < 0.6 && stage > 0.60) {
sym = 3.0;
}
// Stage 4: Wall-border rewrite rule: any black cell adjacent to corridor/room becomes wall (4)
if (sym < 0.5 && stage > 0.25) {
float n1 = step(0.5, mod(cell.y + 1.0, 2.0));
float n2 = step(0.5, mod(cell.x + 1.0, 2.0));
if (n1 + n2 > 0.5) sym = 4.0;
}
return sym;
}
vec3 aces(vec3 x) {
x = max(x, 0.0);
return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
float screenX = fragCoord.x / max(iResolution.x, 1.0);
float split = clamp(P_SPLIT, 0.0, 1.0);
bool isSymbols = screenX < split;
float gridRes = clamp(floor(P_GRID_RES + 0.5), 8.0, 28.0);
float stage = clamp(P_RULE_STAGE, 0.05, 1.0);
float sweep = iTime * max(P_ANIM_RATE, 0.0);
vec2 g = uv * gridRes;
vec2 cell = floor(g);
vec2 f = fract(g);
// Expanding Markov rewrite wave radiating outward from seed origin
float distSeed = length(cell) / (gridRes * 0.65);
float activeWave = fract(sweep * 0.16) * 1.35 + stage * 0.55;
float cellStage = stage * smoothstep(activeWave + 0.18, activeWave - 0.08, distSeed);
float frontier = exp(-abs(distSeed - activeWave) * 18.0);
float sym = evalMarkovCell(cell, cellStage);
vec2 dEdge = min(f, 1.0 - f);
float border = smoothstep(0.08, 0.02, min(dEdge.x, dEdge.y));
vec3 col;
if (isSymbols) {
// Left: Pure MarkovJunior flat color-coded symbol grid (classic B/W/R/U/Y palette) + active rewrite cursor
vec3 symCol = vec3(0.06, 0.07, 0.10); // 0 = black void
if (sym > 0.5 && sym < 1.5) symCol = vec3(0.90, 0.92, 0.96); // 1 = white path
else if (sym > 1.5 && sym < 2.5) symCol = vec3(0.98, 0.76, 0.20); // 2 = gold room
else if (sym > 2.5 && sym < 3.5) symCol = vec3(0.14, 0.80, 0.96); // 3 = cyan water
else if (sym > 3.5) symCol = vec3(0.84, 0.24, 0.26); // 4 = crimson wall
col = mix(symCol, vec3(0.04, 0.05, 0.08), border * 0.65);
col += vec3(0.32, 1.0, 0.72) * frontier * 0.55;
} else {
// Right: Rendered beveled dungeon tiles & animated water from the rewritten symbol grid!
float bevel = smoothstep(0.0, 0.18, min(dEdge.x, dEdge.y));
vec2 slope = vec2(smoothstep(0.82, 1.0, f.x) - smoothstep(0.18, 0.0, f.x),
smoothstep(0.82, 1.0, f.y) - smoothstep(0.18, 0.0, f.y));
vec3 n = normalize(vec3(-slope.x * 1.4, -slope.y * 1.4, 1.0));
vec3 lDir = normalize(vec3(0.55, 0.65, 0.82));
float diff = max(dot(n, lDir), 0.0);
vec3 tileCol = vec3(0.05, 0.06, 0.09);
if (sym > 0.5 && sym < 1.5) {
// Carved stone corridor flagstones
tileCol = vec3(0.46, 0.48, 0.52) * (0.45 + 0.65 * diff) * (0.75 + 0.25 * bevel);
} else if (sym > 1.5 && sym < 2.5) {
// Warm inlaid golden mosaic room floor
float inlay = smoothstep(0.28, 0.20, length(f - 0.5));
tileCol = mix(vec3(0.68, 0.52, 0.26), vec3(0.96, 0.80, 0.34), inlay) * (0.45 + 0.65 * diff);
} else if (sym > 2.5 && sym < 3.5) {
// Flowing subterranean canal water
float rip = 0.5 + 0.5 * sin(g.y * 6.0 - sweep * 4.5 + sin(g.x * 4.0));
tileCol = mix(vec3(0.06, 0.42, 0.62), vec3(0.22, 0.86, 0.96), rip * 0.65 + 0.25);
} else if (sym > 3.5) {
// Raised masonry dungeon wall parapet
float brick = step(0.10, fract(f.x * 2.0 + step(0.5, f.y) * 0.5));
tileCol = mix(vec3(0.26, 0.16, 0.18), vec3(0.54, 0.28, 0.26), brick) * (0.38 + 0.82 * diff);
}
col = tileCol + vec3(0.28, 0.95, 0.82) * frontier * 0.25;
}
float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
col = mix(col, vec3(0.95, 0.97, 1.0), sep);
fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}Attribution: MIT — written for this index.
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| markov-junior-rewrite-rules-live | Tesla T4 1920x1080 | 3.38× baseline (light) · 0.111 ms / 0.114 ms | opengl-timer-query · 32 frames · GPU Weight Atlas · Colab T4 sweep |
| markov-junior-rewrite-rules-live | NVIDIA L4 1920x1080 | 2.77× baseline (light) · 0.044 ms / 0.045 ms · 2.5× faster on L4 | opengl-timer-query · Cross-architecture validation |
| markov-junior-rewrite-rules-live | NVIDIA A100-SXM4-40GB 1920x1080 | 2.12× baseline (light) · 0.061 ms / 0.062 ms · 1.8× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
Crosses
- Fog that flows through generated caves: Procedural caves and dungeons whose fog actually moves through them: drafts along corridors, eddies behind pillars. The generator's voxel grid is used directly as the fluid solver's solid boundary, so no remeshing sits between level and air.
Sources
- primarymxgmn (2022). mxgmn/MarkovJunior. Probabilistic language based on pattern matching and constraint propagation, 153 examplesGitHub API · license MIT · 2026-11-29
- implementationmxgmn (2022). mxgmn/MarkovJunior. Probabilistic language based on pattern matching and constraint propagation, 153 examplesGitHub API · license MIT · 2026-11-29