{
 "id": "model-synthesis",
 "title": "Model Synthesis",
 "aliases": [
  "example-based model synthesis",
  "Merrell model synthesis"
 ],
 "domain": "procgen",
 "subdomain": "constraint-based synthesis",
 "stage": "procedural",
 "realtime": "offline",
 "platforms": [
  "cpu",
  "python"
 ],
 "year_introduced": 2007,
 "inputs": [
  "voxels",
  "mesh"
 ],
 "outputs": [
  "voxels",
  "mesh"
 ],
 "style": "both",
 "dynamic": "static",
 "summary": "Generates large 3D models from a small example by growing the output in modifiable chunks while ensuring every local neighbourhood appears in the input; the direct predecessor of WFC.",
 "how_it_works": "The example model is analysed into local neighbourhood relations: which cell labels may be adjacent along each axis. The output volume is initialised with all labels possible, then filled by an order of assignment (e.g. one chunk or slice at a time) where each cell chooses a label compatible with already-assigned neighbours; constraint propagation removes impossible labels from unassigned cells. Merrell's insight was to modify small regions at a time so a dead end only forces re-doing that region (a limited form of local backtracking), keeping the process tractable. The 2007 paper applies it to polyhedral structures with adjacency via shared faces; the 2011 follow-up extends it to a general procedural modeling algorithm and adds user constraints like shape, connectivity and symmetries.",
 "when_to_use": "Choose it for 3D structure generation (buildings, architecture, bridges) from an example model with explicit user constraints, or when you want a deterministic, chunked solver for very large outputs. Prefer `wave-function-collapse` for entropy-driven, mostly 2D tile and bitmap synthesis with huge community tooling, and `cga-shape-grammar` when buildings should follow an explicit grammar instead of an example.",
 "cost": {
  "class": "offline",
  "notes": "Dominated by constraint propagation across the volume; scaled by chunk size and example complexity."
 },
 "failure_modes": [
  "Output only reproduces local patterns of the input, so large-scale composition is incoherent without extra constraints",
  "Poorly chosen adjacency relations over-constrain the solver and yield contradictions",
  "Chunked solving can show seams or repeated motifs at chunk boundaries",
  "Needs cleanly voxelised or grid-aligned examples: arbitrary meshes need a labelling step"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/1230100.1230119",
   "type": "paper",
   "title": "Example-based model synthesis",
   "authors": [
    "Paul Merrell"
   ],
   "year": 2007,
   "venue": "Proceedings of the 2007 symposium on Interactive 3D graphics and games",
   "url": "https://doi.org/10.1145/1230100.1230119",
   "ids": {
    "doi": "10.1145/1230100.1230119"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1230100.1230119",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1230100.1230119",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1230100.1230119",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1230100.1230119",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1230100.1230119",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "merrell2007example"
  },
  {
   "role": "primary",
   "key": "doi:10.1109/tvcg.2010.112",
   "type": "paper",
   "title": "Model Synthesis: A General Procedural Modeling Algorithm",
   "authors": [
    "P Merrell",
    "D Manocha"
   ],
   "year": 2011,
   "venue": "IEEE Transactions on Visualization and Computer Graphics",
   "url": "https://doi.org/10.1109/tvcg.2010.112",
   "ids": {
    "doi": "10.1109/tvcg.2010.112"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/tvcg.2010.112",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/tvcg.2010.112",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/tvcg.2010.112",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/tvcg.2010.112",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/tvcg.2010.112",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "merrell2011model"
  }
 ],
 "presets": [
  {
   "id": "model-synthesis-live",
   "title": "Model Synthesis — adjacency-constrained tile graph (left) vs grown 3D modular city blocks (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_CITY_SCALE": 2.2,
    "P_CHUNK_WAVE": 0.85,
    "P_CAM_ORBIT": 0.35,
    "P_SPLIT": 0.46
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_CITY_SCALE = 2.2; // P Module Density [1.2, 3.6, 0.1]\nconst float P_CHUNK_WAVE = 0.85; // P Chunk Growth [0.2, 1.0, 0.02]\nconst float P_CAM_ORBIT = 0.35; // P Orbit Speed [0.0, 1.8, 0.05]\nconst float P_SPLIT = 0.46; // P Adjacency / 3D City [0.0, 1.0, 0.02]\n\nmat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }\n\nfloat hash21(vec2 p) {\n  p = fract(p * vec2(127.1, 311.7));\n  p += dot(p, p + 34.5);\n  return fract(p.x * p.y);\n}\n\n// Adjacency-consistent architectural module selector (Merrell 2007 Model Synthesis):\n// Guarantees roads align seamlessly with neighbors, courtyards border towers, and bridges span canals!\nvec2 evalModule(vec2 cell) {\n  // Periodic road & canal spines guarantee global topological connectivity across chunks\n  float isRoadX = step(abs(mod(cell.y + 2.0, 4.0) - 2.0), 0.1);\n  float isRoadZ = step(abs(mod(cell.x + 2.0, 4.0) - 2.0), 0.1);\n  if (isRoadX + isRoadZ > 0.5) {\n    return vec2(0.06, 1.0); // 1 = road/plaza tile\n  }\n  // Inside city blocks, neighbor-coherent tower height from smoothed hash\n  float h = hash21(cell);\n  float hNbr = hash21(cell + vec2(1.0, 0.0));\n  float tiers = floor(mix(h, hNbr, 0.35) * 4.0 + 1.0);\n  float height = 0.16 + tiers * 0.18;\n  float kind = (tiers >= 3.0) ? 3.0 : 2.0; // 2 = mid-rise terrace, 3 = spire tower\n  return vec2(height, kind);\n}\n\nvec2 mapCity(vec3 p, float scale) {\n  vec2 g = p.xz * scale;\n  vec2 cell = floor(g);\n  vec2 f = fract(g) - 0.5;\n  vec2 modInfo = evalModule(cell);\n\n  // Ground plaza plane\n  vec2 res = vec2(p.y + 0.45, 1.0);\n\n  // Extruded architectural module box inside each grid cell\n  float halfW = (modInfo.y > 2.5) ? 0.34 : 0.41;\n  vec3 b = vec3(halfW / scale, modInfo.x, halfW / scale);\n  vec3 lp = vec3(f.x / scale, p.y + 0.45 - modInfo.x, f.y / scale);\n  vec3 q = abs(lp) - b;\n  float dBox = length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0) - 0.008;\n  // Limit step size near cell boundaries for artifact-free raymarching across grid\n  float edgeLim = (0.5 - max(abs(f.x), abs(f.y))) / scale + 0.04;\n  float dMod = min(dBox, edgeLim);\n  if (dMod < res.x) res = vec2(dMod, modInfo.y);\n  return res;\n}\n\nvec3 calcNormal(vec3 p, float scale) {\n  vec2 e = vec2(0.004, 0.0);\n  return normalize(vec3(\n    mapCity(p + e.xyy, scale).x - mapCity(p - e.xyy, scale).x,\n    mapCity(p + e.yxy, scale).x - mapCity(p - e.yxy, scale).x,\n    mapCity(p + e.yyx, scale).x - mapCity(p - e.yyx, scale).x\n  ));\n}\n\nvec3 aces(vec3 x) {\n  x = max(x, 0.0);\n  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  float screenX = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  bool isGraph = screenX < split;\n  float scale = clamp(P_CITY_SCALE, 1.0, 3.8);\n  float chunkW = clamp(P_CHUNK_WAVE, 0.15, 1.0);\n  float spin = iTime * max(P_CAM_ORBIT, 0.0) * 0.35;\n\n  vec3 ro = vec3(0.0, 1.55, 2.65);\n  vec3 rd = normalize(vec3(uv.x, uv.y - 0.44, -1.35));\n  ro.xz = rot2(spin) * ro.xz;\n  rd.xz = rot2(spin) * rd.xz;\n\n  vec3 sky = mix(vec3(0.86, 0.72, 0.58), vec3(0.16, 0.32, 0.58), smoothstep(-0.08, 0.52, rd.y));\n  vec3 col = sky;\n\n  float t = 0.2;\n  vec2 hit = vec2(1e5, 0.0);\n  for (int i = 0; i < 68; i++) {\n    vec2 h = mapCity(ro + rd * t, scale);\n    if (h.x < 0.004) { hit = vec2(t, h.y); break; }\n    t += max(h.x * 0.72, 0.015);\n    if (t > 12.0) break;\n  }\n\n  if (hit.x < 1e4) {\n    vec3 p = ro + rd * hit.x;\n    vec3 n = calcNormal(p, scale);\n    vec3 sunDir = normalize(vec3(0.62, 0.75, 0.42));\n    float diff = max(dot(n, sunDir), 0.0);\n\n    vec2 g = p.xz * scale;\n    vec2 cell = floor(g);\n    vec2 f = fract(g);\n    vec2 dCell = min(f, 1.0 - f);\n    float gridLine = smoothstep(0.06, 0.015, min(dCell.x, dCell.y));\n\n    if (isGraph) {\n      // Left: Modifiable-chunk tile-adjacency state visualization (color-coded by tile prototype & chunk boundary)\n      vec3 tileCol = vec3(0.14, 0.24, 0.36);\n      if (hit.y > 1.5 && hit.y < 2.5) tileCol = vec3(0.18, 0.72, 0.88);\n      else if (hit.y > 2.5) tileCol = vec3(0.96, 0.58, 0.20);\n      // Chunk boundary box highlight every 4x4 modules\n      vec2 chunkF = fract(cell / 4.0);\n      float chunkEdge = smoothstep(0.08, 0.02, min(min(chunkF.x, 1.0 - chunkF.x), min(chunkF.y, 1.0 - chunkF.y)));\n      float scan = exp(-abs(length(p.xz) - fract(iTime * 0.18) * 3.8 * chunkW) * 6.0);\n      col = tileCol * (0.38 + 0.72 * diff) + vec3(0.95, 0.98, 1.0) * gridLine * 0.35 + vec3(0.24, 1.0, 0.76) * (chunkEdge * 0.35 + scan * 0.45);\n    } else {\n      // Right: Shaded modular limestone/terracotta synthesized city with lit window facades!\n      vec3 alb = vec3(0.32, 0.34, 0.38); // road plaza\n      if (hit.y > 1.5 && hit.y < 2.5) alb = vec3(0.84, 0.76, 0.66);\n      else if (hit.y > 2.5) alb = vec3(0.76, 0.64, 0.54);\n      // Terracotta rooftop cap\n      if (n.y > 0.8 && hit.y > 1.5) alb = mix(alb, vec3(0.76, 0.36, 0.24), 0.72);\n      // Procedural facade windows on vertical walls\n      float winMask = 0.0;\n      if (abs(n.y) < 0.3 && hit.y > 1.5) {\n        vec2 wUV = fract(vec2((p.x + p.z) * scale * 4.0, p.y * 12.0));\n        winMask = step(0.24, wUV.x) * step(wUV.x, 0.76) * step(0.25, wUV.y) * step(wUV.y, 0.78);\n        alb = mix(alb, vec3(0.14, 0.22, 0.32), winMask * 0.75);\n      }\n      col = alb * (0.26 + 0.88 * diff) + vec3(0.98, 0.80, 0.42) * winMask * 0.18;\n    }\n    col = mix(col, sky, 1.0 - exp(-hit.x * 0.075));\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));\n  col = mix(col, vec3(0.95, 0.97, 1.0), sep);\n\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "model-synthesis",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T20:35:53.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.8301,
      "std": 0.0405,
      "min": 0.6165,
      "max": 0.9014
     },
     "image": "/specimens/model-synthesis-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "wave-function-collapse",
  "cga-shape-grammar",
  "markov-junior-rewrite-rules"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [],
 "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/model-synthesis.json"
 },
 "solves": [
  "need to generate large buildings from a small example model",
  "want constraint-controlled 3d structure generation",
  "wave collapse fails on very large outputs",
  "synthesise architecture that follows user constraints"
 ],
 "authority": "Merrell, 2007",
 "url": "https://texelatlas.vercel.app/t/model-synthesis/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 66.39,
  "tier": "extreme",
  "p50_ms": 2.1842,
  "p95_ms": 2.2517,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "model-synthesis-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 61.92,
   "tier": "extreme",
   "p50_ms": 0.9846,
   "p95_ms": 1.0056,
   "speedup_x": 2.22,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 44.39,
   "tier": "heavy",
   "p50_ms": 1.2785,
   "p95_ms": 1.2894,
   "speedup_x": 1.71,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}