Physarum agent transport networks × Procedural City Generation (L-system Road Networks) × CGA Shape Grammar (Procedural Buildings)
Cities wired by slime mould. Road networks that emerge from transport demand between settlements instead of hand-tuned growth rules. A slime-mould agent simulation links points of interest with efficient, redundant trails, which steer a street generator whose lots become buildings.
Open in StudioReproduced140× · 4.34 ms
Verified proof

Split-screen WebGL2 proof coupling a slope- and river-aware Physarum slime-mould transport network linking settlement hubs (left) directly into procedural arterial road extraction, block subdivision, and extruded 3D CGA shape-grammar buildings scaled by local trail flux (right).
Chromium Headless ANGLE/SwiftShader WebGL2 · 512x512 · couples emergent slime-mould transport demand to arterial streets, river bridge crossings, and height-graded CGA urban massing in one shared spatial field
Show GLSL proof (210 lines)
const float P_TRAIL_GAIN = 1.15; // P Physarum Trail Flux [0.4, 2.2, 0.05]
const float P_SLOPE_AVOID = 1.10; // P Terrain Cost Bias [0.0, 2.5, 0.05]
const float P_STREET_DENSITY = 1.00; // P Block Subdivision [0.5, 1.8, 0.05]
const float P_CGA_HEIGHT = 1.20; // P Grammar Tower Scale [0.3, 2.5, 0.05]
vec2 hash22(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.xx + p3.yz) * p3.zy);
}
float vnoise(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(
mix(hash22(i).x, hash22(i + vec2(1.0, 0.0)).x, u.x),
mix(hash22(i + vec2(0.0, 1.0)).x, hash22(i + vec2(1.0, 1.0)).x, u.x),
u.y
);
}
// Winding valley river signed distance (negative = water)
float riverDist(vec2 p) {
float cx = 0.05 * sin(p.y * 2.6 + 0.4) - 0.04 * cos(p.y * 5.1) - 0.02;
return abs(p.x - cx) - (0.068 + 0.015 * sin(p.y * 3.8));
}
// Terrain elevation: flat floodplains near river, steep hill on upper-right
float terrainElev(vec2 p) {
float hill = exp(-dot(p - vec2(0.36, 0.34), p - vec2(0.36, 0.34)) * 7.5) * 0.65;
float hill2 = exp(-dot(p - vec2(-0.38, -0.32), p - vec2(-0.38, -0.32)) * 9.0) * 0.45;
return hill + hill2 + 0.06 * vnoise(p * 6.0);
}
// Distance to a curved transport filament linking hub a -> hub b, deflected by terrain cost
float filamentDist(vec2 p, vec2 a, vec2 b, float seed) {
vec2 ab = b - a;
float t = clamp(dot(p - a, ab) / max(dot(ab, ab), 1e-4), 0.0, 1.0);
vec2 base = a + ab * t;
vec2 perp = normalize(vec2(-ab.y, ab.x));
// Organic Physarum routing warp avoiding steep hill & snapping toward bridge ford
float arch = sin(t * 3.1415926);
float wobble = (vnoise(base * 5.5 + seed) - 0.5) * 0.12 * arch;
float hillPush = -exp(-dot(base - vec2(0.34, 0.32), base - vec2(0.34, 0.32)) * 6.0) * 0.11 * P_SLOPE_AVOID * arch;
vec2 q = base + perp * (wobble + hillPush);
return length(p - q);
}
// Evaluates emergent Physarum transport trail field between 6 settlement hubs (food sources)
void evalPhysarumField(vec2 p, float t, out float trail, out float pulse, out float hubGlow) {
vec2 hubs[6];
hubs[0] = vec2(-0.28, 0.26);
hubs[1] = vec2(-0.24, -0.02);
hubs[2] = vec2(-0.18, -0.28);
hubs[3] = vec2( 0.24, 0.14);
hubs[4] = vec2( 0.22, -0.18);
hubs[5] = vec2( 0.01, 0.02); // Central river bridge hub
hubGlow = 0.0;
for (int i = 0; i < 6; i++) {
float d = length(p - hubs[i]);
hubGlow += exp(-d * d * 240.0);
}
// Primary + redundant slime-mould transport edges
float d0 = filamentDist(p, hubs[0], hubs[5], 1.1);
float d1 = filamentDist(p, hubs[1], hubs[5], 2.3);
float d2 = filamentDist(p, hubs[2], hubs[5], 3.7);
float d3 = filamentDist(p, hubs[3], hubs[5], 4.9);
float d4 = filamentDist(p, hubs[4], hubs[5], 6.2);
float d5 = filamentDist(p, hubs[0], hubs[1], 7.4);
float d6 = filamentDist(p, hubs[1], hubs[2], 8.6);
float d7 = filamentDist(p, hubs[3], hubs[4], 9.8);
float d8 = filamentDist(p, hubs[0], hubs[3], 11.2);
float d9 = filamentDist(p, hubs[2], hubs[4], 12.5);
float minD = min(min(min(d0, d1), min(d2, d3)), min(d4, min(d5, d6)));
minD = min(minD, min(d7, min(d8, d9)));
// Secondary branching slime tendrils attracted by trail pheromone
float branch = abs(sin((p.x * 16.0 + vnoise(p * 7.0) * 2.5)) * cos((p.y * 16.0 - vnoise(p * 7.0 + 4.0) * 2.5)));
float tendril = exp(-branch * 7.5) * exp(-minD * 7.0) * 0.42;
// River suppresses non-bridge filaments; terrain slope attenuates trails
float riv = riverDist(p);
float bridgeAllow = exp(-dot(p - hubs[5], p - hubs[5]) * 45.0) + exp(-abs(p.y - 0.20) * 22.0) * 0.7 + exp(-abs(p.y + 0.22) * 22.0) * 0.7;
float waterMask = riv < 0.0 ? clamp(bridgeAllow, 0.0, 1.0) : 1.0;
float slopeCost = exp(-terrainElev(p) * 1.45 * P_SLOPE_AVOID);
float mainTrail = exp(-minD * 36.0) * 1.15 + exp(-minD * 13.0) * 0.48;
trail = clamp((mainTrail + tendril + hubGlow * 0.55) * waterMask * slopeCost * P_TRAIL_GAIN, 0.0, 1.6);
// Animated cytoplasmic transport waves pulsing along the slime filaments
float wave = 0.5 + 0.5 * sin(length(p - hubs[5]) * 28.0 - t * 3.2 + vnoise(p * 12.0) * 2.0);
pulse = trail * (0.55 + 0.45 * wave);
}
vec3 acesTone(vec3 x) {
return clamp((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
bool showCity = uv.x > 0.0;
vec2 suv = vec2(showCity ? (uv.x - 0.25) : (uv.x + 0.25), uv.y);
// Shared city coordinate domain on both sides for 1:1 visual inspection
vec2 p = vec2(suv.x * 1.65, suv.y * 1.05);
float trail, pulse, hubGlow;
evalPhysarumField(p, iTime, trail, pulse, hubGlow);
float riv = riverDist(p);
float elev = terrainElev(p);
float contour = smoothstep(0.92, 0.99, abs(sin(elev * 44.0)));
vec3 col = vec3(0.0);
if (!showCity) {
// Left: Physarum transport network + terrain/river cost field
vec3 ground = mix(vec3(0.04, 0.055, 0.075), vec3(0.11, 0.13, 0.15), elev);
ground += vec3(0.06, 0.09, 0.11) * contour;
if (riv < 0.0) ground = mix(vec3(0.02, 0.09, 0.18), vec3(0.04, 0.16, 0.28), smoothstep(-0.07, 0.0, riv));
vec3 slimeCore = vec3(1.25, 0.86, 0.24) * smoothstep(0.18, 1.05, pulse);
vec3 slimeHalo = vec3(0.65, 0.28, 0.06) * clamp(trail, 0.0, 1.0);
vec3 nodes = vec3(1.6, 1.45, 0.95) * smoothstep(0.25, 0.85, hubGlow);
col = ground + slimeHalo * 0.85 + slimeCore * 1.25 + nodes;
} else {
// Right: Procedural arterial roads + block subdivision + extruded 3D CGA shape-grammar buildings
// Base topographic parcel map
vec3 park = mix(vec3(0.11, 0.16, 0.12), vec3(0.18, 0.22, 0.15), elev);
park = mix(park, park * 0.86, contour * 0.45);
vec3 waterCol = mix(vec3(0.04, 0.14, 0.24), vec3(0.08, 0.24, 0.36), smoothstep(-0.07, 0.0, riv));
col = riv < 0.0 ? waterCol : park;
// Extract arterial highways directly from strong Physarum trails + river bridges
float arterial = smoothstep(0.58, 0.78, trail);
float streetZone = smoothstep(0.18, 0.45, trail) * step(0.008, riv);
// Procedural minor street grid warped slightly by terrain
vec2 gridP = (p + vec2(0.02 * sin(p.y * 5.0), 0.02 * cos(p.x * 5.0))) * (18.0 * P_STREET_DENSITY);
vec2 cell = floor(gridP);
vec2 lf = fract(gridP);
float minorRoad = 1.0 - smoothstep(0.06, 0.11, min(min(lf.x, 1.0 - lf.x), min(lf.y, 1.0 - lf.y)));
vec3 asphalt = vec3(0.09, 0.10, 0.12);
vec3 avenue = vec3(0.16, 0.16, 0.18);
if (streetZone > 0.05) {
col = mix(col, asphalt, minorRoad * streetZone * 0.92);
}
if (arterial > 0.05) {
// Glowing warm streetlight spine along extracted arterial & bridge decks
float centerLine = smoothstep(0.84, 0.98, trail);
col = mix(col, avenue, arterial);
col += vec3(0.95, 0.68, 0.28) * centerLine * 0.48;
}
// Extruded 2.5D CGA shape-grammar buildings inside subdivided lots (back-to-front parallax march)
vec2 sun2 = normalize(vec2(0.65, 0.76));
// Cast directional shadow from neighbouring taller lot
float shadowTrail, shPulse, shHub;
evalPhysarumField(p + sun2 * 0.028, iTime, shadowTrail, shPulse, shHub);
float castShad = 1.0 - 0.42 * smoothstep(0.32, 0.88, shadowTrail) * step(0.01, riv);
col *= castShad;
// Check up to 5 stacked elevation slices for crisp isometric extruded CGA towers
for (int layer = 1; layer <= 5; layer++) {
float fh = float(layer) / 5.0;
vec2 sp = p - vec2(0.006, 0.014) * float(layer) * P_CGA_HEIGHT;
float sRiv = riverDist(sp);
if (sRiv < 0.014) continue;
float sTrail, sP, sH;
evalPhysarumField(sp, iTime, sTrail, sP, sH);
// Buildings only sit on buildable lots (off arterial roadways, within urban trail envelope)
if (sTrail < 0.22 || sTrail > 0.72) continue;
vec2 gsp = (sp + vec2(0.02 * sin(sp.y * 5.0), 0.02 * cos(sp.x * 5.0))) * (18.0 * P_STREET_DENSITY);
vec2 cid = floor(gsp);
vec2 clf = fract(gsp);
vec2 rnd = hash22(cid + 3.7);
// CGA grammar rule: lot height and massing setback driven by local Physarum trail demand
float maxFloors = clamp((sTrail - 0.18) * 1.65 * (0.65 + 0.75 * rnd.x) * P_CGA_HEIGHT, 0.0, 1.05);
if (fh > maxFloors) continue;
// Setback terrace narrows upper stories of high-rise towers
float setback = mix(0.14, 0.26, fh * smoothstep(0.45, 0.9, maxFloors));
vec2 lotSize = vec2(0.5 - setback);
vec2 q = abs(clf - 0.5) - lotSize;
float inFootprint = max(q.x, q.y);
// Courtyard grammar rule for medium-density outer blocks
float isCourtyard = (maxFloors < 0.55 && rnd.y > 0.52) ? 1.0 : 0.0;
bool hole = isCourtyard > 0.5 && length(clf - 0.5) < 0.14;
if (inFootprint < 0.0 && !hole) {
bool isRoof = (fh + 0.21 > maxFloors);
vec3 facadeBase = mix(vec3(0.28, 0.30, 0.34), vec3(0.52, 0.46, 0.38), rnd.y);
if (maxFloors > 0.68) facadeBase = mix(vec3(0.24, 0.32, 0.42), vec3(0.42, 0.48, 0.56), rnd.x);
if (isRoof) {
// Roof terrace + mechanical penthouse unit
float pent = step(max(abs(clf.x - 0.48), abs(clf.y - 0.52)), 0.11) * step(0.45, maxFloors);
col = facadeBase * (0.95 + 0.35 * fh) + vec3(0.14, 0.13, 0.12) * pent;
} else {
// Lit CGA facade window bands on vertical stories
float win = step(0.45, fract(clf.x * 6.0)) * step(0.35, fract(fh * 10.0));
float lit = step(0.52, hash22(cid + vec2(floor(clf.x * 6.0), float(layer))).x);
vec3 shade = facadeBase * (0.52 + 0.38 * fh);
col = shade + vec3(1.15, 0.85, 0.42) * win * lit * 0.55;
}
}
}
}
col = acesTone(col * 1.08);
if (abs(uv.x) < 0.003) col = vec3(0.96, 0.94, 0.88);
fragColor = vec4(pow(clamp(col, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}Why they connect
Physarum agent transport networks runs agents over a trail map seeded with food at settlements and ports and biased by slope, and outputs the trail texture plus a rough graph. Procedural City Generation (L-system Road Networks) takes that texture in place of its population-density map (a texture hop): strong trails pull arterial growth, weaker ones attract minor streets, and its heightfield input still blocks water and steep ground. It outputs a road graph and a layout of blocks and lots. CGA Shape Grammar (Procedural Buildings) consumes the layout and turns each lot into a building mass and facade, with rules chosen by lot size and distance to the strongest trails.
How to build it
Run the physarum simulation in a WebGPU or engine compute shader on a terrain-sized grid; weight deposits by inverse slope and mask out water. Place food at settlement points and let the trails stabilise. Threshold and skeletonise the trail map to extract an arterial graph, then seed an extended L-system road grower (Houdini or a Python port) with those arterials as fixed roads and trail intensity as its density map. Extract blocks, subdivide them into lots, and tag each lot with trail intensity and road class. In Houdini or Blender, run CGA-style rules where the tags pick building height and type: taller along major trails, lower at the fringes.
Field marks
- Trail maps are not planar graphs, so skeletonisation leaves spurs and tiny loops.
- Physarum parameters flip between filaments and blobs, changing the city's character abruptly.
- Without water and slope masks, trails cross rivers and cliffs.
- Grammar rules break on the irregular lots that organic roads create.
Prior art
- Vie Physarale: Evaluation of Roman roads with slime mould. Partial: grows real slime mould between city sites to approximate a road network, the core of the first hop; no procedural street growth or building generation.
- iamgirya/Physarum-building-an-optimal-road-network. Partial: builds an optimal route network with a slime-mould algorithm and converts the result into routes (per its description); no lot subdivision or buildings.
Searches run (4)
- arXiv: all:"physarum" AND all:"road network" → 1 result
- GitHub repos: physarum "road network" → 2 results
- arXiv: all:"slime mould" AND all:"procedural city" → 0 results
- GitHub repos: "slime mould" "procedural city" → 0 results