# TexelAtlas WebGPU / WGSL 3D Look-Dev Playbook

> Compact, zero-truncation agent guide for building game-quality 3D scenes in **WebGPU / WGSL** (Native WebGPU + WGSL render/compute pipelines; verified against `W3C CR 2025 + WGSL`).
> 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 WebGPU / WGSL Pipeline Architecture

- 1. Configure `canvas.getContext("webgpu")` with an `rgba16float` HDR offscreen target + `depth32float` **Reverse-Z** (`depthCompare: "greater-equal"`, clear `0.0`).
- 2. Startup compute pass: generate prefiltered IBL cubemap (from HDRI or procedural sky LUT) once at load or on environment change.
- 3. Geometry pass: CSM / tight shadow maps → main PBR pass (`openpbr-surface` / GGX + `normal-distribution-filtering` + `hex-tiling` / `triplanar-mapping` + `alphaToCoverageEnabled` for cutouts).
- 4. Post chain: compute `GTAO` → dual-filter downsample/upsample bloom → `AgX` / `Neutral` tonemap + `SMAA` into swapchain.

## 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**: `hillaire-sky-atmosphere` + `rayleigh-mie-single-scattering` · **shadows**: `cascaded-shadow-maps` + `percentage-closer-soft-shadows` · **ao/gi**: `n8ao` + `ground-truth-ambient-occlusion` · **materials/micro**: `clearcoat-layer` + `parallax-occlusion-mapping` · **water/volumes**: `exponential-height-fog` + `planar-reflections-oblique-clipping` · **post/aa**: `agx-tonemapping` + `dual-filter-bloom`

### 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` + `ltc-area-lights` · **shadows**: `percentage-closer-soft-shadows` + `contact-shadows` · **ao/gi**: `ground-truth-ambient-occlusion` + `multi-bounce-ambient-occlusion` · **materials/micro**: `disney-principled-brdf` + `clearcoat-layer` · **water/volumes**: `screen-space-reflections` · **post/aa**: `khronos-pbr-neutral` + `agx-tonemapping`

### 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**: `environment-mapping-cubemaps` (builtin) + `split-sum-ibl` · **shadows**: `percentage-closer-soft-shadows` + `contact-shadows` · **ao/gi**: `ground-truth-ambient-occlusion` + `n8ao` · **materials/micro**: `anisotropic-ggx` + `clearcoat-layer` · **water/volumes**: `screen-space-reflections` + `froxel-volumetric-fog` · **post/aa**: `agx-tonemapping` + `dual-filter-bloom`

### 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` · **ao/gi**: `n8ao` + `hbao` · **materials/micro**: `toon-shading` + `toksvig-mipmapping` · **water/volumes**: `exponential-height-fog` · **post/aa**: `kuwahara-filter` + `xdog-stylization`

### 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**: `hillaire-sky-atmosphere` + `hosek-wilkie-sky` · **shadows**: `percentage-closer-filtering` (builtin) + `cascaded-shadow-maps` · **ao/gi**: `ground-truth-ambient-occlusion` + `n8ao` · **materials/micro**: `fresnel-schlick-approximation` + `weathering-simulation` · **water/volumes**: `planar-reflections-oblique-clipping` + `fft-ocean` · **post/aa**: `agx-tonemapping` + `dual-filter-bloom`

### 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**: `hillaire-sky-atmosphere` + `split-sum-ibl` · **shadows**: `cascaded-shadow-maps` + `contact-shadows` · **ao/gi**: `ground-truth-ambient-occlusion` + `multi-bounce-ambient-occlusion` · **materials/micro**: `triplanar-mapping` + `hex-tiling` · **water/volumes**: `exponential-height-fog` + `nubis-volumetric-clouds` · **post/aa**: `agx-tonemapping` + `smaa`

## 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. WebGPU / WGSL Pitfalls & Pass Ordering

- Use `depth32float` Reverse-Z (`near = 1.0, far = 0.0`) from day one to eliminate Z-fighting across wide near-to-far depth ranges (e.g. 0.1m–1000m).
- Check `adapter.features.has("timestamp-query")` before enabling GPU pass profiling; fall back cleanly to `queue.onSubmittedWorkDone()`.

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

### Sky, IBL & GI
- **Environment mapping, cubemaps and skyboxes** (`environment-mapping-cubemaps`) [builtin · 0.1615ms T4] — `createTexture(6 layers) + createView({dimension:'cube'}); WGSL texture_cube<f32>`

### Shadows & Ambient Occlusion
- **Percentage-Closer Filtering** (`percentage-closer-filtering`) [builtin · 0.6316ms T4] — `device.createSampler({compare:"less"}) + WGSL textureSampleCompare(texture_depth_2d, sampler_co`
- **Shadow map depth bias (constant, slope-scale, normal offset)** (`shadow-map-bias-slope-scale-normal-offset`) [builtin · 0.0325ms T4] — `GPUDepthStencilState: depthBias, depthBiasSlopeScale, depthBiasClamp`

### Materials, BRDF & Micro-Detail
- **Mipmapping and anisotropic texture filtering** (`mipmapping-anisotropic-filtering`) [builtin · 0.0868ms T4] — `GPUSamplerDescriptor: mipmapFilter: 'linear', maxAnisotropy: 16`

### Post-Processing, Tonemapping & AA
- **Linear-space rendering and gamma correction** (`linear-color-workflow`) [builtin · 0.0291ms T4] — `Texture formats rgba8unorm-srgb / bgra8unorm-srgb (hardware sRGB decode/encode)`
- **HDR display output (PQ / BT.2100)** (`hdr-display-output-pq`) [builtin · 0.0602ms T4] — `context.configure({ format: "rgba16float", toneMapping: { mode: "extended" } })`

### Stylized, Foliage & Performance
- **Reverse-Z and floating-point depth buffers** (`reverse-z-depth-buffer`) [builtin · 0.0943ms T4] — `format: 'depth32float' with depthStencil.depthCompare: 'greater' and depth clear value 0`
- **GPU-driven rendering** (`gpu-driven-rendering`) [builtin · 0.1231ms T4] — `renderPass.drawIndexedIndirect(buffer, offset); computePass.dispatchWorkgroupsIndirect(buffer, `
- **GPU hardware occlusion queries** (`hardware-occlusion-queries`) [builtin · 0.1309ms T4] — `device.createQuerySet({type:'occlusion',count}); pass.beginOcclusionQuery(i)`
- **Block texture compression (BC7 / ASTC)** (`block-texture-compression`) [builtin · 0.5623ms T4] — `requiredFeatures: ['texture-compression-bc'] or ['texture-compression-astc']; formats bc7-rgba-`
- **Deferred shading (G-buffer)** (`deferred-shading`) [builtin · 2.1913ms T4] — `GPURenderPassDescriptor.colorAttachments (up to maxColorAttachments=8 MRT targets in one pass)`

## 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.
