# TexelAtlas Three.js 3D Look-Dev Playbook

> Compact, zero-truncation agent guide for building game-quality 3D scenes in **Three.js** (r170–r187 (WebGL2 & WebGPU/TSL); verified against `r187`).
> Read this BEFORE writing scene code. Every technique `slug` resolves to `https://texelatlas.vercel.app/t/<slug>.md` with verified equations, parameters, and failure modes.

## 1. Recommended Three.js Pipeline Architecture

- 1. `WebGLRenderer({ antialias: true, powerPreference: "high-performance" })` (or `WebGPURenderer` for TSL/compute) with `toneMapping = THREE.AgXToneMapping` (or `NeutralToneMapping` for color-exact products), `outputColorSpace = THREE.SRGBColorSpace`, and `shadowMap.type = THREE.PCFShadowMap`.
- 2. Build coherent IBL once via `PMREMGenerator.fromScene(envScene, 0.04)` (from an HDRI, `RoomEnvironment`, or a custom lighting-dome + emissive-card scene) → assign to `scene.environment` so every PBR material shares consistent indirect light and reflections.
- 3. Match shadows to scene scale: tight orthographic shadow bounds (`2048×2048`, `bias = -0.0004`, `normalBias = 0.025`) or `PCSS` for small scenes/interiors (`< 20m`), or `CSM` (`three/addons/csm/CSM.js`) for large worlds (`> 20m`). Pair with `RectAreaLight` (`RectAreaLightUniformsLib.init()`) on glowing windows, signage, or softboxes.
- 4. Author differentiated materials: `MeshPhysicalMaterial` (`clearcoat`, `sheen`, `anisotropy`, `iridescence`, `transmission`, `envMapIntensity`) backed by **paired procedural `<canvas>` PBR maps** (`map` + `roughnessMap` + Sobel `normalMap` + `clearcoatRoughnessMap`, `anisotropy = max`) and `alphaToCoverage: true` for alpha cutouts. Prefer paired PBR maps, standalone `ShaderMaterial`/`Reflector`, or WebGPU `three/tsl` over brittle `onBeforeCompile` chunk patching.
- 5. Optional scene-specific passes (before post): planar `Reflector` (or oblique near-plane clip) for flat mirrors/water with physical Schlick Fresnel (`F0 = 0.02`), `SSRPass` for wet/glossy floors, and `FogExp2` / soft radial atmospheric particles (`depthWrite: false`).
- 6. Desktop `EffectComposer`: allocate `WebGLRenderTarget(w, h, { type: THREE.HalfFloatType, samples: 4 })` → `RenderPass` → **transparent-safe `GTAOPass`** (or `n8ao`) → selective `UnrealBloomPass(res, 0.30, 0.45, 0.94)` → `OutputPass` (applies AgX + sRGB once).

```js
// Drop-in Three.js r187 HDR + 4x MSAA + transparent-safe GTAO + selective Bloom + AgX
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.AgXToneMapping;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFShadowMap; // r187 removed PCFSoftShadowMap; use shadow.radius
const rt = new THREE.WebGLRenderTarget(w, h, { type: THREE.HalfFloatType, samples: 4 });
const composer = new EffectComposer(renderer, rt);
composer.addPass(new RenderPass(scene, camera));
const gtao = new GTAOPass(scene, camera, w, h);
gtao.updateGtaoMaterial({ radius: 0.45, samples: 12 });
// CRITICAL: hide transparent/particle/glass/Reflector meshes during GTAOPass or they turn solid black!
const _gtaoRender = gtao.render.bind(gtao);
gtao.render = (r, wb, rb, dt, ma) => {
  const hidden = [];
  scene.traverse((o) => { if (o.visible && (o.userData.skipGTAO || o.material?.transparent)) { o.visible = false; hidden.push(o); } });
  try { _gtaoRender(r, wb, rb, dt, ma); } finally { hidden.forEach((o) => { o.visible = true; }); }
};
composer.addPass(gtao);
composer.addPass(new UnrealBloomPass(new THREE.Vector2(w, h), 0.32, 0.45, 0.94)); // threshold >= 0.92!
composer.addPass(new OutputPass()); // single AgX + sRGB pass at the very end
```

## 2. Scene Archetype Recipes (Pick 1 Technique Per Stage)

### Outdoor Architecture (`outdoor-architecture`)
Daylight or dusk exteriors, streets, plazas, buildings, and walkable outdoor spaces with crisp near-to-far shadows and atmospheric depth.
- **sky/ibl**: `split-sum-ibl` (builtin) + `hillaire-sky-atmosphere` · **shadows**: `cascaded-shadow-maps` (official) + `percentage-closer-soft-shadows` (official) · **ao/gi**: `ground-truth-ambient-occlusion` (official) + `n8ao` (plugin) · **materials/micro**: `clearcoat-layer` (builtin) + `parallax-occlusion-mapping` (official) · **water/volumes**: `exponential-height-fog` (builtin) + `planar-reflections-oblique-clipping` (official) · **post/aa**: `agx-tonemapping` (builtin) + `dual-filter-bloom` (official)

### Interiors, Characters & Product Look-Dev (`interior-product`)
Rooms, galleries, character portraits, and automotive/product turntables with accurate area lights, local reflections, and layered PBR materials.
- **sky/ibl**: `split-sum-ibl` (builtin) + `ltc-area-lights` (builtin) · **shadows**: `percentage-closer-soft-shadows` (official) + `contact-shadows` (official) · **ao/gi**: `ground-truth-ambient-occlusion` (official) + `lightmap-baking` (official) · **materials/micro**: `clearcoat-layer` (builtin) + `anisotropic-ggx` (builtin) · **water/volumes**: `screen-space-reflections` (official) · **post/aa**: `khronos-pbr-neutral` (builtin) + `agx-tonemapping` (builtin)

### Sci-Fi, Cyberpunk, Space & Night Scenes (`scifi-night-neon`)
Dark moody interiors, rain-slicked neon streets, cockpits, and space environments with area lights, wet reflections, volumetric beams, and controlled HDR bloom.
- **sky/ibl**: `split-sum-ibl` (builtin) + `ltc-area-lights` (builtin) · **shadows**: `percentage-closer-soft-shadows` (official) + `contact-shadows` (official) · **ao/gi**: `ground-truth-ambient-occlusion` (official) + `screen-space-gi` (official) · **materials/micro**: `anisotropic-ggx` (builtin) + `clearcoat-layer` (builtin) · **water/volumes**: `exponential-height-fog` (builtin) + `screen-space-reflections` (official) · **post/aa**: `agx-tonemapping` (builtin) + `dual-filter-bloom` (official)

### Stylized, Painterly & NPR Worlds (`stylized-npr`)
Cohesive cel-shaded, anime, watercolor, ink-contour, or dithered 3D worlds with clean silhouette discipline and anti-aliased shading bands.
- **sky/ibl**: `environment-mapping-cubemaps` (builtin) + `hosek-wilkie-sky` · **shadows**: `percentage-closer-filtering` (builtin) + `cascaded-shadow-maps` (official) · **ao/gi**: `n8ao` (plugin) + `hbao` · **materials/micro**: `toon-shading` (builtin) + `inverted-hull-outline` (official) · **water/volumes**: `exponential-height-fog` (builtin) · **post/aa**: `agx-tonemapping` (builtin) + `ordered-dithering-bayer` (official)

### Oceans, Lakes & Coastal Environments (`water-coastal`)
Open seas, rivers, pools, and shorelines combining physical Fresnel, oblique planar reflections or FFT/Gerstner waves, and caustics.
- **sky/ibl**: `split-sum-ibl` (builtin) + `hillaire-sky-atmosphere` · **shadows**: `percentage-closer-filtering` (builtin) + `cascaded-shadow-maps` (official) · **ao/gi**: `ground-truth-ambient-occlusion` (official) + `n8ao` (plugin) · **materials/micro**: `fresnel-schlick-approximation` (builtin) + `hex-tiling` (official) · **water/volumes**: `exponential-height-fog` (builtin) + `planar-reflections-oblique-clipping` (official) · **post/aa**: `agx-tonemapping` (builtin) + `dual-filter-bloom` (official)

### Large Terrain, Forests & Open Landscapes (`terrain-foliage`)
Wide natural vistas with anti-aliased grass and foliage, distance LOD, non-repeating rock/ground textures, clouds, and aerial perspective.
- **sky/ibl**: `split-sum-ibl` (builtin) + `hillaire-sky-atmosphere` · **shadows**: `cascaded-shadow-maps` (official) + `contact-shadows` (official) · **ao/gi**: `ground-truth-ambient-occlusion` (official) + `multi-bounce-ambient-occlusion` · **materials/micro**: `triplanar-mapping` (builtin) + `hashed-alpha-testing` (builtin) · **water/volumes**: `exponential-height-fog` (builtin) + `nubis-volumetric-clouds` · **post/aa**: `agx-tonemapping` (builtin) + `smaa` (official)

## 3. Prototype Shortcuts to Avoid (Upgrade Table)

| Common Agent Shortcut | Visual Symptom | TexelAtlas Upgrade |
|---|---|---|
| Single DirectionalLight shadow frustum stretched across a large (>20m) scene | Blurry, blocky shadows up close and objects looking detached from the ground | `cascaded-shadow-maps`, `percentage-closer-soft-shadows` — Use Cascaded Shadow Maps (`CSM` in Three.js or built-in CSM in Godot/Unity/Unreal) for large worlds, or tightly fitted `PCSS` + `contact-shadows` for compact scenes, with tuned `normalBias`. |
| Uniform roughness/metalness PBR materials with default flat normal maps | Flat, plastic-looking surfaces where painted metal, glass, cloth, skin, wood, and stone read identically | `clearcoat-layer`, `parallax-occlusion-mapping`, `toksvig-mipmapping` — Separate materials physically (`MeshPhysicalMaterial` / OpenPBR `clearcoat`, `sheen`, `anisotropy`, `iridescence`, or subsurface scattering), author varied roughness/AO maps, use POM/detail normals on close-up surfaces, and add `toksvig-mipmapping` to curb specular shimmer. |
| Skipping ambient occlusion or applying heavy monochrome SSAO | Props, characters, and geometry look pasted onto floors, or bright surfaces turn muddy gray in crevices | `n8ao`, `ground-truth-ambient-occlusion`, `multi-bounce-ambient-occlusion` — Enable `N8AO` or `GTAO` (half-res depth-aware denoise) and pair with multi-bounce albedo tinting so bright crevices stay clean and natural. |
| Repeating UV textures on large floors, walls, roads, or terrain | Obvious grid/checkerboard repetition across wide surfaces | `hex-tiling`, `triplanar-mapping`, `weathering-simulation` — Break periodicity with `hex-tiling` or `triplanar-mapping` (for steep slopes/cliffs) and layer low-frequency world-space roughness/color variation. |
| Hard alphaTest cutouts or unsorted alpha-blended cards (foliage, hair, fences, decals) | Sparkling distant edges, popping silhouettes, or broken transparency sorting | `hashed-alpha-testing`, `octahedral-impostors` — Use `alphaToCoverage` + hashed alpha testing (`hashed-alpha-testing`) with MSAA for order-independent anti-aliased cutouts. |
| Flat ambient fill + uncalibrated exposure / linear sRGB clipping (no IBL) | Washed-out shadows, flat ungrounded reflections, and neon/sun highlights clipping to harsh yellow or white | `split-sum-ibl`, `agx-tonemapping`, `exponential-height-fog` — Bake your environment (HDRI, studio rig, or procedural sky) into a prefiltered IBL cubemap (`PMREM`), add subtle atmospheric depth where appropriate, and finish with `AgX` or `Khronos PBR Neutral` + selective HDR bloom (`threshold >= 0.9`). |
| Hand-rolled `sin(x)*cos(y)` surface ripples or mirror blends without Fresnel/oblique clip | Artificial repeating stripes on liquids or broken reflection clipping on glossy/mirror planes | `planar-reflections-oblique-clipping`, `screen-space-reflections`, `fresnel-schlick-approximation` — Use physical Schlick Fresnel (`F0`), Lengyel oblique near-plane clipping for flat mirrors/water, `screen-space-reflections` for wet streets/glossy floors, and multi-directional or FFT/Gerstner waves for open water. |

## 4. Three.js Pitfalls & Pass Ordering

- **GTAOPass black-box trap:** `GTAOPass` renders depth/normals with an override material that ignores `transparent: true`. Always hide steam/fog quads, particles, glass, and `Reflector` planes during `gtao.render(...)` (mark `userData.skipGTAO = true` as shown above), or use `n8ao`.
- **Avoid brittle `onBeforeCompile` on `MeshPhysicalMaterial` in r187:** Internal GLSL chunks (`vNormal`, `perturbNormal2Arb`) changed signatures across Three.js releases and easily fail compilation. Use paired procedural `<canvas>` PBR maps (with Sobel height-to-normal), standalone `ShaderMaterial`/`Reflector`, or WebGPU `three/tsl` instead.
- **Three.js r187 API removals:** `THREE.PCFSoftShadowMap` was **removed** (use `THREE.PCFShadowMap` + `light.shadow.radius`), and `THREE.Clock` is **deprecated** (use `THREE.Timer`).
- Never apply tone mapping inside a custom `ShaderMaterial` when using `EffectComposer` + `OutputPass` — output linear HDR radiance and let `OutputPass` tone-map once.
- Default `EffectComposer` uses `UnsignedByteType` (clips HDR bloom and causes banding). Always allocate a `HalfFloatType` render target with `samples: 4` (WebGL2 MSAA).
- Shadow texel density drops quadratically with shadow-camera width: keep frustums tight to active hero bounds, or switch to `CSM` for scenes wider than ~20m.

## 5. Top Verified Three.js Built-In & Official Switches (110 total; fetch `https://texelatlas.vercel.app/t/<slug>.md`)

### Sky, IBL & GI
- **Split-Sum Image-Based Lighting** (`split-sum-ibl`) [builtin · 0.0613ms T4] — `scene.environment = pmremGenerator.fromEquirectangular(hdr).texture`
- **Environment mapping, cubemaps and skyboxes** (`environment-mapping-cubemaps`) [builtin · 0.1615ms T4] — `scene.background = scene.environment = cubeTexture (CubeTextureLoader)`
- **Linearly Transformed Cosines for Area Lights** (`ltc-area-lights`) [builtin · 0.2775ms T4] — `new THREE.RectAreaLight(color, intensity, w, h); RectAreaLightUniformsLib.init() on WebGLRender`
- **Planar reflections with oblique near-plane clipping** (`planar-reflections-oblique-clipping`) [official · 0.6098ms T4] — `import { Reflector } from 'three/addons/objects/Reflector.js'`
- **Lightmap Baking** (`lightmap-baking`) [official · 0.8339ms T4] — `import { LightMapper } from 'three/addons/lighting/LightMapper.js'`
- **Screen-Space Global Illumination** (`screen-space-gi`) [official · 8.0356ms T4] — `import { ssgi } from 'three/addons/tsl/display/SSGINode.js'`

### Shadows & Ambient Occlusion
- **Hashed alpha testing / alpha-to-coverage for foliage** (`hashed-alpha-testing`) [builtin · 0.0744ms T4] — `material.alphaHash = true; material.alphaToCoverage = true`
- **Percentage-Closer Filtering** (`percentage-closer-filtering`) [builtin · 0.6316ms T4] — `renderer.shadowMap.type = THREE.PCFShadowMap`
- **Screen-Space Contact Shadows** (`contact-shadows`) [official · 0.353ms T4] — `import { sss } from 'three/addons/tsl/display/SSSNode.js'`
- **Ground-Truth Ambient Occlusion** (`ground-truth-ambient-occlusion`) [official · 1.1653ms T4] — `import { ao } from 'three/addons/tsl/display/GTAONode.js' (WebGL: GTAOPass)`
- **Percentage-Closer Soft Shadows** (`percentage-closer-soft-shadows`) [official · 1.6496ms T4] — `examples/webgl_shadowmap_pcss.html patches ShaderChunk.shadowmap_pars_fragment with PCSS`
- **Cascaded Shadow Maps** (`cascaded-shadow-maps`) [official · 2.1515ms T4] — `import { CSM } from 'three/addons/csm/CSM.js' (WebGPU: CSMShadowNode)`

### Materials, BRDF & Micro-Detail
- **Triplanar mapping** (`triplanar-mapping`) [builtin · 0.0423ms T4] — `import { triplanarTexture } from 'three/tsl'`
- **Schlick Fresnel approximation** (`fresnel-schlick-approximation`) [builtin · 0.0514ms T4] — `Used internally by MeshStandardMaterial/MeshPhysicalMaterial (F_Schlick)`
- **Anisotropic GGX** (`anisotropic-ggx`) [builtin · 0.0614ms T4] — `material.anisotropy = 1 (MeshPhysicalMaterial)`
- **Charlie sheen (Estevez-Kulla)** (`charlie-sheen`) [builtin · 0.0669ms T4] — `material.sheen = 1; material.sheenRoughness (MeshPhysicalMaterial)`
- **Clearcoat layer** (`clearcoat-layer`) [builtin · 0.0727ms T4] — `material.clearcoat = 1 (MeshPhysicalMaterial)`
- **Thin-film iridescence** (`thin-film-iridescence`) [builtin · 0.0814ms T4] — `material.iridescence = 1 (MeshPhysicalMaterial)`

### Water, Fog & Volumes
- **Exponential Height Fog** (`exponential-height-fog`) [builtin · 0.0776ms T4] — `import { exponentialHeightFogFactor } from 'three/tsl'; scene.fogNode = ...`
- **Real-time Water Caustics** (`water-caustics-realtime`) [official · 0.3065ms T4] — `examples/webgpu_caustics.html`
- **Screen-space Volumetric Light Scattering (God Rays)** (`volumetric-light-scattering-god-rays`) [official · 1.4269ms T4] — `import { godrays } from 'three/addons/tsl/display/GodraysNode.js'`
- **Flow-map water animation** (`flow-map-water`) [official · 0.2795ms T4] — `import { Water } from 'three/addons/objects/Water2.js' (flowMap option)`
- **Ray-marched Participating Media** (`volume-ray-marching`) [official · 12.8474ms T4] — `import { VolumeShader } from 'three/addons/shaders/VolumeShader.js'; TSL: RaymarchingBox from t`
- **Precomputed Atmospheric Scattering** (`precomputed-atmospheric-scattering`) [plugin · 0.6278ms T4] — `npm i @takram/three-atmosphere`

### Post-Processing, Tonemapping & AA
- **AgX** (`agx-tonemapping`) [builtin · 0.0387ms T4] — `renderer.toneMapping = THREE.AgXToneMapping`
- **Khronos PBR Neutral tone mapper** (`khronos-pbr-neutral`) [builtin · 0.0423ms T4] — `renderer.toneMapping = THREE.NeutralToneMapping`
- **Temporal Anti-Aliasing** (`temporal-anti-aliasing`) [official · 0.1956ms T4] — `import { traa } from 'three/addons/tsl/display/TRAANode.js' (WebGL: TAARenderPass)`
- **SMAA** (`smaa`) [official · 0.2174ms T4] — `import { smaa } from 'three/addons/tsl/display/SMAANode.js' (WebGL: SMAAPass)`
- **Screen-space reflections** (`screen-space-reflections`) [official · 0.5894ms T4] — `import { ssr } from 'three/addons/tsl/display/SSRNode.js' (WebGL: SSRPass)`
- **Dual-filter and progressive-downsample bloom** (`dual-filter-bloom`) [official · 3.5692ms T4] — `import { bloom } from 'three/addons/tsl/display/BloomNode.js' (WebGL: UnrealBloomPass)`

### Stylized, Foliage & Performance
- **Reverse-Z and floating-point depth buffers** (`reverse-z-depth-buffer`) [builtin · 0.0943ms T4] — `new THREE.WebGLRenderer({ reversedDepthBuffer: true })`
- **Toon / cel shading with lighting ramps** (`toon-shading`) [builtin · 0.2921ms T4] — `new THREE.MeshToonMaterial({ gradientMap })`
- **Ordered dithering with Bayer matrices** (`ordered-dithering-bayer`) [official · 0.0433ms T4] — `import { bayerDither } from 'three/addons/tsl/math/Bayer.js'`
- **Inverted-hull outlines** (`inverted-hull-outline`) [official · 0.0752ms T4] — `import { OutlineEffect } from 'three/addons/effects/OutlineEffect.js'`
- **MatCap (lit sphere) shading** (`matcap-shading`) [builtin · 0.0427ms T4] — `new THREE.MeshMatcapMaterial({ matcap })`
- **Posterization** (`posterization`) [builtin · 0.052ms T4] — `import { posterize } from 'three/tsl'`

## 6. Quantitative Look-Dev Gates & Mandatory Phase-2 Polish Pass

- **Roughness Contrast Gate:** Span `<= 0.06` (wet puddles, clearcoat, glass, polished metal) to `>= 0.88` (matte asphalt, plaster, fabric, dry bark) using paired PBR maps — never let a scene collapse into uniform `0.4–0.6` plastic.
- **Lighting & HDR Discipline:** Establish a clear warm-vs-cool focal hierarchy backed by prefiltered IBL + area lights; drive emissives at HDR `1.5–4.5` with bloom `threshold >= 0.92` so glow kisses sources without milky wash.
- **Silhouette & Framing Rule:** Never leave bare box primitives or unframed glowing rectangles; frame walls, eaves, signs, and openings with trim, bevels, conduits/cables, and grounded street/floor props, and verify curved UV orientation (`LatheGeometry` labels).
- **Mandatory Phase-2 Polish Pass:** After building v1, capture screenshots across Hero, Close-Up, and Grazing views, score all 8 checkpoints at https://texelatlas.vercel.app/guides/scene-audit.md (matching defects against https://texelatlas.vercel.app/api/v1/symptoms.json or MCP `texel_diagnose`), and execute a dedicated upgrade pass fixing your **3 weakest visual areas** before finishing.
