{
 "id": "lscm-uv-unwrapping",
 "title": "Least Squares Conformal Maps",
 "aliases": [],
 "domain": "geometry",
 "subdomain": "UV parameterization",
 "stage": "geometry",
 "realtime": "interactive",
 "platforms": [
  "cpu",
  "blender"
 ],
 "year_introduced": 2002,
 "inputs": [
  "mesh"
 ],
 "outputs": [
  "uv-atlas"
 ],
 "style": "both",
 "dynamic": "static",
 "summary": "Computes a UV parameterization of a mesh chart by minimising the deviation from a conformal (angle-preserving) map with a linear least-squares solve, pinning two vertices to remove the rigid-body freedom.",
 "how_it_works": "The Cauchy-Riemann equations say a map is conformal when its gradient is a rotation plus scale. On a triangle mesh, each triangle is expressed in a local orthonormal basis and the conformality error is a quadratic function of the UV coordinates. Summing the squared errors over triangles gives a sparse least-squares system. A pair of vertices is pinned to fix translation, rotation and scale (or boundary conditions are provided); solving the symmetric positive-definite system gives UVs that preserve angles as well as possible. The method works with free boundaries, so a disc-topology chart takes its natural shape. Charts are usually produced by cutting seams along a spanning tree or by a segmentation step beforehand, and area distortion is often fixed by a following packing/scaling stage.",
 "when_to_use": "Choose it for quick, stable unwrapping of a single disc-like chart: hand-seam workflows, texture painting and baking. Prefer `xatlas` when you need automatic chart segmentation and packing of the whole mesh, `geometry-images` when you want a single square chart for the entire surface, and an area-preserving method when texel density must be uniform.",
 "cost": {
  "class": "interactive",
  "notes": "One sparse linear solve per chart; sub-second for typical charts with tens of thousands of triangles."
 },
 "failure_modes": [
  "Angle preservation means area can blow up: large stretch near sharp cone-like regions",
  "Flipped triangles can still appear since the objective does not forbid them",
  "Depends on which two vertices are pinned and on the seam layout",
  "Charts with high Gaussian curvature need many seams, creating visible texture breaks"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/566570.566590",
   "type": "paper",
   "title": "Least squares conformal maps for automatic texture atlas generation",
   "authors": [
    "Bruno Lévy",
    "Sylvain Petitjean",
    "Nicolas Ray",
    "Jérome Maillot"
   ],
   "year": 2002,
   "venue": "Proceedings of the 29th annual conference on Computer graphics and interactive techniques",
   "url": "https://doi.org/10.1145/566570.566590",
   "ids": {
    "doi": "10.1145/566570.566590"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/566570.566590",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/566570.566590",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/566570.566590",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/566570.566590",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/566570.566590",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "lvy2002least"
  },
  {
   "role": "implementation",
   "key": "gh:jpcy/xatlas",
   "type": "code",
   "title": "jpcy/xatlas",
   "description": "Mesh parameterization / UV unwrapping library",
   "authors": [
    "jpcy"
   ],
   "year": 2018,
   "venue": "GitHub",
   "url": "https://github.com/jpcy/xatlas",
   "ids": {
    "repo": "jpcy/xatlas"
   },
   "license": "MIT",
   "extra": {
    "stars": 2633,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2024-06-16T22:20:33Z",
    "language": "C++",
    "homepage": null,
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/jpcy/xatlas",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/jpcy/xatlas",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/jpcy/xatlas",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/jpcy/xatlas",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/jpcy/xatlas",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/jpcy/xatlas",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "jpcy2018jpcy"
  }
 ],
 "presets": [
  {
   "id": "lscm-uv-unwrapping-live",
   "title": "Least Squares Conformal Maps — sheared planar UV (left) vs angle-preserving conformal UV & Tissot circles (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_UV_FREQ": 8,
    "P_TISSOT_CIRCLES": 0.85,
    "P_SPLIT": 0.45,
    "P_ROT_SPEED": 1
   },
   "basis": "original",
   "license_note": "Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).",
   "code": "const float P_UV_FREQ = 8.0; // P Checker Density [4.0, 16.0, 1.0]\nconst float P_TISSOT_CIRCLES = 0.85; // P Tissot Indicatrix [0.0, 1.5, 0.05]\nconst float P_SPLIT = 0.45; // P Planar / LSCM Split [0.0, 1.0, 0.02]\nconst float P_ROT_SPEED = 1.0; // P Spin 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\n// Sculpted undulating hourglass/vase manifold with strong positive & negative Gaussian curvature\nfloat mapSurface(vec3 p, float spin) {\n  vec3 q = p;\n  q.xz = rot2(spin * 0.35) * q.xz;\n  q.yz = rot2(0.28) * q.yz;\n  float ang = atan(q.z, q.x);\n  float profileR = 0.56 + 0.22 * cos(q.y * 3.8) + 0.08 * sin(ang * 3.0) * cos(q.y * 2.2);\n  float dCyl = length(q.xz) - profileR;\n  float dCap = abs(q.y) - 0.82;\n  vec2 w = vec2(dCyl, dCap);\n  return (min(max(w.x, w.y), 0.0) + length(max(w, 0.0)) - 0.04) * 0.72;\n}\n\nvec3 calcNormal(vec3 p, float spin) {\n  vec2 e = vec2(0.0025, 0.0);\n  return normalize(vec3(\n    mapSurface(p + e.xyy, spin) - mapSurface(p - e.xyy, spin),\n    mapSurface(p + e.yxy, spin) - mapSurface(p - e.yxy, spin),\n    mapSurface(p + e.yyx, spin) - mapSurface(p - e.yyx, spin)\n  ));\n}\n\n// Evaluate UV checkerboard + Tissot indicatrix circles (circles stay strictly circular ONLY under conformal maps!)\nvec3 evalUvPattern(vec2 uvTex, float freq, float tissotAmt, float scaleFactor) {\n  vec2 g = uvTex * freq;\n  vec2 cell = floor(g);\n  vec2 f = fract(g) - 0.5;\n  float chk = mod(cell.x + cell.y, 2.0);\n  // Subtle conformal area-scale color ramp (teal = compressed, ivory = neutral, amber = expanded)\n  vec3 scaleTint = mix(vec3(0.18, 0.62, 0.84), vec3(0.95, 0.64, 0.24), clamp(scaleFactor, 0.0, 1.0));\n  vec3 base = mix(vec3(0.16, 0.20, 0.26), mix(vec3(0.86, 0.88, 0.90), scaleTint, 0.45), chk);\n\n  // Orthogonal UV gridlines (preserve exact 90-degree crossings under LSCM!)\n  float gridLine = smoothstep(0.055, 0.015, min(abs(f.x), abs(f.y)));\n  base = mix(base, vec3(0.06, 0.09, 0.14), gridLine * 0.45);\n\n  // Tissot indicatrix circles centered in every UV tile: distortion reveals shear immediately!\n  if (tissotAmt > 0.01) {\n    float r = length(f);\n    float ring = smoothstep(0.055, 0.012, abs(r - 0.28));\n    base = mix(base, vec3(0.98, 0.34, 0.32), ring * 0.82 * min(tissotAmt, 1.2));\n  }\n  return base;\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  float freq = clamp(floor(P_UV_FREQ + 0.5), 3.0, 18.0);\n  float tissot = clamp(P_TISSOT_CIRCLES, 0.0, 1.5);\n  float spin = iTime * max(P_ROT_SPEED, 0.0);\n\n  vec3 ro = vec3(0.0, 0.08, 2.55);\n  vec3 rd = normalize(vec3(uv, -1.52));\n\n  vec3 col = mix(vec3(0.03, 0.042, 0.068), vec3(0.092, 0.118, 0.170), smoothstep(-0.55, 0.55, uv.y));\n  vec2 bgG = abs(fract(uv * 10.0 - 0.5) - 0.5);\n  col += vec3(0.018, 0.028, 0.045) * smoothstep(0.03, 0.0, min(bgG.x, bgG.y));\n\n  float t = 0.0;\n  bool hit = false;\n  for (int i = 0; i < 64; i++) {\n    float d = mapSurface(ro + rd * t, spin);\n    if (d < 0.002) { hit = true; break; }\n    t += d;\n    if (t > 9.0) break;\n  }\n\n  if (hit) {\n    vec3 p = ro + rd * t;\n    vec3 n = calcNormal(p, spin);\n\n    // Object-space coordinates on the curved surface of revolution\n    vec3 objP = p;\n    objP.xz = rot2(spin * 0.35) * objP.xz;\n    objP.yz = rot2(0.28) * objP.yz;\n\n    // Left: Naive Planar UV projection (causes severe shear & stretched Tissot ellipses on curved flanks!)\n    vec2 naiveUV = objP.xy * 0.65;\n\n    // Right: Exact Isothermal / Conformal LSCM parameterization!\n    // For a surface of revolution r(y), conformal coordinate satisfies dv = ds / r(y) so metric is isotropic: ds^2 = r^2(du^2 + dv^2)!\n    float theta = atan(objP.z, objP.x);\n    float rSurf = max(length(objP.xz), 0.18);\n    // Integrate meridian arc-length / r(y) using 6-tap midpoint quadrature for true angle-preserving LSCM UV!\n    float vConf = 0.0;\n    float dy = objP.y / 6.0;\n    for (int k = 0; k < 6; k++) {\n      float ym = (float(k) + 0.5) * dy;\n      float rm = 0.56 + 0.22 * cos(ym * 3.8) + 0.08 * sin(theta * 3.0) * cos(ym * 2.2);\n      float drdy = -0.22 * 3.8 * sin(ym * 3.8) - 0.08 * 2.2 * sin(theta * 3.0) * sin(ym * 2.2);\n      float ds = sqrt(1.0 + drdy * drdy) * dy;\n      vConf += ds / max(rm, 0.22);\n    }\n    vec2 lscmUV = vec2(theta / 3.14159265, vConf / 3.14159265);\n    float confScale = clamp((rSurf - 0.32) / 0.50, 0.0, 1.0);\n\n    bool isLscm = screenX >= split;\n    vec3 alb = isLscm\n      ? evalUvPattern(lscmUV, freq, tissot, confScale)\n      : evalUvPattern(naiveUV, freq, tissot, 0.5);\n\n    vec3 l1 = normalize(vec3(0.62, 0.86, 0.55));\n    vec3 l2 = normalize(vec3(-0.75, -0.22, 0.52));\n    float diff1 = max(dot(n, l1), 0.0);\n    float diff2 = max(dot(n, l2), 0.0);\n    vec3 hVec = normalize(l1 - rd);\n    float spec = pow(max(dot(n, hVec), 0.0), 42.0) * 0.42;\n    float rim = pow(1.0 - max(dot(n, -rd), 0.0), 3.0) * 0.26;\n\n    col = alb * (0.28 + 0.82 * diff1 + 0.24 * diff2) + vec3(spec) + vec3(0.45, 0.72, 1.0) * rim;\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": "lscm-uv-unwrapping",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:04:32.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.5938,
      "std": 0.202,
      "min": 0.2119,
      "max": 0.926
     },
     "image": "/specimens/lscm-uv-unwrapping-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "xatlas",
  "geometry-images",
  "heat-method-geodesics"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "xatlas",
   "why": "The atlas generator uses chart-level parameterization of this sort before packing."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/geometry/lscm-uv-unwrapping.json"
 },
 "solves": [
  "need quick uvs for a single patch after marking seams",
  "texture stretches when unwrapping a mesh section",
  "angle-preserving unwrap for painting",
  "unfold a disc-like chart without much shear",
  "uv map for baking a hand-seamed piece"
 ],
 "authority": "Lévy et al., 2002",
 "url": "https://texelatlas.vercel.app/t/lscm-uv-unwrapping/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 25.7,
  "tier": "heavy",
  "p50_ms": 0.8069,
  "p95_ms": 0.8204,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "lscm-uv-unwrapping-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 21.56,
   "tier": "heavy",
   "p50_ms": 0.3406,
   "p95_ms": 0.3467,
   "speedup_x": 2.37,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 15.36,
   "tier": "moderate",
   "p50_ms": 0.4425,
   "p95_ms": 0.4485,
   "speedup_x": 1.82,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}