{
 "id": "preetham-sky",
 "title": "Preetham Analytic Daylight Model",
 "aliases": [
  "Perez sky",
  "A Practical Analytic Model for Daylight"
 ],
 "domain": "volumes",
 "subdomain": "atmosphere",
 "stage": "volume",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu"
 ],
 "year_introduced": 1999,
 "inputs": [
  "material-params"
 ],
 "outputs": [
  "radiance",
  "hdr-image"
 ],
 "style": "photoreal",
 "dynamic": "dynamic",
 "summary": "Closed-form sky luminance and chromaticity as a function of sun position and turbidity, using Perez distribution coefficients fitted to simulations; trivial to run per pixel.",
 "how_it_works": "The model computes the xyY color of any sky direction. Luminance and the two chromaticities each follow a Perez formula: a product of a gradient term over zenith angle and a scattering-indicatrix term over the angle to the sun, normalized by the same expression evaluated at the zenith. The five Perez coefficients for each channel are linear functions of turbidity, and the zenith values are polynomial fits of turbidity and sun elevation. Aerial perspective is a separate approximate analytic extinction and in-scatter along the ray. Everything is evaluated in a fragment shader from a handful of constants, then converted xyY to RGB and tonemapped. Turbidity (roughly clear to hazy) is the main art control.",
 "when_to_use": "Choose it for a quick, cheap sky dome with turbidity and sun-angle sliders, for background skies in demos, and for feeding a plausible environment light into image-based lighting.\n\nPrefer `hosek-wilkie-sky` for better accuracy near the horizon and in the circumsolar region, and for ground-albedo control. Prefer `hillaire-sky-atmosphere` or `precomputed-atmospheric-scattering` when the camera leaves the ground, you need sunsets below the horizon, or you need atmosphere on geometry.",
 "cost": {
  "class": "cheap",
  "notes": "A few dozen ALU operations per pixel, no textures."
 },
 "failure_modes": [
  "Sky below the horizon and around sunset is unreliable; the fit was made for sun elevations above the horizon",
  "Overly dark or saturated zenith at low turbidity and low sun",
  "Perez term overestimates glow near the horizon, producing a flat white band",
  "Only valid from ground level: no altitude, no planet curvature, no space view",
  "Circumsolar region is smooth, so there is no realistic sun disc, only an added blob"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/311535.311545",
   "type": "paper",
   "title": "A practical analytic model for daylight",
   "authors": [
    "A. J. Preetham",
    "Peter Shirley",
    "Brian Smits"
   ],
   "year": 1999,
   "venue": "Proceedings of the 26th annual conference on Computer graphics and interactive techniques  - SIGGRAPH '99",
   "url": "https://doi.org/10.1145/311535.311545",
   "ids": {
    "doi": "10.1145/311535.311545"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/311535.311545",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/311535.311545",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/311535.311545",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/311535.311545",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/311535.311545",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "preetham1999practical"
  },
  {
   "role": "implementation",
   "key": "gh:mrdoob/three.js",
   "type": "code",
   "title": "mrdoob/three.js",
   "description": "JavaScript 3D Library.",
   "authors": [
    "mrdoob"
   ],
   "year": 2010,
   "venue": "GitHub",
   "url": "https://github.com/mrdoob/three.js",
   "ids": {
    "repo": "mrdoob/three.js"
   },
   "license": "MIT",
   "extra": {
    "stars": 119718,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-29T11:39:51Z",
    "language": "JavaScript",
    "homepage": "https://threejs.org/",
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "mrdoob2010mrdoob"
  }
 ],
 "presets": [
  {
   "id": "preetham-sky-specimen",
   "title": "Preetham analytic sky: turbidity 2 (left) vs 8 (right)",
   "runtime": "glsl-fragment",
   "params": {
    "turbidity_left": 2,
    "turbidity_right": 8
   },
   "code": "// Preetham analytic daylight sky (Perez luminance distribution in xyY, turbidity-driven coefficients).\n// Same view and sun in both halves; only turbidity changes: left T=2 (clear), right T=8 (hazy).\nvec3 preetham(vec3 rd, vec3 sd, float T) {\n  float ts = acos(clamp(sd.y, -1.0, 1.0));\n  float ct = max(rd.y, 0.02);\n  float gam = acos(clamp(dot(rd, sd), -1.0, 1.0));\n  vec3 cA = vec3(0.1787 * T - 1.4630, -0.0193 * T - 0.2592, -0.0167 * T - 0.2608);\n  vec3 cB = vec3(-0.3554 * T + 0.4275, -0.0665 * T + 0.0008, -0.0950 * T + 0.0092);\n  vec3 cC = vec3(-0.0227 * T + 5.3251, -0.0004 * T + 0.2125, -0.0079 * T + 0.2102);\n  vec3 cD = vec3(0.1206 * T - 2.5771, -0.0641 * T - 0.8989, -0.0441 * T - 1.6537);\n  vec3 cE = vec3(-0.0670 * T + 0.3703, -0.0033 * T + 0.0452, -0.0109 * T + 0.0529);\n  float chi = (4.0 / 9.0 - T / 120.0) * (3.14159 - 2.0 * ts);\n  float Yz = (4.0453 * T - 4.9710) * tan(chi) - 0.2155 * T + 2.4192;\n  float t2 = ts * ts, t3 = t2 * ts;\n  float xz = T * T * (0.00166 * t3 - 0.00375 * t2 + 0.00209 * ts) + T * (-0.02903 * t3 + 0.06377 * t2 - 0.03202 * ts + 0.00394) + (0.11693 * t3 - 0.21196 * t2 + 0.06052 * ts + 0.25886);\n  float yz = T * T * (0.00275 * t3 - 0.00610 * t2 + 0.00317 * ts) + T * (-0.04214 * t3 + 0.08970 * t2 - 0.04153 * ts + 0.00516) + (0.15346 * t3 - 0.26756 * t2 + 0.06669 * ts + 0.26688);\n  vec3 zen = vec3(Yz, xz, yz);\n  vec3 F = (1.0 + cA * exp(cB / ct)) * (1.0 + cC * exp(cD * gam) + cE * cos(gam) * cos(gam));\n  vec3 F0 = (1.0 + cA * exp(cB)) * (1.0 + cC * exp(cD * ts) + cE * cos(ts) * cos(ts));\n  vec3 xyY = zen * F / F0;\n  float X = xyY.y / xyY.z * xyY.x, Z = (1.0 - xyY.y - xyY.z) / xyY.z * xyY.x;\n  return vec3(3.2406 * X - 1.5372 * xyY.x - 0.4986 * Z, -0.9689 * X + 1.8758 * xyY.x + 0.0415 * Z, 0.0557 * X - 0.2040 * xyY.x + 1.0570 * Z);\n}\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  vec3 rd = normalize(vec3(uv.x * 1.4, uv.y * 1.4 + 0.5, -1.0));\n  vec3 sd = normalize(vec3(0.35, 0.55, -0.75));\n  float T = fragCoord.x < 0.5 * iResolution.x ? 2.0 : 8.0;\n  vec3 col = max(preetham(rd, sd, T), 0.0) * 0.07;\n  if (rd.y < 0.0) col = mix(col, vec3(0.04, 0.045, 0.04) * (1.0 + 0.1 * T), smoothstep(0.0, -0.03, rd.y));\n  col = 1.0 - exp(-col * 1.4);\n  if (abs(fragCoord.x - 0.5 * iResolution.x) < 1.0) col = vec3(1.0);\n  fragColor = vec4(pow(col, vec3(1.0 / 2.2)), 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": "preetham-sky",
     "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.835,
      "std": 0.2035,
      "unique_colors": 135
     },
     "image": "/specimens/preetham-sky-specimen.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "hosek-wilkie-sky",
  "rayleigh-mie-single-scattering",
  "hillaire-sky-atmosphere"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "exponential-height-fog",
   "why": "Fog color is taken from the sky model's horizon radiance so distant geometry fades into the sky."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/volumes/preetham-sky.json"
 },
 "solves": [
  "need a quick sky dome with a sun angle slider",
  "cheap daylight sky for a demo",
  "sky lighting for image-based lighting without textures",
  "turbidity-controlled haze on a procedural sky",
  "small shader that gives a plausible sky"
 ],
 "authority": "Preetham et al., 1999",
 "url": "https://texelatlas.vercel.app/t/preetham-sky/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 3.71,
  "tier": "light",
  "p50_ms": 0.122,
  "p95_ms": 0.1285,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "preetham-sky-specimen",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 3.22,
   "tier": "light",
   "p50_ms": 0.0512,
   "p95_ms": 0.0517,
   "speedup_x": 2.38,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 2.18,
   "tier": "light",
   "p50_ms": 0.0627,
   "p95_ms": 0.0627,
   "speedup_x": 1.95,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}