Colour contract

Status: the linear scene is the only scene colour path on Metal and WebGPU. It is encoded to SDR at exposure 1 before temporal reconstruction, by a per-channel clamp or, in the sun-lit world, a filmic curve (below); there is no glow, bloom, HDR adaptation or grade. Index.

Rules

C1. Separate authored colour math from light transport

The target scene working space is linear RGB with sRGB/Rec.709 primaries, in RGBA16F on both backends. Lighting, light transport, reflections, temporal colour history and any future bloom compose there; scene transparency keeps encoded arithmetic as islands, so a scene without post effects reproduces the encoded image. No implicit display encoding is allowed in a graph edge. Alpha, masks, weights, heights, normals, motion and signed bump data never receive an RGB transfer function.

Keep the material's authored encoded-colour operations as a bounded material-local calculation, not as a second scene renderer. Sample/filter its colour inputs as normalized encoded values using non-sRGB views; retain complement, signed operations, MODULATE2X/4X and their documented clamp points. Decode the resulting colour roles once with the standard sRGB transfer function before lighting. This is an explicit interpretation of unprofiled game art, not a claim that the files contain sRGB metadata. It preserves authored compositing and sampling better than silently changing every stage to linear arithmetic. A direct bitmap is the same calculation with one sample. No decode/re-encode is inserted between its stages.

The compiler must expose base response, self-illumination, authored specular/environment contribution and opacity separately, rather than decoding an already-lit framebuffer and calling it albedo. Self-light masks retain their authored alpha routing; they mix lit response and unlit colour in the encoded space, and the mix is decoded. Root modifiers after lighting must remain in order, with explicit encode/operate/decode boundaries where their authored operation requires encoded RGB. Do not move a clamp or modifier across lighting by algebraic guesswork. Unsupported separations block that material's lighting migration and need a fixture, not a flattened texture.

Lighting's old fixed-function ×2 is not an emissive scale or extra sun intensity. Remove it with the combined baked-lighting path, not from authored material-only ×2 operations. Legacy light bytes are tagged lighting data, not automatically sRGB colour textures; their conversion belongs to the baked-lighting contract.

Validation: CPU material_graph_test/material_bump_test and Metal material_stage_gpu_test/material_graph_gpu_test remain the encoded-operation oracle. Add linear-boundary probes for direct colour, masked self-light, post-light root modifiers and saturated ×2 followed by subtraction. Test RGB transfer round-trips while alpha remains unchanged. Run the same Slang inputs on Metal and Chrome.

Encoded operations that cannot be moved across the linear boundary

These are operation families, not a complete inventory of individual material assets. Their encoded result cannot be recovered by independently decoding their inputs and repeating the operation in linear space:

  • Combiner graphs and packed terrain layers: stage operations include MODULATE2X/4X, addition and subtraction with saturation after each stage; packed terrain weights instead sum before their clamp. Decode the completed material-local colour, not each input. The CPU evaluator and shaders/material_combiner.slang retain these distinct clamp points.
  • Lighting and lightmap MODULATE2X: mesh and terrain combine encoded response and lighting with saturation; the BSP atlas also stores combined lighting. These are not separable from their final saturated result. Re-evaluate supported source terms or replace unsupported illumination as specified by B1–B2; never decode the combined framebuffer and call it albedo. Terrain and static-mesh lighting use the ×2 path.
  • Post-light detail, specular and root colour modifiers: detail can modulate the already-lit value, specular can add or MODULATE2X with a later clamp, and root modifiers follow those operations. The supplied dungeon light shader is an example with masked specular after diffuse lighting. Their ordering cannot be reconstructed from the final colour. Keep any required encoded operation at its actual position as an explicit encode/operate/decode island, with independent pass state where applicable.
  • Framebuffer blends: the additive, alpha and modulation families combine a source with the existing encoded destination. The blend family and order remain content (M4), but they execute in the linear scene: the source converts at its output and the destination is linear. Multiplicative families keep the encoded product up to the sRGB curve's departure from a power law; additive and alpha families change appearance, re-baselined and user-accepted rather than matched to the encoded image.

Masked self-illumination and opacity retain separate colour and data roles even though the encoded path combines them after lighting; an encoded final pixel alone cannot recover those roles. The list above identifies the required boundaries; coverage of all materials and artistic acceptance remain open.

C2. Exposure and emission have one owner

Use relative scene-linear units; ordinary unlit white has value 1 before exposure. Authored self-illumination remains unlit, not automatically a physical light source. Its provisional gain is identity; any gain above that, and any light emitted into the scene, is a named rendering preset, not inferred from a bright texel, material name or screenshot. Preserve authored masks, tint, lifetime and blend family. Existing RT effect-light intensities are enhancement profiles, not calibration data.

One graph node owns scene exposure. Initially use fixed identity exposure for deterministic validation; automatic adaptation is disabled until its metering region, bounds, response and cut/reset policy are accepted on the fixtures below. Exposure does not include HUD/UI. MetalFX must consume the same exposure convention, not independently adapt the displayed scene a second time. History either stores unexposed linear colour or carries its exposure scale explicitly; a scale change cannot silently reuse incompatible history.

No automatic adaptation runs. MetalFX's internal automatic exposure (see above) remains; it weights reconstruction rather than setting the displayed exposure.

Do not clamp scene radiance to 1 before a future tone mapping. Preserve hue ratios through the highlight shoulder and use an explicit gamut-compression stage for out-of-gamut display values, rather than independent-channel hard clipping or a blanket desaturation of the painted palette. The tone curve, gamut-compression parameters, exposure/adaptation and bloom strengths remain preset decisions. A host ships the identity reference (exposure 1, per-channel clamp, no gamut stage or bloom) outside the sun-lit world, and the coastal filmic curve above in it; its inset/outset compresses highlights toward white per channel rather than through a separate gamut stage. Both are presets.

Validation fixtures: a locked-clock standalone scene and a town level at dawn, noon, dusk and night, dark interior to bright exterior, distant scenery, reflective equipment and overlapping particle effects. Record linear highlight/luminance ranges and clipping, compare stills and adaptation sequences on both backends, then obtain user artistic acceptance of any further named SDR preset. Do not fit reference screenshots or infer nits from 8-bit files.

C3. UI white and output encoding are explicit

Keep bitmap UI/glyphs at output resolution after reconstruction, integer-snapped and unaffected by scene exposure or dynamic resolution. For SDR, encode the tone-mapped scene first, then composite UI with its existing encoded-space colour/modulation/blending; this deliberate display-layer exception preserves glyph and panel edges over the scene. UI white maps to display white (normalized 1), not a guessed luminance in nits. World-view widgets tone-map/encode their own scene before entering this layer. A future HDR compositor must explicitly convert UI to its approved reference-white level and validate its translucent edges; it cannot reuse encoded UI values as linear light.

Browser baseline: request the browser's preferred canvas format (bgra8unorm or rgba8unorm, not a hard-coded BGRA assumption), opaque alpha, srgb canvas colour space and standard SDR tone mapping. The presentation adapter must explicitly establish or verify these settings through the pinned C/JS bridge. Store final sRGB-encoded values into the non-sRGB canvas exactly once; if an sRGB attachment view is used later, remove the manual encoding. A format name alone does not select a colour space. Display-P3 and extended/HDR browser canvases are not baseline requirements.

Metal baseline presents the same SDR sRGB result with matching layer colour-space metadata. Future native HDR uses a separate output transform from the same linear scene, never SDR tone-map followed by an HDR boost. UI reference white in nits, HDR peak/roll-off and OS EDR mapping await a supported-display measurement and user approval; until then HDR display output is not enabled.

Retain the gamma/brightness/contrast LUT as a user display adjustment on the final encoded SDR scene/UI, once only; it is not sRGB decoding, scene exposure or a mandatory extra gamma. Keep its neutral identity reference and pre-adjustment screenshot semantics. Do not apply this SDR LUT directly to linear HDR values; HDR needs an explicitly approved mapping of that control.

Validation: port video_output_gpu_test, UI/login/glyph goldens and render_scale_gpu_test; add transfer-ramp, neutral-LUT, transparent-edge and scene/UI-white probes including RGBA/BGRA channel order. Compare offscreen readback with the browser-presented canvas to catch double encoding, and log format/colour-space/tone-mapping configuration. Physical display checks remain separate from readback.

C4. Migration and portable shader constraints

The linear scene replaced the encoded scene path. It is encoded to SDR at exposure 1; underwater and temporal reconstruction remain on encoded SDR. Baked-lighting replacement, linear temporal history and a single exposure convention remain open before C4 is complete. Keep equation tests as historical semantic evidence, and re-baseline changed scene/post captures deliberately. The gamma adjustment is the separate C3 operation.

The Slang spike binds this port: shared parameter records are 16-byte vectors/arrays with host/reflection layout checks; bindings follow declaration order. Samples below per-pixel decisions use gradients computed in uniform flow and SampleGrad; known single-mip post inputs can use explicit level zero. Filtered sampling and presentation are not established by the spike. Do not require shader-f16 or float32-filterable: use core-filterable RGBA16F for colour and explicit loads/reductions for R32F luminance. Post fusion is conditional on whole-frame timing (performance experiments); it is not part of the colour equation.