@ignifx/core 0.14.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/decoders/draco3dgltf.LICENSE.md +201 -0
- package/decoders/draco_decoder.js +116 -0
- package/decoders/draco_decoder_gltf.wasm +0 -0
- package/decoders/vendored.json +22 -0
- package/dist/agx-tone-mapping-Cgt844j6.js +53 -0
- package/dist/agx-tone-mapping-Cgt844j6.js.map +1 -0
- package/dist/auto-exposure-uzPn0beO.js +246 -0
- package/dist/auto-exposure-uzPn0beO.js.map +1 -0
- package/dist/bloom-hdr-CLtQj-oY.js +315 -0
- package/dist/bloom-hdr-CLtQj-oY.js.map +1 -0
- package/dist/contact-shadows-T523EXaP.js +84 -0
- package/dist/contact-shadows-T523EXaP.js.map +1 -0
- package/dist/{decoders-CHJ7vduE.js → decoders-BUQrlS8U.js} +3 -2
- package/dist/decoders-BUQrlS8U.js.map +1 -0
- package/dist/{environment-Cq2BmA96.js → environment-DPi0_0SP.js} +18 -4
- package/dist/environment-DPi0_0SP.js.map +1 -0
- package/dist/gtao-_nr0b6-E.js +630 -0
- package/dist/gtao-_nr0b6-E.js.map +1 -0
- package/dist/hdr-output-BrUvpAsE.js +525 -0
- package/dist/hdr-output-BrUvpAsE.js.map +1 -0
- package/dist/index.d.ts +509 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1522 -512
- package/dist/index.js.map +1 -1
- package/dist/{instanced-mesh-instance-DYwH0vLi.js → instanced-mesh-instance-NnODkvqK.js} +2 -2
- package/dist/{instanced-mesh-instance-DYwH0vLi.js.map → instanced-mesh-instance-NnODkvqK.js.map} +1 -1
- package/dist/mat4-D6exvAuO.js +949 -0
- package/dist/mat4-D6exvAuO.js.map +1 -0
- package/dist/{render-path-Dx0learj.js → render-path-Be7WgN7r.js} +35 -4
- package/dist/render-path-Be7WgN7r.js.map +1 -0
- package/dist/{render-texture-IuR0iFVa.js → render-texture-C_TnaSz2.js} +28 -2
- package/dist/render-texture-C_TnaSz2.js.map +1 -0
- package/dist/scene-color-passes-DlNr-qyZ.js +65 -0
- package/dist/scene-color-passes-DlNr-qyZ.js.map +1 -0
- package/dist/scene-inputs-BxGOsnIZ.js +318 -0
- package/dist/scene-inputs-BxGOsnIZ.js.map +1 -0
- package/dist/{shader-material-CDQ0Y5kN.js → shader-material-B6p66wB8.js} +17 -6
- package/dist/shader-material-B6p66wB8.js.map +1 -0
- package/dist/{shader-material-BPb_oEZQ.js → shader-material-C0TAUr4t.js} +102 -4
- package/dist/shader-material-C0TAUr4t.js.map +1 -0
- package/dist/ssgi-Dm-maZrc.js +113 -0
- package/dist/ssgi-Dm-maZrc.js.map +1 -0
- package/dist/{surface-shader-CwQ03yHG.js → surface-shader-BaK0kvBB.js} +2 -2
- package/dist/{surface-shader-CwQ03yHG.js.map → surface-shader-BaK0kvBB.js.map} +1 -1
- package/dist/taa-BwBZLy11.js +480 -0
- package/dist/taa-BwBZLy11.js.map +1 -0
- package/dist/{vec3-T2PasQZv.js → vec3-D-0Y2mzE.js} +4 -948
- package/dist/vec3-D-0Y2mzE.js.map +1 -0
- package/package.json +4 -2
- package/dist/decoders-CHJ7vduE.js.map +0 -1
- package/dist/environment-Cq2BmA96.js.map +0 -1
- package/dist/hdr-output-DDpIo4Q5.js +0 -300
- package/dist/hdr-output-DDpIo4Q5.js.map +0 -1
- package/dist/render-path-Dx0learj.js.map +0 -1
- package/dist/render-texture-IuR0iFVa.js.map +0 -1
- package/dist/shader-material-BPb_oEZQ.js.map +0 -1
- package/dist/shader-material-CDQ0Y5kN.js.map +0 -1
- package/dist/vec3-T2PasQZv.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hdr-output-BrUvpAsE.js","names":[],"sources":["../src/lite/gpu/hdr-output.ts"],"sourcesContent":["import {\n AcesToneMapping,\n addTask,\n addTaskBefore,\n buildFrameGraphTask,\n createEffectRenderTask,\n createEffectWrapper,\n createRenderTarget,\n createRenderTask,\n createSurfaceRenderTargetTexture,\n enableMaterialPlugins,\n getFrameGraph,\n getPbrUnlit,\n isPbrMaterial,\n isStandardMaterial,\n NeutralToneMapping,\n onRenderTargetTextureResize,\n reconcileMaterialPlugins,\n setEffectTexture,\n setEffectUniforms,\n setEnvironmentRotation,\n setFog,\n StandardToneMapping,\n} from \"@babylonjs/lite\";\nimport { rebuildMaterialPipelines } from \"../material.js\";\nimport { AGX_CALL_WGSL, AGX_HELPERS_WGSL, AGX_TONE_MAPPING_ID } from \"./agx-tone-mapping.js\";\nimport { DEPTH_STENCIL_FORMAT, markHdrScene } from \"./render-path.js\";\nimport type { AutoExposurePass } from \"./auto-exposure.js\";\nimport type { HdrOutputHandle, ScenePresenter } from \"./render-path.js\";\nimport type {\n EffectWrapper,\n EngineContext,\n FogConfig,\n ImageProcessingConfig,\n MaterialPlugin,\n RenderTarget,\n SceneContext,\n Task,\n Texture2D,\n} from \"@babylonjs/lite\";\n\n/**\n * The HDR render path (`docs/plan/2026-11-gi-phase-1-execution-plan.md`, step G2): the frame graph\n * a scene gets when the project declares `rendering.hdr`. Its own chunk: `../engine.ts` imports it\n * only when the setting is on, so a project without HDR loads none of it (`CONSTITUTION.md` §2.5).\n *\n * ```text\n * [shadow] → scene ──→ hdr (rgba16float) ─ [custom effects, linear] ─→ output ──→ swapchain\n * └──→ sceneColor ─ (built-in effects)\n * ```\n *\n * - **Linear colour.** Lite's PBR shader ends every fragment with fog, exposure, the curve, a\n * `pow(1/2.2)` encode, a clamp and contrast (`lib/material/pbr/pbr-template.js` line 171), so an\n * `rgba16float` target alone still holds values ≤ 1. {@link createLinearOutputPlugin} saves the\n * colour before that block and restores it before the fragment is written (spike S1).\n * - **The output pass** applies the scene's `imageProcessing` — exposure, contrast and the curve\n * the `Environment` set, or `loadEnvironment` set — then the same encode, clamp and contrast,\n * so a PBR-only scene presents the same bytes as without HDR, within half-float rounding.\n * - **Two output tasks.** A task cannot change its target once recorded, so there is one that\n * writes the swapchain and one that writes `sceneColor`, an ordinary colour target a\n * `PostProcessStack` chain reads. {@link ScenePresenter.setPresentEnabled} switches between them,\n * so the frame runs exactly one.\n *\n * - **Every other colour writer (step G3).** The restore re-applies the PBR fog, so a fogged scene\n * keeps its fog. A Standard material (and a surface shader on one) gets\n * {@link createStandardLinearPlugin}, which decodes its display colour; a surface shader on a PBR\n * host is caught by the PBR plugin, because its composite runs before the save. Lite's environment\n * skyboxes (`.env`, `.dds`) are patched to return the cube map's linear colour\n * ({@link linearSkyboxFragment}). Custom `.wgsl` materials (particles, foliage) are wrapped by\n * `./shader-material.ts`, which asks {@link markHdrScene}'s record. Sprites need nothing: a\n * `SpriteRenderer` draws its own pass onto the swapchain after the scene, so it never passes\n * through the output pass. Under HDR, Standard and custom-shader colour now gets the scene's\n * exposure, curve and contrast like everything else; with Lite's defaults (exposure 1, contrast 1,\n * no curve) that is the identity and the image matches the plain path.\n * - **Fog colour.** The scene's fog colour is stored decoded here, so the Standard fog block blends\n * in linear space and the PBR restore can use it as is.\n * - **Custom effects first.** A `PostProcessStack`'s custom effects ordered before any built-in one\n * are inserted before the output pass ({@link HdrOutputHandle.insertLinearTask}) and the output\n * pass reads the last one's result ({@link HdrOutputHandle.setOutputSource}). Bloom, SMAA and\n * Lite's image-processing task stay after it: they expect display colour and 8-bit targets.\n *\n * Not covered: Lite's six-face `loadSkybox` cube and its solid-colour and ground backgrounds, which\n * have fixed shaders with no patch point; they still encode twice under HDR.\n */\n\n/**\n * The colour format of the HDR scene target.\n *\n * @internal\n */\nexport const HDR_SCENE_FORMAT: GPUTextureFormat = \"rgba16float\";\n\n/**\n * The name the linear-output plugin carries; part of Lite's pipeline cache key.\n *\n * @internal\n */\nexport const LINEAR_OUTPUT_PLUGIN_NAME = \"ignifx-hdr-linear-output\";\n\n/**\n * The name the Standard material's decode plugin carries.\n *\n * @internal\n */\nexport const STANDARD_LINEAR_PLUGIN_NAME = \"ignifx-hdr-linear-standard\";\n\n/**\n * The name the unlit PBR material's plugin carries.\n *\n * @internal\n */\nexport const UNLIT_LINEAR_PLUGIN_NAME = \"ignifx-hdr-linear-unlit\";\n\n/**\n * Where the skybox patch sits in Lite's skybox patch list: after rotation (0) and blur (1)\n * (`lib/scene/set-environment-rotation.js`, `lib/scene/set-environment-blur.js`).\n */\nconst SKYBOX_PATCH_ORDER = 8;\n\n/**\n * Lite's fog factor (`lib/shader/wgsl-fog.js`) under an ignifx name: the PBR shader declares\n * `calcFogFactor` only when the scene has fog, and the plugin code must compile either way.\n */\nconst FOG_FACTOR_WGSL =\n \"fn ignifxFogFactor(d:vec3<f32>)->f32{var k:f32=1.0;let mode=scene.vFogInfos.x;let dist=length(d);\" +\n \"if(mode==3.0){k=(scene.vFogInfos.z-dist)/(scene.vFogInfos.z-scene.vFogInfos.y);}\" +\n \"else if(mode==1.0){k=1.0/pow(2.71828,dist*scene.vFogInfos.w);}\" +\n \"else if(mode==2.0){k=1.0/pow(2.71828,dist*dist*scene.vFogInfos.w*scene.vFogInfos.w);}\" +\n \"return clamp(k,0.0,1.0);}\";\n\n/**\n * The PBR fog block (`lib/material/pbr/pbr-fog-wgsl.js`) on the restored colour, except that the\n * fog colour is already linear: the HDR path stores it decoded.\n */\nconst FOG_RESTORE_WGSL =\n \"if(scene.vFogInfos.x>0.0){color=mix(scene.vFogColor.rgb,color,\" +\n \"pow(ignifxFogFactor((scene.view*vec4<f32>(input.worldPos,1.0)).xyz),2.2));}\";\n\n/**\n * The frame-graph task names, in the order they run after `\"scene\"`.\n *\n * @internal\n */\nexport const HDR_OUTPUT_TASK_NAMES = { toChain: \"ignifx:hdr-output-chain\", toSwapchain: \"ignifx:hdr-output\" } as const;\n\n/**\n * The curve numbers the output shader branches on.\n *\n * @internal\n */\nexport const HDR_CURVE = { none: 0, standard: 1, aces: 2, neutral: 3, agx: 4 } as const;\n\n/** The output pass's uniform block: exposure, contrast, curve, padding. */\nconst UNIFORM_FLOATS = 4;\n\n/**\n * Builds the material plugin that keeps a PBR fragment's colour linear.\n *\n * @remarks\n * `CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION` is injected at two slots (`AI`, `NI`;\n * `lib/material/plugin/plugin-bridge-shared.js` line 13), so the save is an assignment, never a\n * `let`; the second one, after indirect light, wins. Priority 0 puts the restore ahead of any other\n * plugin's `CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR` code, which then works on linear colour.\n *\n * @returns The plugin. Plain data, so one object can be shared by every material.\n *\n * @internal\n */\nexport function createLinearOutputPlugin(): MaterialPlugin {\n const fragment = {\n CUSTOM_FRAGMENT_DEFINITIONS: `var<private> ignifxLinearColor: vec3<f32>;${FOG_FACTOR_WGSL}`,\n CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION: \"ignifxLinearColor = color;\",\n CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR: `color = ignifxLinearColor;${FOG_RESTORE_WGSL}`,\n };\n return {\n name: LINEAR_OUTPUT_PLUGIN_NAME,\n priority: 0,\n getCustomCode: (stage) => (stage === \"fragment\" ? fragment : null),\n };\n}\n\n/**\n * Builds the plugin that keeps an unlit PBR material's colour linear.\n *\n * @remarks\n * With no environment, Lite's unlit fragment assigns its colour at the `NI` slot\n * (`lib/material/pbr/fragments/unlit-fragment.js`), after the linear-output plugin's save there, so\n * the save would hold the lit colour. This plugin recomputes the unlit colour instead\n * (`baseColor * material.unlitColor`, both in scope before the fragment is written), then applies\n * the fog the restore would.\n *\n * @returns The plugin, shared by every unlit PBR material.\n *\n * @internal\n */\nexport function createUnlitLinearPlugin(): MaterialPlugin {\n const fragment = {\n CUSTOM_FRAGMENT_DEFINITIONS: FOG_FACTOR_WGSL,\n CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR: `color = baseColor*material.unlitColor;${FOG_RESTORE_WGSL}`,\n };\n return {\n name: UNLIT_LINEAR_PLUGIN_NAME,\n priority: 0,\n getCustomCode: (stage) => (stage === \"fragment\" ? fragment : null),\n };\n}\n\n/**\n * Builds the plugin that turns a Standard material's colour linear.\n *\n * @remarks\n * Lite's Standard shader does no image processing and no encode: what it writes is the colour that\n * is displayed. The plugin decodes it with the exact inverse of the output pass's encode\n * (`pow(c, 2.2)`), so the output pass gives it back. It runs at the `BC` slot, before Lite's Standard fog\n * block (the `BA` slot), which then mixes in the decoded fog colour. Priority 1000 puts it after any\n * surface shader's own `CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR` code.\n *\n * @returns The plugin, shared by every Standard material.\n *\n * @internal\n */\nexport function createStandardLinearPlugin(): MaterialPlugin {\n const fragment = {\n CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR: \"color=vec4<f32>(pow(max(color.rgb,vec3<f32>(0.0)),vec3<f32>(2.2)),color.a);\",\n };\n return {\n name: STANDARD_LINEAR_PLUGIN_NAME,\n priority: 1000,\n getCustomCode: (stage) => (stage === \"fragment\" ? fragment : null),\n };\n}\n\n/**\n * Makes one of Lite's environment skybox shaders return the cube map's linear colour.\n *\n * @remarks\n * The `.env` (`\"hdr\"`) and `.dds` skyboxes multiply by `mesh.exposureLinear`, then encode, clamp\n * and apply contrast themselves (`lib/material/pbr/background-hdr-skybox.js`,\n * `lib/_chunks/background-dds-skybox-*.js`), and Lite gives them no material plugin point. The patch\n * returns the colour just before that multiply, so the output pass applies exposure, the curve and\n * the encode once. Code after the inserted `return` is unreachable, which WGSL accepts. A shader the\n * pattern does not match is returned unchanged.\n *\n * @param fragment - The skybox fragment WGSL, after Lite's own rotation and blur patches.\n * @returns The patched WGSL.\n *\n * @internal\n */\nexport function linearSkyboxFragment(fragment: string): string {\n const match = /\\b([A-Za-z_]\\w*)\\*=mesh\\.exposureLinear;/u.exec(fragment);\n if (match === null) {\n return fragment;\n }\n return `${fragment.slice(0, match.index)}return vec4<f32>(${match[1] ?? \"\"},1.0);${fragment.slice(match.index)}`;\n}\n\n/**\n * A fog configuration with its colour decoded the way Lite's PBR fog block decodes it.\n *\n * @param fog - The configuration the `Environment` installed, colour in sRGB.\n * @returns A fresh configuration, colour linear.\n *\n * @internal\n */\nexport function linearFogConfig(fog: FogConfig): FogConfig {\n return {\n mode: fog.mode,\n density: fog.density,\n start: fog.start,\n end: fog.end,\n color: [fog.color[0] ** 2.2, fog.color[1] ** 2.2, fog.color[2] ** 2.2],\n };\n}\n\n/**\n * Builds the output pass's fragment shader.\n *\n * @remarks\n * The curves are Lite's own WGSL (`ToneMapping.helpersWGSL`/`callWGSL`) and ignifx's AgX in the\n * same form (`./agx-tone-mapping.ts`, so both paths run one function), which read the exposure\n * from `scene.vImageInfos.x`; naming the uniform block `scene` lets them drop in unchanged. One\n * shader holds all of them and branches on a uniform, so a curve change uploads 16 bytes instead\n * of compiling a pipeline. The encode, clamp and contrast copy the PBR template's tail.\n *\n * @param autoExposure - Whether binding 2 holds the auto exposure texel (`./auto-exposure.ts`),\n * `log2` of a multiplier applied before the curve.\n * @returns The WGSL, with Lite's `effectFragment` entry point.\n *\n * @internal\n */\nexport function hdrOutputFragmentWgsl(autoExposure = false): string {\n return [\n AcesToneMapping.helpersWGSL,\n NeutralToneMapping.helpersWGSL,\n AGX_HELPERS_WGSL,\n \"struct HdrOutputUniforms{vImageInfos:vec4<f32>};\",\n \"@group(0)@binding(0)var<uniform>scene:HdrOutputUniforms;\",\n \"@group(0)@binding(1)var hdrColor:texture_2d<f32>;\",\n autoExposure ? \"@group(0)@binding(2)var autoExposure:texture_2d<f32>;\" : \"\",\n \"@fragment fn effectFragment(fragment:EffectVertexOutput)->@location(0)vec4<f32>{\",\n \"let texel=textureLoad(hdrColor,vec2<i32>(fragment.position.xy),0);\",\n \"var color=max(texel.rgb,vec3<f32>(0.0));\",\n autoExposure ? \"color*=exp2(textureLoad(autoExposure,vec2<i32>(0,0),0).r);\" : \"\",\n \"let curve=i32(scene.vImageInfos.z+0.5);\",\n `if(curve==${String(HDR_CURVE.standard)}){${StandardToneMapping.callWGSL}}`,\n `else if(curve==${String(HDR_CURVE.aces)}){${AcesToneMapping.callWGSL}}`,\n `else if(curve==${String(HDR_CURVE.neutral)}){${NeutralToneMapping.callWGSL}}`,\n `else if(curve==${String(HDR_CURVE.agx)}){${AGX_CALL_WGSL}}`,\n \"else{color*=scene.vImageInfos.x;}\",\n \"color=pow(color,vec3<f32>(1.0/2.2));\",\n \"color=clamp(color,vec3<f32>(0.0),vec3<f32>(1.0));\",\n \"let highContrast=color*color*(3.0-2.0*color);\",\n \"if(scene.vImageInfos.y<1.0){color=mix(vec3<f32>(0.5),color,scene.vImageInfos.y);}\",\n \"else{color=mix(color,highContrast,scene.vImageInfos.y-1.0);}\",\n \"color=max(color,vec3<f32>(0.0));\",\n \"return vec4<f32>(color,texel.a);\",\n \"}\",\n ].join(\"\\n\");\n}\n\n/**\n * The curve number for a scene's image processing.\n *\n * @remarks\n * Tone mapping switched on with no curve named is Lite's standard curve (`pbr-renderable.js`). A\n * custom Lite curve the output pass does not know falls back to the standard one.\n *\n * @param processing - The scene's image processing.\n * @returns One of {@link HDR_CURVE}.\n *\n * @internal\n */\nexport function hdrCurveOf(processing: Pick<ImageProcessingConfig, \"toneMappingEnabled\" | \"toneMapping\">): number {\n if (!processing.toneMappingEnabled) {\n return HDR_CURVE.none;\n }\n const id = processing.toneMapping?.id;\n if (id === AcesToneMapping.id) {\n return HDR_CURVE.aces;\n }\n if (id === AGX_TONE_MAPPING_ID) {\n return HDR_CURVE.agx;\n }\n return id === NeutralToneMapping.id ? HDR_CURVE.neutral : HDR_CURVE.standard;\n}\n\n/**\n * Writes the output pass's uniforms and says whether they changed.\n *\n * @param processing - The scene's image processing.\n * @param out - The four floats: exposure, contrast, curve, padding.\n * @returns `true` when `out` now differs from what it held.\n *\n * @internal\n */\nexport function writeHdrOutputUniforms(processing: ImageProcessingConfig, out: Float32Array): boolean {\n const curve = hdrCurveOf(processing);\n if (out[0] === processing.exposure && out[1] === processing.contrast && out[2] === curve) {\n return false;\n }\n out[0] = processing.exposure;\n out[1] = processing.contrast;\n out[2] = curve;\n return true;\n}\n\n/**\n * Builds the HDR render path and appends it to the scene's frame graph.\n *\n * @remarks\n * The same contract as `installOffscreenRenderPath` in `./render-path.ts`: call it right after\n * `createSceneContext(engine, { defaultRenderTask: false })` and before `registerScene`. It also\n * installs Lite's material-plugin bridges, which the linear-output plugin needs before the scene is\n * registered. With MSAA on, the scene draws into a multisampled `rgba16float` target that resolves\n * into the sampled one.\n *\n * @param engine - The engine, which is also the primary surface.\n * @param scene - The scene created with no default render task.\n * @param installAutoExposure - Builds the auto exposure passes over the HDR texture, between the\n * scene task and the output tasks (`./auto-exposure.ts`); omitted when auto exposure is off.\n * @returns The presenter, with its {@link ScenePresenter.hdr} handle set.\n *\n * @internal\n */\nexport function installHdrRenderPath(\n engine: EngineContext,\n scene: SceneContext,\n installAutoExposure?: (hdrTexture: Texture2D) => AutoExposurePass,\n): ScenePresenter {\n enableMaterialPlugins(scene);\n markHdrScene(scene);\n installLinearSkybox(scene);\n const hdr = createSurfaceRenderTargetTexture(engine, {\n lbl: \"ignifx:scene-hdr\",\n format: HDR_SCENE_FORMAT,\n samples: 1,\n size: engine,\n });\n const isMultisampled = engine.msaaSamples > 1;\n const config: { name: string; rt: RenderTarget; rst?: RenderTarget; depth?: RenderTarget } = {\n name: \"scene\",\n rt: hdr.rt,\n };\n if (isMultisampled) {\n config.rt = createRenderTarget({\n lbl: \"ignifx:scene-hdr-msaa\",\n format: HDR_SCENE_FORMAT,\n dFormat: DEPTH_STENCIL_FORMAT,\n samples: engine.msaaSamples,\n size: engine,\n });\n config.rst = hdr.rt;\n } else {\n config.depth = createRenderTarget({\n lbl: \"ignifx:scene-depth\",\n dFormat: DEPTH_STENCIL_FORMAT,\n samples: 1,\n size: engine,\n });\n }\n const sceneTask: Task = createRenderTask(config, engine, scene);\n addTask(scene, sceneTask);\n const autoExposure = installAutoExposure?.(hdr.texture) ?? null;\n\n const effect: EffectWrapper = createEffectWrapper(engine, {\n name: \"ignifx:hdr-output\",\n fragmentWGSL: hdrOutputFragmentWgsl(autoExposure !== null),\n bindings: [\n { name: \"hdrOutput\", binding: 0, kind: \"uniform\", uniformByteLength: UNIFORM_FLOATS * 4 },\n { name: \"hdrColor\", binding: 1, kind: \"texture\" },\n ...(autoExposure === null\n ? []\n : [\n {\n name: \"autoExposure\",\n binding: 2,\n kind: \"texture\" as const,\n textureSampleType: \"unfilterable-float\" as const,\n },\n ]),\n ],\n });\n setEffectTexture(effect, 1, hdr.texture);\n if (autoExposure !== null) {\n setEffectTexture(effect, 2, autoExposure.exposureTexture);\n }\n // What the output pass reads: the scene, or the last linear effect a PostProcessStack put first.\n let outputSource: Texture2D | null = null;\n // A resize swaps the texture behind the facade; the wrapper's cached bind group still holds the\n // old view until a texture write marks it dirty.\n onRenderTargetTextureResize(hdr, () => {\n setEffectTexture(effect, 1, outputSource ?? hdr.texture);\n });\n const uniforms = new Float32Array(UNIFORM_FLOATS);\n uniforms[0] = Number.NaN;\n writeHdrOutputUniforms(scene.imageProcessing, uniforms);\n setEffectUniforms(effect, uniforms);\n\n const sceneColor = createRenderTarget({ lbl: \"ignifx:scene-color\", format: engine.format, samples: 1, size: engine });\n const toChain: Task = createEffectRenderTask(\n { name: HDR_OUTPUT_TASK_NAMES.toChain, effect, target: sceneColor, clear: true },\n engine,\n scene,\n );\n const toSwapchain: Task = createEffectRenderTask(\n { name: HDR_OUTPUT_TASK_NAMES.toSwapchain, effect, target: engine.scRT, clear: true },\n engine,\n scene,\n );\n addTask(scene, toChain);\n addTask(scene, toSwapchain);\n toChain.executionEnabled = false;\n\n const plugins: LinearPlugins = {\n pbr: createLinearOutputPlugin(),\n unlit: createUnlitLinearPlugin(),\n standard: createStandardLinearPlugin(),\n };\n let linearFog: FogConfig | null = null;\n const handle: HdrOutputHandle = {\n sceneTexture: hdr.texture,\n exposureTexture: autoExposure?.exposureTexture ?? null,\n sceneTarget: hdr.rt,\n sceneTask,\n sceneTargetTexture: hdr,\n update(isSceneRegistered: boolean): void {\n autoExposure?.update();\n if (writeHdrOutputUniforms(scene.imageProcessing, uniforms)) {\n setEffectUniforms(effect, uniforms);\n }\n // The `Environment` installs a fresh sRGB config on every change; it is swapped for a decoded\n // copy once, before the frame reads it (`setFog` re-registers nothing it already has).\n const fog = scene.fog;\n if (fog !== null && fog !== linearFog) {\n linearFog = linearFogConfig(fog);\n setFog(scene, linearFog);\n }\n attachLinearOutput(scene, plugins, isSceneRegistered);\n },\n insertLinearTask(task: Task, isFrameGraphBuilt: boolean): void {\n addTaskBefore(scene, task, toChain);\n if (isFrameGraphBuilt) {\n buildFrameGraphTask(getFrameGraph(scene), task);\n }\n },\n setOutputSource(texture: Texture2D | null): void {\n if (texture === outputSource) {\n return;\n }\n outputSource = texture;\n setEffectTexture(effect, 1, texture ?? hdr.texture);\n },\n };\n let isPresentEnabled = true;\n return {\n sceneColor,\n swapchain: engine.scRT,\n setPresentEnabled(enabled: boolean): void {\n isPresentEnabled = enabled;\n toSwapchain.executionEnabled = enabled;\n toChain.executionEnabled = !enabled;\n },\n get isPresentEnabled(): boolean {\n return isPresentEnabled;\n },\n hdr: handle,\n scenePass: { task: sceneTask, target: hdr.rt, format: HDR_SCENE_FORMAT },\n };\n}\n\n/** The two shared plugins the per-frame walk hands out. */\ninterface LinearPlugins {\n /** The save, restore and fog for PBR materials, PBR skyboxes included. */\n readonly pbr: MaterialPlugin;\n /** The recompute and fog for unlit PBR materials. */\n readonly unlit: MaterialPlugin;\n /** The decode for Standard materials. */\n readonly standard: MaterialPlugin;\n}\n\n/**\n * Makes Lite's environment skyboxes write linear colour (see {@link linearSkyboxFragment}).\n *\n * @remarks\n * Lite composes a skybox's fragment through `scene._environmentSkyboxShaderComposer`, which runs the\n * loaders in `scene._environmentSkyboxShaderPatchLoaders` in order\n * (`lib/material/pbr/environment-skybox-shader-composer.js`). Neither field is declared in\n * `index.d.ts`, and the composer is created only by Lite's own registration, which also prepends\n * the scene uniforms the `.env` skybox needs. `setEnvironmentRotation(scene, 0)` is that\n * registration with no visible effect (rotation 0 is what the scene has); the `Environment`\n * overwrites it with its own rotation later. The patch is installed before any environment loads,\n * and pinned by `test/render/hdr-coverage.browser.test.ts`.\n *\n * @param scene - The HDR scene.\n */\nfunction installLinearSkybox(scene: SceneContext): void {\n setEnvironmentRotation(scene, 0);\n // Boundary assertion (coding standards §5.2): the loader list is a plain array Lite keeps on the\n // scene object it created; see the remarks for the `lib/` file that reads it.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n const slots = scene as SceneContext & SkyboxPatchSlots;\n // oxlint-disable-next-line no-underscore-dangle\n const loaders = (slots._environmentSkyboxShaderPatchLoaders ??= []);\n loaders[SKYBOX_PATCH_ORDER] = () => Promise.resolve({ _apply: linearSkyboxFragment });\n}\n\n/** The undeclared Lite scene field the skybox patch writes (adapter-internal mirror, standards §5.1). */\ninterface SkyboxPatchSlots {\n /** Lite's skybox shader patches, by order; each resolves to an object whose `_apply` edits the WGSL. */\n _environmentSkyboxShaderPatchLoaders?: (SkyboxPatchLoader | undefined)[];\n}\n\n/** One entry of Lite's skybox patch list. */\ntype SkyboxPatchLoader = () => Promise<{ readonly _apply: (fragment: string, kind: string) => string }>;\n\n/**\n * Gives every PBR and Standard material in the scene its linear-output plugin, once.\n *\n * @remarks\n * A walk rather than a hook at material creation, because materials come from several places\n * (material assets, glTF models, `.lite` code) and a surface shader replaces a material's whole\n * plugin list; a material that lost the plugin gets it back on the next frame. A PBR skybox\n * (`setPbrSkybox`) is a PBR material and gets the PBR plugin. Lite's mesh factories leave\n * `material` `null` until one is assigned.\n *\n * @param scene - The scene to walk.\n * @param shared - The shared plugins.\n * @param isSceneRegistered - Whether a patched material's pipelines must be rebuilt.\n */\nfunction attachLinearOutput(scene: SceneContext, shared: LinearPlugins, isSceneRegistered: boolean): void {\n const meshes = scene.meshes;\n for (let index = 0; index < meshes.length; index += 1) {\n const material = meshes[index]?.material;\n // Declared non-null, but Lite's mesh factories create meshes with `material: null`\n // (`lib/mesh/mesh-factories.js`), and `isPbrMaterial(null)` throws.\n // oxlint-disable-next-line typescript/no-unnecessary-condition\n if (material === undefined || material === null) {\n continue;\n }\n let plugin: MaterialPlugin;\n if (isPbrMaterial(material)) {\n plugin = getPbrUnlit(material) === undefined ? shared.pbr : shared.unlit;\n } else if (isStandardMaterial(material)) {\n plugin = shared.standard;\n } else {\n continue;\n }\n const current = material.plugins ?? [];\n // A PBR material that became unlit, or stopped being so, swaps one plugin for the other.\n let stale: MaterialPlugin | null = null;\n if (plugin === shared.pbr) {\n stale = shared.unlit;\n } else if (plugin === shared.unlit) {\n stale = shared.pbr;\n }\n const hasStale = stale !== null && current.includes(stale);\n if (current.includes(plugin) && !hasStale) {\n continue;\n }\n const kept = hasStale ? current.filter((other) => other !== stale) : current;\n material.plugins = kept.includes(plugin) ? kept : [...kept, plugin];\n if (plugin === shared.standard) {\n // The Standard bridge bakes a plugin signature per material, which only happens for meshes it\n // saw at `enableMaterialPlugins` or at a material change; this bakes and rebuilds it now.\n void reconcileMaterialPlugins(scene, material);\n continue;\n }\n if (isSceneRegistered) {\n rebuildMaterialPipelines(scene, material);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0FA,MAAa,mBAAqC;;;;;;AAOlD,MAAa,4BAA4B;;;;;;AAOzC,MAAa,8BAA8B;;;;;;AAO3C,MAAa,2BAA2B;;;;;AAMxC,MAAM,qBAAqB;;;;;AAM3B,MAAM,kBACJ;;;;;AAUF,MAAM,mBACJ;;;;;;AAQF,MAAa,wBAAwB;CAAE,SAAS;CAA2B,aAAa;AAAoB;;;;;;AAO5G,MAAa,YAAY;CAAE,MAAM;CAAG,UAAU;CAAG,MAAM;CAAG,SAAS;CAAG,KAAK;AAAE;;AAG7E,MAAM,iBAAiB;;;;;;;;;;;;;;AAevB,SAAgB,2BAA2C;CACzD,MAAM,WAAW;EACf,6BAA6B,6CAA6C;EAC1E,8CAA8C;EAC9C,kCAAkC,6BAA6B;CACjE;CACA,OAAO;EACL,MAAM;EACN,UAAU;EACV,gBAAgB,UAAW,UAAU,aAA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