CGA Shape Grammar (Procedural Buildings)
A grammar of 3D shapes with scope-aware operations (split, repeat, extrude, component split) that turns a building footprint and a few parameters into a detailed, textured facade and mass model.
Also known as CGA shape, shape grammar for buildings, CityEngine rules
In the family Procedural generation, buildings and cities
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 CGA architectural shape-grammar engine. |
| Unity | None found | |
| Unreal 5.7 | Official add-on | Enable the PCG plugin; PCG graph shape grammar nodes docs |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
A shape is a labelled 3D scope (position, orientation, size) plus geometry. Rules rewrite a shape symbol into others: split divides the scope along an axis into slices with relative or absolute sizes (floors, tiles), repeat tiles an element to fill a range, comp splits a volume into faces, extrude and taper make masses, and insert replaces a scope by an asset. Rules apply in sequence from a lot footprint through mass model, floors, facade tiles and windows, with stochastic selection among alternatives for variety and context queries (occlusion, snapping) to avoid collisions. The grammar's output is a hierarchy of terminal shapes meshed into the final model. It excels at structured, regular architecture and keeps all design logic as editable rules.
When to choose it
Reach for it when
- generate detailed building facades procedurally
- need to populate a city with many varied buildings
- model architecture from rules instead of by hand
- make variations of a building style from a few parameters
Choose it for city blocks and facades where rules (floors, bays, windows) express the style, and for large crowds of varied buildings from a handful of rules. Prefer Model Synthesis or Wave Function Collapse when you want to imitate an example rather than author rules, L-Systems for organic growth, and Procedural Kit Modeling with Verification (procgen-kit) when modules must be parametric, closed and collision-verified.
Field marks
- Rules are brittle with irregular footprints: splits on odd lot shapes give slivers or overlapping scopes
- Grammar authoring is an expertise barrier; subtle rule errors yield mismatched facades
- Repeated rules make uniform, clone-like facades unless stochastic variation is added
- Output mesh topology is not guaranteed manifold or watertight
- Complex designs (organic, historical) are hard to express and require many custom operations
Presets
Facade produced by a CGA-style split/repeat rule chain
{
"FLOORS": 5,
"TILE_W": 0.11,
"GROUND_H": 0.17,
"ROOF_H": 0.06
}Show GLSL (51 lines)
// Facade from a CGA-style rule chain: split(y){ground | floor~ | roof}, repeat(x){wall | window | wall}, with a door on the ground floor.
const int FLOORS = 5;
const float TILE_W = 0.11;
const float GROUND_H = 0.17;
const float ROOF_H = 0.06;
float h(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
float box(vec2 p, vec2 b) { vec2 q = abs(p) - b; return max(q.x, q.y); }
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = fragCoord / iResolution.xy;
vec3 sky = mix(vec3(0.85, 0.65, 0.5), vec3(0.2, 0.3, 0.55), uv.y);
vec3 col = sky;
vec2 lo = vec2(0.12, 0.06), hi = vec2(0.88, 0.94);
if (uv.x > lo.x && uv.x < hi.x && uv.y > lo.y && uv.y < hi.y) {
float H = hi.y - lo.y, y = (uv.y - lo.y) / H * (1.0 - 0.0);
float gh = GROUND_H, rh = ROOF_H, fh = (1.0 - gh / 1.0 * 0.0);
float yy = uv.y - lo.y;
float totalH = H, floorsH = totalH - GROUND_H - ROOF_H;
float fl = floorsH / float(FLOORS);
vec3 wall = vec3(0.72, 0.62, 0.52);
float tx = (uv.x - lo.x) / TILE_W;
float nTiles = floor((hi.x - lo.x) / TILE_W);
float ti = floor(tx);
vec2 tl = vec2(fract(tx) - 0.5, 0.0);
col = wall * (0.9 + 0.1 * h(floor(uv * 90.0)));
if (yy < GROUND_H) {
// ground: shopfront band with a door in the middle tile
col = wall * 0.75;
vec2 q = vec2(fract(tx) - 0.5, yy / GROUND_H - 0.5);
bool mid = abs(ti - floor(nTiles * 0.5)) < 0.5;
float d = box(q, mid ? vec2(0.3, 0.42) : vec2(0.36, 0.28));
vec3 gl = mid ? vec3(0.25, 0.15, 0.1) : vec3(0.3, 0.45, 0.55);
col = mix(col, gl, smoothstep(0.03, -0.01, d));
} else if (yy > totalH - ROOF_H) {
col = vec3(0.35, 0.18, 0.15) * (0.8 + 0.2 * sin(uv.x * 220.0));
col = mix(col, wall * 0.5, step(totalH - ROOF_H * 0.22, yy));
} else {
float fy = (yy - GROUND_H) / fl;
float fi = floor(fy);
vec2 q = vec2(fract(tx) - 0.5, fract(fy) - 0.5);
float d = box(q, vec2(0.2, 0.28));
float lit = step(0.5, h(vec2(ti, fi)));
vec3 gl = mix(vec3(0.22, 0.32, 0.45), vec3(1.0, 0.8, 0.45), lit) * (0.7 + 0.5 * (0.5 - q.y));
col = mix(col, gl, smoothstep(0.02, -0.01, d));
col = mix(col, wall * 0.45, smoothstep(0.02, 0.0, abs(d - 0.04)) * step(0.0, d) * 0.5);
col *= 1.0 - 0.25 * smoothstep(0.03, 0.0, abs(fract(fy) - 0.0));
}
col = mix(col, vec3(0.08), smoothstep(0.004, 0.0, min(uv.x - lo.x, hi.x - uv.x)) * 0.5);
} else if (uv.y < lo.y) col = vec3(0.15, 0.15, 0.17);
fragColor = vec4(pow(col, vec3(0.8)), 1.0);
}
Attribution: written for this index
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| cga-shape-grammar-specimen | Tesla T4 1920x1080 | 1.55× baseline (feather) · 0.051 ms / 0.053 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| cga-shape-grammar-specimen | NVIDIA L4 1920x1080 | 1.33× baseline (feather) · 0.021 ms / 0.021 ms · 2.4× faster on L4 | opengl-timer-query · Cross-architecture validation |
| cga-shape-grammar-specimen | NVIDIA A100-SXM4-40GB 1920x1080 | 1.11× baseline (feather) · 0.032 ms / 0.032 ms · 1.6× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Procedural City Generation (L-system Road Networks); cited by Model Synthesis.
Crosses
- Overgrown grammar cities: Ruins and old towns where vines follow what the building is: climbing drainpipes, hanging from ledges, avoiding glass. The grammar's semantic labels become growth guidance, and twist-free frames keep stems and leaves oriented.
- 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.
- Procedural City Generation (L-system Road Networks): Road networks produce the lots and footprints that the shape grammar extrudes into buildings.
Sources
- primaryPascal Müller, Peter Wonka, Simon Haegler, Andreas Ulmer, Luc Van Gool (2006). Procedural modeling of buildings. ACM Transactions on Graphics.Verified via crossref · 2026-11-29doi:10.1145/1141911.1141931