Baked-lighting contract

Status: ordinary mesh and terrain source terms evaluate separately, and standalone and world scenes expose draw mappings for components and BSP provenance with a provisional ambient baseline. Seamless terrain borders decompose with their neighbours' stitched source terms. The directional and clustered paths consume separated streams for eligible receivers and are the default output; the combined path remains the B1 migration boundary for receivers they do not cover (on the 16-texture WebGPU tier, a graph material with a cube in its eighth slot). A secondary view takes the baseline with its own cascades; portal levels and scripted portal views take the sun without shadows. Applies to Metal and browser WebGPU. Colour; index.

Rules

B1. A receiver has declared lighting provenance

Import/derived data must distinguish combined legacy lighting, static direct, ambient/indirect and live direct. Record which source identities each static-direct result already includes, which time/environment it depends on, and whether decomposition is supported. A label such as lightmap, cached colour or no-sun does not prove indirect-only content. The device layer must not infer this from a texture format.

In the linear path, evaluate material response against ambient/indirect plus static-direct plus live-direct terms, retaining authored self-light and specular separately. A live sun visibility factor multiplies only the live directional term, never ambient, emission or the whole framebuffer. Every ordinary point/spot source is either baked static direct or clustered live direct for a given receiver, never both. A moving source cannot remain in its static cache. AO must not add a second baked shadow term by darkening a combined map and calling that indirect occlusion.

During migration a combined receiver keeps its current path and is excluded from the new primary sun/clustered-light application. This is a temporary migration boundary, not a selectable renderer mode. The phase ends only when every supported receiver is converted/replaced and the old combined path is removed. The current RT multiplier is removed with it. Gate an unsupported region's lighting migration explicitly rather than enabling double lighting or silently changing its bake label.

Validation: add importer/provenance assertions and synthetic receiver tests for sun off/on, static source off/on and cluster inclusion. With ambient and emission alone, sun visibility must change neither. With one local source, enabling the live route must remove its static term. lighting_accounting_test exercises those CPU accounting rules using synthetic receiver terms; it does not exercise a live renderer. Existing effect_lighting_gpu_test, the scene_gpu daylight tests and terrain_lighting_gpu_test supply useful response/coverage fixtures but do not yet prove this new accounting.

B2. Replace inseparable data; do not subtract saturated bytes

Use these conversion rules on both backends:

ClassConversion before live lightingValidation
TerrainStop consuming the timed intensity grids as lighting/shadow multipliers once live directional lighting owns the surface. Keep their decoder/evidence, but remove the runtime lookup from the replacement path. Re-evaluate ordinary static-light records separately from the known positions/normals/masks; keep each source static-direct or omit it when clustered. Supply authored terrain ambient separately. Never treat the serialized or final sector RGB as a clean indirect map. Preserve holes, layer order, masks and 257-grid seam rules.environment_test, time_environment_test, time_environment_gpu_test plus a new sun-only/ordinary-only/ambient-only split fixture; stitched border and region-load sequences at dawn/noon/dusk/night.
Cached meshesRe-evaluate ordinary records without timed sun (rebuildSceneMeshInstance(..., sunlight=false) is evidence for separability, not the final linear implementation). The target evaluates known source terms before byte saturation, with ambient/mesh-colour streams separate. Remove the old timed sunlight masks from lighting consumption; render sun visibility live. Preserve cache alpha and authored vertex colour roles. If a receiver lacks usable records, replace its illumination instead of subtracting a sun estimate from final RGB.mesh_lighting_test, environment_test and mesh-lighting leaves; a non-sun floor, static/sway/LOD meshes and moving doors. Compare components before saturation, then render isolated source toggles.
BSPDo not reinterpret frame 0, a night frame, an average or a per-texel minimum of the timed DXT atlases as indirect-only. The payloads themselves are not inverted. The saved lightmap records list each traced light with its per-texel visibility, and the builder is known, so a surface's non-sun static direct light is rebuilt from those sources and the sun stays live. Replace the combined atlas contribution with the common ambient baseline plus that rebuilt static direct light and the live lights; a surface whose sources cannot all be evaluated keeps the ambient baseline alone. An offline rebuilt static-direct/indirect product may replace that baseline only with source provenance and fixtures; never in addition to its live sources. A non-sun atlas may remain only after its included ordinary sources are identified and excluded from live direct.bsp_test and scene_gpu_test preserve atlas/UV evidence during the backend port; new interior doorway and sunlit exterior BSP fixtures verify source ownership, absence of frozen sun shadows and agreement with adjoining terrain/meshes.

Byte saturation, separate quantization, compression and missing light-build information make reverse subtraction unreliable. The replacement baseline is the authored environment ambient for each class, converted under a documented linear-light preset, with no invented baked GI. Ambient is an artistic baseline, not a claim to measured irradiance. Absence of a trustworthy indirect bake means no additional indirect term until a replacement is validated. Do not bake painted diffuse texture into a new illumination product.

Validation of conversion: preserve the current source-derived byte tests as evidence, but add independent linear source-term tests. Compare labelled component images (ambient, static direct, live sun, live local, self-light) before the final image. Linear-light scaling/normalization is provisional identity on the normalized control terms, with no extra gain; it is not the sRGB decoding of a saturated combined RGB cache.

B3. Visibility, lifetime and shader portability

Preserve sun lighting flags, unlit surfaces and zone/environment selection as source eligibility, not as blanket darkness. Terrain and eligible mesh/BSP receivers use the current directional colour/direction, including moon selection, without keeping the old discrete baked sun shadow on top. Known ordinary static lights may depend on environment tracks; static-direct does not mean time-invariant. Streamed geometry and changed time, environment, transform, material opacity, wind pose or source ownership invalidate the affected cached lighting/shadow data. Do not reuse a bake from another instance, LOD, region conversion version or clock state without a declared correspondence.

All lighting terms remain distinct from colour-role textures and share the colour contract. Graph edges declare linear format/usage, explicit history and sub-view ownership; no read/write feedback is implicit. Browser baseline uses shadow maps/cluster buffers and core-filterable formats, not RT, native bindless or filterable R32F assumptions. Native RT may replace visibility behind the same direct-light rule; it cannot add another sun term. Projected pawn shadows are deleted when their real-time replacement lands, not stacked permanently.

The Slang findings are binding: lighting/material records use 16-byte vectors with host/reflection layout checks, globals bind in declaration order, and sampled masks beneath per-pixel branches use explicit gradients taken in uniform flow. The spike did not validate terrain layers, bump, filtered masks or shadow sampling; those require Metal/Chrome tests before this path is enabled.

Validation: shared material alpha/UV fixtures must also drive shadow coverage, including wind and changing opacity; add streamed blocker/source removal, device loss and independent reflection-view tests. Reuse ray_tracing_alpha_gpu_test as native coverage evidence, not as WebGPU validation.