{
 "id": "cube-sphere-mapping",
 "title": "Cube-Sphere Planet Mapping",
 "aliases": [
  "spherified cube",
  "quadrilateralized spherical cube",
  "planet cube mapping"
 ],
 "domain": "procgen",
 "subdomain": "planets",
 "stage": "procedural",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "cpu",
  "unity",
  "unreal",
  "godot"
 ],
 "year_introduced": 2013,
 "inputs": [],
 "outputs": [
  "mesh",
  "heightfield",
  "texture"
 ],
 "style": "both",
 "dynamic": "static",
 "summary": "Map a cube's six faces onto a sphere so a planet can be built from six square quadtrees: far less polar distortion than lat-long grids, uniform tiles for LOD, and trivial cube-map lookups.",
 "how_it_works": "A point on a cube face is normalised to the sphere, or better mapped with an equal-area correction (tan warping or the 'spherified cube' formula) that reduces the shrinking of cells toward face centres. Each face carries a quadtree of square tiles that subdivide with camera proximity, each tile evaluating a 3D noise or heightmap sampled at the sphere position, which avoids seams because noise is a function of 3D position, not 2D face uv. Matching edge vertices (stitching or skirts) between neighbouring tiles at different LODs prevents cracks. Because each face is regular, cube maps and per-face texture atlases work directly, unlike a UV sphere, which pinches at poles.",
 "when_to_use": "Choose it for planetary terrain with LOD streaming, procedural planet generation and sky/cube-map lookups. Prefer lat-long UV spheres only for small, static globes, an icosphere when you need near-uniform triangles with no faces to stitch, and `fractal-brownian-motion` sampled in 3D as the height source on whichever mesh you use.",
 "cost": {
  "class": "cheap",
  "notes": "Mapping is a few arithmetic operations per vertex; cost depends on LOD scheme and noise octaves."
 },
 "failure_modes": [
  "Naive normalisation squashes cells toward cube corners and stretches them toward face centres, giving uneven texel density",
  "Cracks along face and LOD boundaries unless skirts or stitching are used",
  "2D noise per face produces visible seams at cube edges; sample 3D noise on the sphere position instead",
  "Floating-point precision at planetary scale needs camera-relative or origin-shifted rendering"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://acko.net/blog/making-worlds-1-of-spheres-and-cubes",
   "type": "web",
   "title": "Making Worlds 1 - Of Spheres and Cubes",
   "authors": [
    "Steven Wittens"
   ],
   "year": null,
   "venue": "acko.net",
   "url": "https://acko.net/blog/making-worlds-1-of-spheres-and-cubes",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20260315221213/https://acko.net/blog/making-worlds-1-of-spheres-and-cubes/",
     "timestamp": "20260315221213"
    },
    "page_title": "Making Worlds 1 - Of Spheres and Cubes — Acko.net",
    "host": "acko.net",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://acko.net/blog/making-worlds-1-of-spheres-and-cubes → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://acko.net/blog/making-worlds-1-of-spheres-and-cubes → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "http",
     "endpoint": "GET https://acko.net/blog/making-worlds-1-of-spheres-and-cubes → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 0.95,
   "__bib": "wittensmaking"
  }
 ],
 "presets": [
  {
   "id": "cube-sphere-mapping-specimen",
   "title": "Cube-sphere mapping: plain cube faces (left) vs tangent-warped faces (right)",
   "runtime": "glsl-fragment",
   "params": {
    "GRID": 6
   },
   "code": "// Cube-to-sphere mapping: left sphere = plain gnomonic cube faces, right = tangent-warped faces.\nconst float GRID = 6.0;\nfloat warp(float u, bool on) { return on ? tan(u * 0.7853982) : u; }\nfloat unwarp(float u, bool on) { return on ? atan(u) * 1.2732395 : u; }\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n    vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n    bool right = uv.x > 0.0;\n    vec2 p = uv - vec2(right ? 0.5 : -0.5, 0.0);\n    vec3 col = vec3(0.06, 0.07, 0.09) + 0.05 * uv.y;\n    float r2 = dot(p, p), R = 0.44;\n    if (r2 < R * R) {\n        float z = sqrt(R * R - r2);\n        vec3 n = normalize(vec3(p, z));\n        float a = iTime * 0.0 + 0.6;\n        mat2 rot = mat2(cos(a), -sin(a), sin(a), cos(a));\n        n.xz = rot * n.xz; n.yz = mat2(cos(0.5), -sin(0.5), sin(0.5), cos(0.5)) * n.yz;\n        vec3 an = abs(n); vec2 f; vec3 base;\n        if (an.x > an.y && an.x > an.z) { f = n.yz / an.x; base = vec3(0.85, 0.35, 0.3); }\n        else if (an.y > an.z) { f = n.xz / an.y; base = vec3(0.35, 0.8, 0.4); }\n        else { f = n.xy / an.z; base = vec3(0.35, 0.5, 0.9); }\n        vec2 g = vec2(unwarp(f.x, right), unwarp(f.y, right)) * 0.5 + 0.5;\n        vec2 cell = fract(g * GRID);\n        float line = min(min(cell.x, 1.0 - cell.x), min(cell.y, 1.0 - cell.y));\n        vec2 id = floor(g * GRID);\n        float chk = mod(id.x + id.y, 2.0);\n        vec3 c = base * (0.55 + 0.35 * chk);\n        c = mix(vec3(0.05), c, smoothstep(0.0, 0.07, line));\n        vec3 sn = normalize(vec3(p, z));\n        float dif = max(dot(sn, normalize(vec3(-0.4, 0.6, 0.7))), 0.0);\n        col = c * (0.25 + 0.85 * dif);\n    }\n    col = mix(col, vec3(0.9), smoothstep(0.004, 0.0, abs(uv.x)));\n    fragColor = vec4(pow(col, vec3(0.45)), 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": "cube-sphere-mapping",
     "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.4154,
      "std": 0.1598,
      "unique_colors": 241
     },
     "image": "/specimens/cube-sphere-mapping-specimen.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "fractal-brownian-motion",
  "perlin-noise",
  "improved-perlin-noise",
  "simplex-noise"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "simplex-noise",
   "why": "3D noise sampled at the sphere position gives seamless planetary heights across cube faces."
  }
 ],
 "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/cube-sphere-mapping.json"
 },
 "solves": [
  "pole pinching ruins my planet texture",
  "uv sphere has distorted triangles near the poles",
  "building a planet from tiles with level of detail",
  "need even tile sizes for streaming planetary terrain",
  "sky or planet lookup without polar distortion"
 ],
 "authority": "Wittens",
 "url": "https://texelatlas.vercel.app/t/cube-sphere-mapping/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 1.86,
  "tier": "feather",
  "p50_ms": 0.0613,
  "p95_ms": 0.0655,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "cube-sphere-mapping-specimen",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 1.48,
   "tier": "feather",
   "p50_ms": 0.0236,
   "p95_ms": 0.024,
   "speedup_x": 2.6,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 1.24,
   "tier": "feather",
   "p50_ms": 0.0358,
   "p95_ms": 0.0359,
   "speedup_x": 1.71,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}