{
 "id": "environment-mapping-cubemaps",
 "title": "Environment mapping, cubemaps and skyboxes",
 "aliases": [
  "cube mapping",
  "skybox",
  "reflection mapping",
  "HDRI backdrop",
  "environment map"
 ],
 "domain": "gi",
 "subdomain": "image-based lighting",
 "stage": "lighting",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal",
  "godot",
  "blender"
 ],
 "year_introduced": 1986,
 "inputs": [
  "hdr-image"
 ],
 "outputs": [
  "radiance"
 ],
 "style": "both",
 "dynamic": "both",
 "summary": "Store the light arriving from the distant surroundings in a six-face cubemap or equirectangular image, then look it up by direction for backgrounds, mirror reflections and, once prefiltered, diffuse and glossy lighting.",
 "how_it_works": "An environment map records incoming radiance as a function of direction only, which is exact when the light is far away compared with the object. The map is stored as six cube faces or a latitude-longitude image; a cubemap fetch converts a 3D direction into a face and texel, so there is no pole distortion and hardware filtering works across seams on modern GPUs.\n\nUses build on one lookup. The background is a draw at the far plane that samples the map with the view ray. A mirror reflection samples with `reflect(view, normal)`. Rough and diffuse lighting need the map convolved against a lobe, which is why engines prefilter it into mips ([split-sum-ibl](split-sum-ibl)) or project it into [spherical-harmonics-lighting](spherical-harmonics-lighting). Captured HDR data must stay in linear floating point; an LDR map clips the sun and makes every reflection look weak.\n\nThe map can be a photographed HDRI, a rendered sky ([hosek-wilkie-sky](hosek-wilkie-sky), [hillaire-sky-atmosphere](hillaire-sky-atmosphere)), or a capture from the scene itself.",
 "when_to_use": "Choose it for the backdrop, for sky and studio lighting, and for reflections of things that are effectively at infinity.\n\nPrefer [reflection-probes-parallax-corrected-cubemaps](reflection-probes-parallax-corrected-cubemaps) for interiors, where finite room size makes plain lookups look pasted on. Prefer [screen-space-reflections](screen-space-reflections) or [path-tracing](path-tracing) when nearby dynamic objects must appear in reflections. Prefer [split-sum-ibl](split-sum-ibl) for glossy PBR lighting from the same map rather than raw reflect lookups.",
 "cost": {
  "class": "cheap",
  "notes": "One texture fetch per pixel for lookup; memory is six faces per probe, and prefiltering is a one-time cost."
 },
 "failure_modes": [
  "Reflections have no parallax, so an object near a floor or wall looks as if its reflection were infinitely far away",
  "Seams along cube edges if filtering across faces is not enabled or if prefilter does not wrap",
  "Clipped suns and lights when the map is stored in 8 bits, making metals dull",
  "Equirectangular maps stretch and alias near the poles",
  "Reflected content cannot contain the object itself or any local dynamic light",
  "Mismatched handedness or axis convention flips the map horizontally or vertically between tools"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1109/mcg.1986.276658",
   "type": "paper",
   "title": "Environment Mapping and Other Applications of World Projections",
   "authors": [
    "Ned Greene"
   ],
   "year": 1986,
   "venue": "IEEE Computer Graphics and Applications",
   "url": "https://doi.org/10.1109/mcg.1986.276658",
   "ids": {
    "doi": "10.1109/mcg.1986.276658"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/mcg.1986.276658",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/mcg.1986.276658",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/mcg.1986.276658",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/mcg.1986.276658",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/mcg.1986.276658",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "greene1986environment"
  },
  {
   "role": "tutorial",
   "key": "url:https://google.github.io/filament/Filament.html",
   "type": "tutorial",
   "title": "Filament: Physically based rendering (image based lights section)",
   "authors": [
    "Romain Guy",
    "Mathias Agopian"
   ],
   "year": null,
   "venue": "google.github.io",
   "url": "https://google.github.io/filament/Filament.html",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261105144234/https://google.github.io/filament/Filament.html",
     "timestamp": "20261105144234"
    },
    "page_title": "Redirecting...",
    "host": "google.github.io",
    "title_confirmed_by_page": false,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://google.github.io/filament/Filament.html → 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://google.github.io/filament/Filament.html → 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,
   "__bib": "guyfilament"
  },
  {
   "role": "implementation",
   "key": "gh:google/filament",
   "type": "code",
   "title": "google/filament",
   "description": "Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, WebGPU, and WebGL2",
   "authors": [
    "google"
   ],
   "year": 2018,
   "venue": "GitHub",
   "url": "https://github.com/google/filament",
   "ids": {
    "repo": "google/filament"
   },
   "license": "Apache-2.0",
   "extra": {
    "stars": 20815,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-25T07:40:17Z",
    "language": "C++",
    "homepage": "https://google.github.io/filament/",
    "license_name": "Apache License 2.0"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/google/filament",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/google/filament",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/google/filament",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/google/filament",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/google/filament",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/google/filament",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "google2018google"
  }
 ],
 "presets": [
  {
   "id": "environment-mapping-cubemaps-live",
   "title": "Environment Mapping & Cubemaps — unfolded 6-face cubemap cross & mip blur (left) vs seamless 3D skybox & glossy IBL spheres (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_ROUGHNESS": 0.18,
    "P_SUN_ELEV": 0.36,
    "P_CAM_ORBIT": 0.35,
    "P_SPLIT": 0.46
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_ROUGHNESS = 0.18; // P IBL Roughness [0.0, 0.9, 0.03]\nconst float P_SUN_ELEV = 0.36; // P Sun Elevation [0.08, 0.85, 0.03]\nconst float P_CAM_ORBIT = 0.35; // P Orbit Speed [0.0, 1.5, 0.05]\nconst float P_SPLIT = 0.46; // P Cross / 3D Split [0.0, 1.0, 0.02]\n\n// Analytic procedural HDR cubemap sampled by unit direction d and prefilter roughness r\nvec3 evalCubemap(vec3 d, float rough, float sunElev) {\n  d = normalize(d);\n  vec3 sunDir = normalize(vec3(0.72, sunElev, -0.58));\n  float blur = clamp(rough, 0.0, 1.0);\n\n  // Sky zenith-to-horizon gradient with warm sunset scattering\n  vec3 zenith = vec3(0.10, 0.24, 0.58);\n  vec3 horizon = mix(vec3(0.95, 0.56, 0.30), vec3(0.65, 0.78, 0.94), smoothstep(0.15, 0.70, sunElev));\n  vec3 ground = vec3(0.12, 0.11, 0.13);\n\n  float upT = smoothstep(-0.04 - blur * 0.35, 0.55 + blur * 0.25, d.y);\n  vec3 sky = mix(horizon, zenith, upT);\n  float gndT = smoothstep(0.02 + blur * 0.25, -0.18 - blur * 0.35, d.y);\n  vec3 col = mix(sky, ground, gndT);\n\n  // Distant mountain silhouette band around the horizon\n  float az = atan(d.z, d.x);\n  float mtnH = 0.055 + 0.045 * sin(az * 3.0 + 0.5) + 0.028 * cos(az * 7.0 - 1.1) + 0.015 * sin(az * 13.0);\n  float mtnMask = smoothstep(mtnH + 0.012 + blur * 0.14, mtnH - 0.012 - blur * 0.10, d.y) * smoothstep(-0.08, 0.01, d.y);\n  col = mix(col, vec3(0.14, 0.16, 0.24) + vec3(0.22, 0.14, 0.10) * max(dot(d, sunDir), 0.0), mtnMask * (1.0 - blur * 0.65));\n\n  // Soft volumetric cloud deck\n  float cl = sin(az * 4.0 + d.y * 9.0) * cos(az * 6.0 - d.y * 5.0);\n  float clBand = smoothstep(0.15, 0.45, d.y) * smoothstep(0.75, 0.35, d.y) * smoothstep(0.15, 0.72, cl);\n  col = mix(col, mix(vec3(0.96, 0.86, 0.78), vec3(0.72, 0.78, 0.88), blur), clBand * 0.42 * (1.0 - blur * 0.5));\n\n  // Pre-filtered solar disc + Mie aureole\n  float sunCos = max(dot(d, sunDir), 0.0);\n  float sunExp = mix(220.0, 6.0, blur * blur);\n  float sunGain = mix(6.5, 0.95, blur);\n  col += vec3(1.0, 0.86, 0.62) * (pow(sunCos, sunExp) * sunGain + pow(sunCos, 8.0) * 0.42);\n  return col;\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 sx = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  bool show3D = sx >= split;\n\n  float rough = clamp(P_ROUGHNESS, 0.0, 0.95);\n  float sunElev = clamp(P_SUN_ELEV, 0.06, 0.88);\n  float orb = iTime * max(P_CAM_ORBIT, 0.0);\n\n  vec3 col = vec3(0.05, 0.06, 0.09);\n\n  if (!show3D) {\n    // Left: Horizontal 4x3 cubemap cross layout (-X, +Z, +X, -Z across middle; +Y top; -Y bottom)\n    vec2 p = vec2(sx / max(split, 0.05), fragCoord.y / max(iResolution.y, 1.0));\n    vec2 g = (p - vec2(0.06, 0.14)) / vec2(0.88, 0.72);\n    vec2 cell = floor(g * vec2(4.0, 3.0));\n    vec2 f = fract(g * vec2(4.0, 3.0)) * 2.0 - 1.0;\n\n    bool valid = false;\n    vec3 dir = vec3(0.0, 0.0, 1.0);\n    vec3 faceTint = vec3(1.0);\n\n    if (cell.y == 1.0 && cell.x >= 0.0 && cell.x < 4.0) {\n      valid = true;\n      if (cell.x == 0.0) { dir = vec3(-1.0, f.y, f.x); faceTint = vec3(1.0, 0.45, 0.45); }\n      else if (cell.x == 1.0) { dir = vec3(f.x, f.y, 1.0); faceTint = vec3(0.45, 0.85, 1.0); }\n      else if (cell.x == 2.0) { dir = vec3(1.0, f.y, -f.x); faceTint = vec3(0.95, 0.72, 0.35); }\n      else { dir = vec3(-f.x, f.y, -1.0); faceTint = vec3(0.65, 0.55, 1.0); }\n    } else if (cell.x == 1.0 && cell.y == 2.0) {\n      valid = true;\n      dir = vec3(f.x, 1.0, -f.y);\n      faceTint = vec3(0.45, 1.0, 0.65);\n    } else if (cell.x == 1.0 && cell.y == 0.0) {\n      valid = true;\n      dir = vec3(f.x, -1.0, f.y);\n      faceTint = vec3(0.85, 0.65, 0.45);\n    }\n\n    if (valid) {\n      col = evalCubemap(dir, rough, sunElev);\n      // Clean cubemap face border\n      float edge = smoothstep(0.93, 0.985, max(abs(f.x), abs(f.y)));\n      col = mix(col, faceTint * 1.15, edge);\n    } else {\n      vec2 bgG = abs(fract(p * 18.0) - 0.5);\n      col = vec3(0.05, 0.06, 0.09) + vec3(0.025, 0.035, 0.05) * smoothstep(0.06, 0.01, min(0.5 - bgG.x, 0.5 - bgG.y));\n    }\n  } else {\n    // Right: Seamless 3D skybox + chrome mirror ball (center) + prefiltered glossy/diffuse companion spheres\n    vec3 ro = vec3(2.35 * sin(orb), 0.16, 2.35 * cos(orb));\n    vec3 fw = normalize(-ro);\n    vec3 ri = normalize(cross(fw, vec3(0.0, 1.0, 0.0)));\n    vec3 up = cross(ri, fw);\n    vec3 rd = normalize(fw * 1.38 + ri * (uv.x - 0.18) + up * uv.y);\n\n    col = evalCubemap(rd, 0.0, sunElev);\n\n    // Intersect 3 IBL chrome/glossy/matte spheres\n    vec3 centers[3];\n    float radii[3];\n    float rVals[3];\n    centers[0] = vec3(0.0, 0.02, 0.0); radii[0] = 0.52; rVals[0] = rough;\n    centers[1] = vec3(-0.74, -0.22, 0.25); radii[1] = 0.24; rVals[1] = 0.03;\n    centers[2] = vec3(0.74, -0.22, -0.18); radii[2] = 0.24; rVals[2] = 0.82;\n\n    float bestT = 1e5;\n    int bestI = -1;\n    for (int i = 0; i < 3; i++) {\n      vec3 oc = ro - centers[i];\n      float b = dot(oc, rd);\n      float c = dot(oc, oc) - radii[i] * radii[i];\n      float disc = b * b - c;\n      if (disc > 0.0) {\n        float t = -b - sqrt(disc);\n        if (t > 0.05 && t < bestT) { bestT = t; bestI = i; }\n      }\n    }\n\n    if (bestI >= 0) {\n      vec3 p = ro + rd * bestT;\n      vec3 n = normalize(p - centers[bestI]);\n      vec3 v = -rd;\n      vec3 rDir = reflect(-v, n);\n      float r = rVals[bestI];\n      vec3 f0 = (bestI == 0) ? vec3(0.95, 0.78, 0.45) : ((bestI == 1) ? vec3(0.94) : vec3(0.32, 0.48, 0.62));\n      float ndv = max(dot(n, v), 0.0);\n      vec3 F = f0 + (1.0 - f0) * pow(1.0 - ndv, 5.0);\n      vec3 specIBL = evalCubemap(rDir, r, sunElev);\n      vec3 diffIBL = evalCubemap(n, 0.92, sunElev) * 0.55;\n      col = mix(specIBL * F, diffIBL * f0 + specIBL * F * 0.35, r * 0.75);\n    }\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(sx - split));\n  col = mix(col, vec3(0.95, 0.97, 1.0), sep);\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "reduced-sandbox",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "environment-mapping-cubemaps",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T21:07:08.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.4862,
      "std": 0.1968,
      "min": 0.2744,
      "max": 0.9955
     },
     "image": "/specimens/environment-mapping-cubemaps-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "split-sum-ibl",
  "spherical-harmonics-lighting",
  "reflection-probes-parallax-corrected-cubemaps",
  "hosek-wilkie-sky",
  "irradiance-volumes"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "split-sum-ibl",
   "why": "The raw environment map is the input that gets convolved per roughness into the prefiltered mip chain."
  },
  {
   "id": "spherical-harmonics-lighting",
   "why": "The same map projects to nine SH coefficients for cheap diffuse lighting."
  },
  {
   "id": "hillaire-sky-atmosphere",
   "why": "A rendered sky can be captured into a cubemap each time the sun moves, giving a dynamic environment."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/gi/environment-mapping-cubemaps.json"
 },
 "solves": [
  "need a skybox or hdri background behind the scene",
  "want cheap fake reflections of the surroundings on shiny objects",
  "metal looks dull without anything to reflect",
  "how to store light from all directions in a texture"
 ],
 "authority": "Greene, 1986",
 "url": "https://texelatlas.vercel.app/t/environment-mapping-cubemaps/",
 "execution_fidelity": "reduced-sandbox",
 "fidelity_label": "Analytic Sandbox",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 4.91,
  "tier": "light",
  "p50_ms": 0.1615,
  "p95_ms": 0.1712,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "environment-mapping-cubemaps-live",
  "execution_fidelity": "reduced-sandbox",
  "fidelity_label": "Analytic Sandbox",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 4.26,
   "tier": "light",
   "p50_ms": 0.0678,
   "p95_ms": 0.0706,
   "speedup_x": 2.38,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 3.49,
   "tier": "light",
   "p50_ms": 0.1004,
   "p95_ms": 0.1038,
   "speedup_x": 1.61,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}