{
 "id": "cga-shape-grammar",
 "title": "CGA Shape Grammar (Procedural Buildings)",
 "aliases": [
  "CGA shape",
  "shape grammar for buildings",
  "CityEngine rules"
 ],
 "domain": "procgen",
 "subdomain": "buildings and cities",
 "stage": "procedural",
 "realtime": "interactive",
 "platforms": [
  "cpu",
  "houdini",
  "blender"
 ],
 "year_introduced": 2006,
 "inputs": [
  "layout"
 ],
 "outputs": [
  "mesh"
 ],
 "style": "both",
 "dynamic": "static",
 "summary": "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.",
 "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_use": "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` when modules must be parametric, closed and collision-verified.",
 "cost": {
  "class": "medium",
  "notes": "Rule derivation is fast per building (milliseconds to seconds) but generating a whole city is a batch job; resulting meshes need LOD."
 },
 "failure_modes": [
  "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"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/1141911.1141931",
   "type": "paper",
   "title": "Procedural modeling of buildings",
   "authors": [
    "Pascal Müller",
    "Peter Wonka",
    "Simon Haegler",
    "Andreas Ulmer",
    "Luc Van Gool"
   ],
   "year": 2006,
   "venue": "ACM Transactions on Graphics",
   "url": "https://doi.org/10.1145/1141911.1141931",
   "ids": {
    "doi": "10.1145/1141911.1141931"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1141911.1141931",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1141911.1141931",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1141911.1141931",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1141911.1141931",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1141911.1141931",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "mller2006procedural"
  }
 ],
 "presets": [
  {
   "id": "cga-shape-grammar-specimen",
   "title": "Facade produced by a CGA-style split/repeat rule chain",
   "runtime": "glsl-fragment",
   "params": {
    "FLOORS": 5,
    "TILE_W": 0.11,
    "GROUND_H": 0.17,
    "ROOF_H": 0.06
   },
   "code": "// Facade from a CGA-style rule chain: split(y){ground | floor~ | roof}, repeat(x){wall | window | wall}, with a door on the ground floor.\nconst int FLOORS = 5;\nconst float TILE_W = 0.11;\nconst float GROUND_H = 0.17;\nconst float ROOF_H = 0.06;\nfloat h(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }\nfloat box(vec2 p, vec2 b) { vec2 q = abs(p) - b; return max(q.x, q.y); }\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n    vec2 uv = fragCoord / iResolution.xy;\n    vec3 sky = mix(vec3(0.85, 0.65, 0.5), vec3(0.2, 0.3, 0.55), uv.y);\n    vec3 col = sky;\n    vec2 lo = vec2(0.12, 0.06), hi = vec2(0.88, 0.94);\n    if (uv.x > lo.x && uv.x < hi.x && uv.y > lo.y && uv.y < hi.y) {\n        float H = hi.y - lo.y, y = (uv.y - lo.y) / H * (1.0 - 0.0);\n        float gh = GROUND_H, rh = ROOF_H, fh = (1.0 - gh / 1.0 * 0.0);\n        float yy = uv.y - lo.y;\n        float totalH = H, floorsH = totalH - GROUND_H - ROOF_H;\n        float fl = floorsH / float(FLOORS);\n        vec3 wall = vec3(0.72, 0.62, 0.52);\n        float tx = (uv.x - lo.x) / TILE_W;\n        float nTiles = floor((hi.x - lo.x) / TILE_W);\n        float ti = floor(tx);\n        vec2 tl = vec2(fract(tx) - 0.5, 0.0);\n        col = wall * (0.9 + 0.1 * h(floor(uv * 90.0)));\n        if (yy < GROUND_H) {\n            // ground: shopfront band with a door in the middle tile\n            col = wall * 0.75;\n            vec2 q = vec2(fract(tx) - 0.5, yy / GROUND_H - 0.5);\n            bool mid = abs(ti - floor(nTiles * 0.5)) < 0.5;\n            float d = box(q, mid ? vec2(0.3, 0.42) : vec2(0.36, 0.28));\n            vec3 gl = mid ? vec3(0.25, 0.15, 0.1) : vec3(0.3, 0.45, 0.55);\n            col = mix(col, gl, smoothstep(0.03, -0.01, d));\n        } else if (yy > totalH - ROOF_H) {\n            col = vec3(0.35, 0.18, 0.15) * (0.8 + 0.2 * sin(uv.x * 220.0));\n            col = mix(col, wall * 0.5, step(totalH - ROOF_H * 0.22, yy));\n        } else {\n            float fy = (yy - GROUND_H) / fl;\n            float fi = floor(fy);\n            vec2 q = vec2(fract(tx) - 0.5, fract(fy) - 0.5);\n            float d = box(q, vec2(0.2, 0.28));\n            float lit = step(0.5, h(vec2(ti, fi)));\n            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));\n            col = mix(col, gl, smoothstep(0.02, -0.01, d));\n            col = mix(col, wall * 0.45, smoothstep(0.02, 0.0, abs(d - 0.04)) * step(0.0, d) * 0.5);\n            col *= 1.0 - 0.25 * smoothstep(0.03, 0.0, abs(fract(fy) - 0.0));\n        }\n        col = mix(col, vec3(0.08), smoothstep(0.004, 0.0, min(uv.x - lo.x, hi.x - uv.x)) * 0.5);\n    } else if (uv.y < lo.y) col = vec3(0.15, 0.15, 0.17);\n    fragColor = vec4(pow(col, vec3(0.8)), 1.0);\n}\n",
   "basis": "original",
   "license_note": "written for this index",
   "execution_fidelity": "faithful-pass",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "cga-shape-grammar",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-29T15:51:50.471Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.5481,
      "std": 0.158,
      "unique_colors": 155
     },
     "image": "/specimens/cga-shape-grammar-specimen.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "procedural-city-roads",
  "l-systems",
  "model-synthesis",
  "procedural-kit-modeling"
 ],
 "extends": [
  "l-systems"
 ],
 "supersedes": [],
 "combines_with": [
  {
   "id": "procedural-city-roads",
   "why": "Road networks produce the lots and footprints that the shape grammar extrudes into buildings."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/procgen/cga-shape-grammar.json"
 },
 "solves": [
  "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"
 ],
 "authority": "Müller et al., 2006",
 "url": "https://texelatlas.vercel.app/t/cga-shape-grammar/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 1.55,
  "tier": "feather",
  "p50_ms": 0.0511,
  "p95_ms": 0.053,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "cga-shape-grammar-specimen",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 1.33,
   "tier": "feather",
   "p50_ms": 0.0212,
   "p95_ms": 0.0213,
   "speedup_x": 2.41,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 1.11,
   "tier": "feather",
   "p50_ms": 0.0321,
   "p95_ms": 0.0322,
   "speedup_x": 1.59,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}