{
 "id": "shape-matching-deformation",
 "title": "Shape matching (meshless deformation)",
 "aliases": [
  "Meshless deformations"
 ],
 "domain": "simulation",
 "subdomain": "soft bodies",
 "stage": "simulation",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "cpu",
  "unity"
 ],
 "year_introduced": 2005,
 "inputs": [
  "particles"
 ],
 "outputs": [
  "particles",
  "mesh"
 ],
 "style": "both",
 "dynamic": "dynamic",
 "summary": "Soft-body method that pulls each particle toward the best-fit rigid transform of its rest shape, giving stable, controllable deformable objects without a mesh.",
 "how_it_works": "Given particles with rest positions and current positions, compute the optimal rotation (and translation) that maps the rest shape onto the current one: the centre of mass for translation and a polar decomposition of the covariance matrix `A_pq` for rotation. Each particle's goal position is its rest position under this transform, and particles are moved toward their goals by a stiffness factor. Adding a linear or quadratic transformation to the fit lets the object shear, stretch or bend. Multiple overlapping clusters give local deformation instead of a single global one. Time integration is explicit and unconditionally stable because the goal is geometric.",
 "when_to_use": "Choose it for cheap jelly, plush and secondary-motion deformation in games. Prefer `xpbd` when you need volume constraints and calibrated stiffness, `position-based-dynamics` for cloth/ropes, and `vertex-block-descent` when you need accurate elasticity.",
 "cost": {
  "class": "cheap",
  "notes": "Cheap: a covariance and polar decomposition per cluster."
 },
 "failure_modes": [
  "Does not model true elasticity; large deformations look like a springy blob",
  "Polar decomposition can flip on inverted configurations",
  "Global fit makes the object too rigid, clusters give seams",
  "Stiffness is a blend factor, not a material parameter"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/1073204.1073216",
   "type": "paper",
   "title": "Meshless deformations based on shape matching",
   "authors": [
    "Matthias Müller",
    "Bruno Heidelberger",
    "Matthias Teschner",
    "Markus Gross"
   ],
   "year": 2005,
   "venue": "ACM Transactions on Graphics",
   "url": "https://doi.org/10.1145/1073204.1073216",
   "ids": {
    "doi": "10.1145/1073204.1073216"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1073204.1073216",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1073204.1073216",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1073204.1073216",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1073204.1073216",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1073204.1073216",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "mller2005meshless"
  }
 ],
 "presets": [
  {
   "id": "shape-matching-deformation-live",
   "title": "Shape Matching Deformation — meshless soft-body polar-decomposition goal lattice & elastic pull",
   "runtime": "glsl-fragment",
   "params": {
    "P_STIFFNESS": 0.62,
    "P_SQUASH_AMP": 1,
    "P_GOAL_VIS": 0.85,
    "P_BOUNCE_SPD": 1
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_STIFFNESS = 0.62; // P Stiffness Alpha [0.1, 1.0, 0.02]\nconst float P_SQUASH_AMP = 1.0; // P Impact Squash [0.2, 1.8, 0.05]\nconst float P_GOAL_VIS = 0.85; // P Goal Pose Overlay [0.0, 1.5, 0.05]\nconst float P_BOUNCE_SPD = 1.0; // P Bounce Speed [0.0, 2.5, 0.05]\n\nmat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }\n\nfloat sdSeg(vec2 p, vec2 a, vec2 b) {\n  vec2 pa = p - a;\n  vec2 ba = b - a;\n  float h = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-5), 0.0, 1.0);\n  return length(pa - ba * h);\n}\n\n// Compute bouncing rigid goal center, polar-decomposition rotation, and deformed lattice point\nvoid evalSoftBody(vec2 rest, float t, float stiff, float amp, out vec2 goalPos, out vec2 defPos) {\n  // Periodic bounce cycle on floor y = -0.34\n  float cyc = fract(t * 0.42);\n  float air = 4.0 * cyc * (1.0 - cyc);\n  float impact = exp(-pow((cyc - 0.03) * 8.0, 2.0)) + exp(-pow((cyc - 0.97) * 8.0, 2.0));\n  float centerY = -0.14 + air * 0.34;\n  float centerX = 0.14 * sin(t * 0.85);\n  float rotAng = 0.45 * sin(t * 1.1) + 0.18 * (1.0 - air);\n\n  // Best-fit rigid goal configuration g_i = R * q_i + c_cm\n  vec2 c = vec2(centerX, centerY);\n  goalPos = c + rot2(rotAng) * rest;\n\n  // Non-rigid squash-and-stretch + shear modes damped by shape-matching stiffness alpha\n  float compliance = (1.0 - stiff * 0.78) * amp;\n  float sy = 1.0 - 0.36 * impact * compliance + 0.14 * sin(t * 7.5) * compliance * 0.45;\n  float sx = 1.0 / max(sy, 0.45); // area-preserving deformation\n  float shear = 0.24 * cos(t * 2.6) * compliance * (rest.y + 0.16);\n\n  vec2 localDef = vec2(rest.x * sx + shear, rest.y * sy);\n  // Quadratic bend mode during impact\n  localDef.y += 0.35 * impact * compliance * (rest.x * rest.x - 0.018);\n\n  vec2 rawDef = c + rot2(rotAng) * localDef;\n  // Clamp against floor plane y = -0.34\n  rawDef.y = max(rawDef.y, -0.335);\n\n  // Shape matching pull: x_i <- x_i + alpha * (g_i - x_i)\n  defPos = mix(rawDef, goalPos, stiff * 0.48);\n  defPos.y = max(defPos.y, -0.335);\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 px = 1.0 / max(iResolution.y, 1.0);\n  float stiff = clamp(P_STIFFNESS, 0.08, 1.0);\n  float amp = clamp(P_SQUASH_AMP, 0.15, 2.0);\n  float goalVis = clamp(P_GOAL_VIS, 0.0, 1.5);\n  float t = iTime * max(P_BOUNCE_SPD, 0.0);\n\n  // Lab backdrop + floor\n  vec3 col = mix(vec3(0.025, 0.036, 0.058), vec3(0.056, 0.076, 0.118), smoothstep(-0.5, 0.5, uv.y));\n  vec2 grid = abs(fract(uv * 10.0 - 0.5) - 0.5);\n  col += vec3(0.015, 0.024, 0.040) * smoothstep(0.035, 0.008, min(grid.x, grid.y));\n\n  // Rigid floor surface at y = -0.34\n  if (uv.y < -0.34) {\n    float floorGrid = smoothstep(0.04, 0.01, abs(fract(uv.x * 8.0) - 0.5));\n    col = mix(vec3(0.07, 0.09, 0.13), vec3(0.14, 0.18, 0.25), floorGrid * 0.6);\n  }\n  col = mix(col, vec3(0.55, 0.72, 0.90), smoothstep(px * 3.0, px * 0.6, abs(uv.y + 0.34)) * 0.85);\n\n  // Evaluate 5x5 meshless particle grid (25 particles)\n  float bodyField = 0.0;\n  float dispSum = 0.0;\n  float minDef = 1e5;\n  float minGoal = 1e5;\n  float pullLine = 0.0;\n  float goalHull = 0.0;\n\n  for (int iy = 0; iy < 5; iy++) {\n    for (int ix = 0; ix < 5; ix++) {\n      vec2 rest = (vec2(float(ix), float(iy)) - 2.0) * 0.078;\n      vec2 gPos, dPos;\n      evalSoftBody(rest, t, stiff, amp, gPos, dPos);\n\n      float dd = length(uv - dPos);\n      float dg = length(uv - gPos);\n      minDef = min(minDef, dd);\n      minGoal = min(minGoal, dg);\n\n      float disp = length(gPos - dPos);\n      float w = exp(-dd * dd / 0.0036);\n      bodyField += w;\n      dispSum += w * disp;\n\n      // Elastic restoration vector alpha * (g_i - x_i)\n      float dPull = sdSeg(uv, dPos, gPos);\n      pullLine = max(pullLine, smoothstep(px * 2.6, px * 0.6, dPull) * smoothstep(0.004, 0.02, disp));\n\n      // Draw goal rigid wireframe boundary\n      if (ix < 4) {\n        vec2 gNext, dNext;\n        evalSoftBody(rest + vec2(0.078, 0.0), t, stiff, amp, gNext, dNext);\n        if (iy == 0 || iy == 4) {\n          goalHull = max(goalHull, smoothstep(px * 2.5, px * 0.6, sdSeg(uv, gPos, gNext)));\n        }\n      }\n      if (iy < 4) {\n        vec2 gNext, dNext;\n        evalSoftBody(rest + vec2(0.0, 0.078), t, stiff, amp, gNext, dNext);\n        if (ix == 0 || ix == 4) {\n          goalHull = max(goalHull, smoothstep(px * 2.5, px * 0.6, sdSeg(uv, gPos, gNext)));\n        }\n      }\n    }\n  }\n\n  // Smooth gelatin soft-body metaball fill colored by local displacement from rigid goal\n  float mask = smoothstep(0.32, 0.58, bodyField);\n  if (mask > 0.005) {\n    float avgDisp = clamp((dispSum / max(bodyField, 1e-4)) * 12.0, 0.0, 1.0);\n    vec3 softCol = mix(vec3(0.10, 0.66, 0.82), vec3(0.98, 0.52, 0.18), avgDisp);\n    float rim = smoothstep(0.95, 0.36, bodyField);\n    vec3 shaded = softCol * (0.62 + 0.38 * smoothstep(-0.35, 0.25, uv.y)) + vec3(0.85, 0.96, 1.0) * rim * 0.42;\n    col = mix(col, shaded, mask * 0.86);\n  }\n\n  // Overlay best-fit rigid goal frame (R * q_i + c), goal positions, and pull arrows\n  col = mix(col, vec3(0.98, 0.84, 0.32), goalHull * 0.72 * min(goalVis, 1.2));\n  col = mix(col, vec3(1.0, 0.92, 0.45), smoothstep(0.011, 0.005, minGoal) * 0.75 * min(goalVis, 1.2));\n  col += vec3(0.96, 0.42, 0.78) * pullLine * 0.85 * min(goalVis, 1.2);\n  col = mix(col, vec3(0.92, 0.98, 1.0), smoothstep(0.016, 0.007, minDef) * 0.88);\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": "shape-matching-deformation",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:53:35.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.388,
      "std": 0.2052,
      "min": 0.1996,
      "max": 0.9254
     },
     "image": "/specimens/shape-matching-deformation-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "position-based-dynamics",
  "xpbd",
  "linear-blend-skinning"
 ],
 "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/simulation/shape-matching-deformation.json"
 },
 "solves": [
  "want cheap jelly or plush squishy objects",
  "soft body without a volumetric mesh",
  "need stable secondary motion in games",
  "deformable objects explode with spring-based methods"
 ],
 "authority": "Müller et al., 2005",
 "url": "https://texelatlas.vercel.app/t/shape-matching-deformation/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 49.32,
  "tier": "heavy",
  "p50_ms": 1.5288,
  "p95_ms": 1.6285,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 36,
  "preset_id": "shape-matching-deformation-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 43.44,
   "tier": "heavy",
   "p50_ms": 0.6907,
   "p95_ms": 0.6935,
   "speedup_x": 2.21,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 33.35,
   "tier": "heavy",
   "p50_ms": 0.9605,
   "p95_ms": 0.9613,
   "speedup_x": 1.59,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}