@ignifx/core 0.17.0 → 0.18.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.
Files changed (46) hide show
  1. package/dist/{environment-CMpzGXTz.js → environment-DZ6WUHbm.js} +2 -2
  2. package/dist/{environment-CMpzGXTz.js.map → environment-DZ6WUHbm.js.map} +1 -1
  3. package/dist/{hdr-output-BrUvpAsE.js → hdr-output-Dbv0lhFl.js} +4 -3
  4. package/dist/{hdr-output-BrUvpAsE.js.map → hdr-output-Dbv0lhFl.js.map} +1 -1
  5. package/dist/{ignifx-error-Der0bpHK.js → ignifx-error-B8ByiSfJ.js} +10 -1
  6. package/dist/ignifx-error-B8ByiSfJ.js.map +1 -0
  7. package/dist/index.d.ts +110 -3
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +836 -35
  10. package/dist/index.js.map +1 -1
  11. package/dist/light-probe-asset-B60_X-yN.js +331 -0
  12. package/dist/light-probe-asset-B60_X-yN.js.map +1 -0
  13. package/dist/light-probes-DkYN89Qw.js +284 -0
  14. package/dist/light-probes-DkYN89Qw.js.map +1 -0
  15. package/dist/{material-plugin-B-hartHR.js → material-plugin-CiAmriQ_.js} +2 -2
  16. package/dist/{material-plugin-B-hartHR.js.map → material-plugin-CiAmriQ_.js.map} +1 -1
  17. package/dist/{post-effect-CuoYvrhb.js → post-effect-CQnlX1RH.js} +2 -2
  18. package/dist/{post-effect-CuoYvrhb.js.map → post-effect-CQnlX1RH.js.map} +1 -1
  19. package/dist/{post-effect-compiler-Bps8QbiJ.js → post-effect-compiler-C_7HTHZy.js} +3 -3
  20. package/dist/{post-effect-compiler-Bps8QbiJ.js.map → post-effect-compiler-C_7HTHZy.js.map} +1 -1
  21. package/dist/{prefab-overrides-76IhcF-e.d.ts → prefab-overrides-BLQn5yHS.d.ts} +231 -7
  22. package/dist/prefab-overrides-BLQn5yHS.d.ts.map +1 -0
  23. package/dist/{prefab-overrides-DGiGTSN-.js → prefab-overrides-DT-wHHAJ.js} +2 -2
  24. package/dist/{prefab-overrides-DGiGTSN-.js.map → prefab-overrides-DT-wHHAJ.js.map} +1 -1
  25. package/dist/prefab.d.ts +1 -1
  26. package/dist/prefab.js +1 -1
  27. package/dist/{reflection-probe-C0pzGrG_.js → reflection-probe-DlVsl3zJ.js} +3 -3
  28. package/dist/{reflection-probe-C0pzGrG_.js.map → reflection-probe-DlVsl3zJ.js.map} +1 -1
  29. package/dist/{reflection-probes-B8_vK9YR.js → reflection-probes-B8S9WnVX.js} +3 -3
  30. package/dist/{reflection-probes-B8_vK9YR.js.map → reflection-probes-B8S9WnVX.js.map} +1 -1
  31. package/dist/{render-path-Be7WgN7r.js → render-path-D11i_7X8.js} +3 -2
  32. package/dist/{render-path-Be7WgN7r.js.map → render-path-D11i_7X8.js.map} +1 -1
  33. package/dist/{scene-color-passes-DlNr-qyZ.js → scene-color-passes-B93qTOka.js} +35 -12
  34. package/dist/scene-color-passes-B93qTOka.js.map +1 -0
  35. package/dist/{shader-material-Cjfq7nFS.js → shader-material-C2_UCYdO.js} +5 -5
  36. package/dist/{shader-material-Cjfq7nFS.js.map → shader-material-C2_UCYdO.js.map} +1 -1
  37. package/dist/{shader-material-DCjYDdkh.js → shader-material-CaAkv5nT.js} +2 -2
  38. package/dist/{shader-material-DCjYDdkh.js.map → shader-material-CaAkv5nT.js.map} +1 -1
  39. package/dist/{shader-pragma-cjEC-EPK.js → shader-pragma-DmZpxGUo.js} +2 -2
  40. package/dist/{shader-pragma-cjEC-EPK.js.map → shader-pragma-DmZpxGUo.js.map} +1 -1
  41. package/dist/{surface-shader-D40hXQ8c.js → surface-shader-BeDRofOV.js} +4 -4
  42. package/dist/{surface-shader-D40hXQ8c.js.map → surface-shader-BeDRofOV.js.map} +1 -1
  43. package/package.json +1 -1
  44. package/dist/ignifx-error-Der0bpHK.js.map +0 -1
  45. package/dist/prefab-overrides-76IhcF-e.d.ts.map +0 -1
  46. package/dist/scene-color-passes-DlNr-qyZ.js.map +0 -1
@@ -1,5 +1,5 @@
1
- import { K as toEntityHandle, L as readOwnerTag, a as EDITOR_ONLY_METADATA_KEY, i as selectReflectionProbe, r as resolveReflectionProbeSize } from "./reflection-probe-C0pzGrG_.js";
2
- import { i as readSceneEnvironment } from "./environment-CMpzGXTz.js";
1
+ import { K as toEntityHandle, L as readOwnerTag, a as EDITOR_ONLY_METADATA_KEY, i as selectReflectionProbe, r as resolveReflectionProbeSize } from "./reflection-probe-DlVsl3zJ.js";
2
+ import { i as readSceneEnvironment } from "./environment-DZ6WUHbm.js";
3
3
  import { o as rebuildMaterialPipelines } from "./material-CGk5mAah.js";
4
4
  import { n as deviceOf, r as removeTask, t as colorTextureOf } from "./render-texture-UqRHRLQy.js";
5
5
  import { addTask, buildFrameGraphTask, clearPbrLocalEnvironment, createBankedFreeCamera, createRenderTarget, createRenderTask, enablePbrLocalCubemap, getFrameGraph, getPbrUnlit, isPbrMaterial, isPbrSkybox, setPbrEnvironment, setPbrLocalEnvironment } from "@babylonjs/lite";
@@ -548,4 +548,4 @@ function bindingFor(previous, environment, x, y, z, box) {
548
548
  //#endregion
549
549
  export { createReflectionProbeRuntime };
550
550
 
551
- //# sourceMappingURL=reflection-probes-B8_vK9YR.js.map
551
+ //# sourceMappingURL=reflection-probes-B8S9WnVX.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reflection-probes-B8_vK9YR.js","names":[],"sources":["../src/lite/gpu/reflection-probe.ts","../src/render/gpu/reflection-probes.ts"],"sourcesContent":["import {\n addTask,\n buildFrameGraphTask,\n clearPbrLocalEnvironment,\n createBankedFreeCamera,\n createRenderTarget,\n createRenderTask,\n enablePbrLocalCubemap,\n getFrameGraph,\n getPbrUnlit,\n isPbrMaterial,\n isPbrSkybox,\n setPbrEnvironment,\n setPbrLocalEnvironment,\n} from \"@babylonjs/lite\";\nimport { rebuildMaterialPipelines } from \"../material.js\";\nimport { readOwnerTag } from \"../picking.js\";\nimport { readSceneEnvironment } from \"./environment.js\";\nimport { colorTextureOf, deviceOf, removeTask } from \"./render-texture.js\";\nimport type { NodeTag } from \"../node.js\";\nimport type {\n BankedFreeCamera,\n EngineContext,\n EnvironmentTextures,\n Mesh,\n PbrMaterialProps,\n RenderTarget,\n RenderTask,\n SceneContext,\n} from \"@babylonjs/lite\";\n\n/**\n * Reflection probes (`docs/plan/2026-11-gi-phase-2-execution-plan.md`, step B1). Its own chunk,\n * loaded only when a world has a `ReflectionProbe` (`CONSTITUTION.md` §2.5). Every Lite claim was\n * read from `@babylonjs/lite@1.34.0`.\n *\n * - **Capture.** Lite has no cube capture, so six render tasks (`createRenderTask`, each with its own\n * `rgba16float` target and a `createBankedFreeCamera` looking down one axis, 90° field of view,\n * square target) are appended to the frame graph, switched on for the frames that capture, like\n * `./render-texture.ts`. Faces follow the cube-map convention in Lite's left-handed space: +X, −X\n * and ±Z faces use +Y as up, +Y uses −Z and −Y uses +Z.\n * - **Cube and mips.** In the next frame's `PreRender`, a small render pipeline of ignifx's own copies\n * each face into a cube texture, decoding gamma when `rendering.hdr` is off (the faces then hold\n * tone-mapped sRGB), and box-downsamples the mip chain. It is submitted before Lite's frame, so queue\n * order makes it read the frame that rendered the faces. Mips are not GGX-prefiltered.\n * - **Environment.** The cube is wrapped in an `EnvironmentTextures` (`index.d.ts` 5598) that shares\n * the scene environment's BRDF table and spherical harmonics, so diffuse light is unchanged.\n * - **Materials.** `setPbrLocalEnvironment` (box parallax) or `setPbrEnvironment` (no box) per lit PBR\n * material, then a material rebuild (`index.d.ts` 12612–12654). `enablePbrLocalCubemap` must have\n * resolved first; it is called when the chunk loads.\n * - **Culling mask.** Render tasks have no mesh filter, so each face task's `execute` hides the meshes\n * the caller rejects and shows them again, as `./render-texture.ts` does for editor-only meshes.\n */\n\n/** The colour format of the faces and the cube. */\nconst PROBE_FORMAT: GPUTextureFormat = \"rgba16float\";\n\n/** The depth/stencil format Lite's own render tasks use. */\nconst DEPTH_STENCIL_FORMAT: GPUTextureFormat = \"depth24plus-stencil8\";\n\n/** Each face's view direction and up vector, in cube-face order +X, −X, +Y, −Y, +Z, −Z. */\nconst FACES: readonly (readonly [number, number, number, number, number, number])[] = [\n [1, 0, 0, 0, 1, 0],\n [-1, 0, 0, 0, 1, 0],\n [0, 1, 0, 0, 0, -1],\n [0, -1, 0, 0, 0, 1],\n [0, 0, 1, 0, 1, 0],\n [0, 0, -1, 0, 1, 0],\n];\n\n/** A full-screen triangle that copies, decodes, or (through a linear sampler) box-downsamples. */\nconst BLIT_WGSL = /* wgsl */ `\nstruct VsOut { @builtin(position) position: vec4<f32>, @location(0) uv: vec2<f32> };\n@vertex fn vs(@builtin(vertex_index) index: u32) -> VsOut {\n let corner = vec2<f32>(f32((index << 1u) & 2u), f32(index & 2u));\n var out: VsOut;\n out.position = vec4<f32>(corner * 2.0 - 1.0, 0.0, 1.0);\n out.uv = vec2<f32>(corner.x, 1.0 - corner.y);\n return out;\n}\n@group(0) @binding(0) var source: texture_2d<f32>;\n@group(0) @binding(1) var sourceSampler: sampler;\n@fragment fn copy(in: VsOut) -> @location(0) vec4<f32> {\n return vec4<f32>(textureSampleLevel(source, sourceSampler, in.uv, 0.0).rgb, 1.0);\n}\n@fragment fn decode(in: VsOut) -> @location(0) vec4<f32> {\n let colour = textureSampleLevel(source, sourceSampler, in.uv, 0.0).rgb;\n return vec4<f32>(pow(max(colour, vec3<f32>(0.0)), vec3<f32>(2.2)), 1.0);\n}\n`;\n\n/** The blit pipelines of one device. */\ninterface BlitPipelines {\n readonly copy: GPURenderPipeline;\n readonly decode: GPURenderPipeline;\n readonly sampler: GPUSampler;\n}\n\n/** Each device's pipelines, the map created on first use (coding standards §4). */\nlet pipelineCache: WeakMap<GPUDevice, BlitPipelines> | null = null;\n\n/**\n * One probe's capture passes and cube map.\n *\n * @internal\n */\nexport interface LiteReflectionProbe {\n /** The cube face size in pixels. */\n readonly size: number;\n /** The environment materials reflect, `null` until the first capture resolved. Stable afterwards. */\n readonly environment: EnvironmentTextures | null;\n /**\n * Renders the six faces in the coming frame.\n *\n * @param x - The world X of the capture point.\n * @param y - The world Y.\n * @param z - The world Z.\n * @param near - The near clip distance.\n * @param far - The far clip distance.\n */\n capture(x: number, y: number, z: number, near: number, far: number): void;\n /**\n * Turns the faces the last frame rendered into the cube map, when a capture ran.\n *\n * @param decodeGamma - Whether the faces hold gamma-encoded colour (`rendering.hdr` off).\n * @returns `true` when {@link LiteReflectionProbe.environment} was created by this call.\n */\n resolve(decodeGamma: boolean): boolean;\n /** Removes the passes and frees the textures. Idempotent. */\n dispose(): void;\n}\n\n/**\n * Loads Lite's local-cubemap shader path. Resolve it before assigning any probe.\n *\n * @returns A promise that resolves once the path is registered.\n *\n * @internal\n */\nexport function enableReflectionProbes(): Promise<void> {\n return enablePbrLocalCubemap();\n}\n\n/**\n * Creates a probe's six face passes, switched off, at the end of the scene's frame graph.\n *\n * @param engine - The WebGPU engine.\n * @param scene - The registered render scene.\n * @param size - The face size in pixels, a power of two.\n * @param excludeKey - The `metadata` key that, set to `true` on a mesh, keeps it out of the faces.\n * @param accept - Whether a mesh's owner may be captured; `false` hides it during the faces.\n * @returns The probe.\n *\n * @internal\n */\nexport function createLiteReflectionProbe(\n engine: EngineContext,\n scene: SceneContext,\n size: number,\n excludeKey: string,\n accept: (tag: NodeTag | null) => boolean,\n): LiteReflectionProbe {\n const targets: RenderTarget[] = [];\n const tasks: RenderTask[] = [];\n const cameras: BankedFreeCamera[] = [];\n const hidden: Mesh[] = [];\n for (const face of FACES) {\n const target = createRenderTarget({\n lbl: \"ignifx:reflection-probe-face\",\n format: PROBE_FORMAT,\n dFormat: DEPTH_STENCIL_FORMAT,\n samples: 1,\n size: { width: size, height: size },\n });\n const camera = createBankedFreeCamera(\n { x: 0, y: 0, z: 0 },\n { x: face[0], y: face[1], z: face[2] },\n {\n x: face[3],\n y: face[4],\n z: face[5],\n },\n );\n camera.fov = Math.PI / 2;\n const task = createRenderTask({ name: \"ignifx:reflection-probe\", rt: target, cam: camera }, engine, scene);\n task.executionEnabled = false;\n const execute = task.execute?.bind(task);\n if (execute === undefined) {\n throw new TypeError(\"Lite's render task has no execute(); reflection-probe.ts needs updating for this Lite.\");\n }\n task.execute = (): number => {\n for (const mesh of scene.meshes) {\n if (mesh.visible !== false && (mesh.metadata?.[excludeKey] === true || !accept(readOwnerTag(mesh)))) {\n mesh.visible = false;\n hidden.push(mesh);\n }\n }\n try {\n return execute();\n } finally {\n for (const mesh of hidden) {\n mesh.visible = true;\n }\n hidden.length = 0;\n }\n };\n addTask(scene, task);\n buildFrameGraphTask(getFrameGraph(scene), task);\n targets.push(target);\n tasks.push(task);\n cameras.push(camera);\n }\n let cube: GPUTexture | null = null;\n let environment: EnvironmentTextures | null = null;\n let isCapturing = false;\n let isDisposed = false;\n return {\n size,\n get environment(): EnvironmentTextures | null {\n return environment;\n },\n capture(x: number, y: number, z: number, near: number, far: number): void {\n if (isDisposed) {\n return;\n }\n for (let index = 0; index < FACES.length; index += 1) {\n const face = FACES[index];\n const camera = cameras[index];\n const task = tasks[index];\n if (face === undefined || camera === undefined || task === undefined) {\n continue;\n }\n camera.position.set(x, y, z);\n camera.target.set(x + face[0], y + face[1], z + face[2]);\n camera.nearPlane = near;\n camera.farPlane = far;\n task.executionEnabled = true;\n }\n isCapturing = true;\n },\n resolve(decodeGamma: boolean): boolean {\n if (isDisposed || !isCapturing) {\n return false;\n }\n isCapturing = false;\n for (const task of tasks) {\n task.executionEnabled = false;\n }\n const device = deviceOf(engine);\n const base = readSceneEnvironment(scene);\n if (device === null || base === null) {\n return false;\n }\n cube ??= device.createTexture({\n label: \"ignifx:reflection-probe\",\n size: [size, size, FACES.length],\n format: PROBE_FORMAT,\n mipLevelCount: Math.log2(size) + 1,\n usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,\n });\n if (!blitFaces(device, cube, targets, decodeGamma)) {\n return false;\n }\n if (environment !== null) {\n return false;\n }\n environment = {\n specularCube: cube,\n specularCubeView: cube.createView({ dimension: \"cube\" }),\n brdfLut: base.brdfLut,\n brdfLutView: base.brdfLutView,\n cubeSampler: base.cubeSampler,\n brdfSampler: base.brdfSampler,\n irradianceSH: base.irradianceSH,\n sphericalHarmonics: base.sphericalHarmonics,\n lodGenerationScale: base.lodGenerationScale,\n lodGenerationOffset: base.lodGenerationOffset ?? 0,\n };\n return true;\n },\n dispose(): void {\n if (isDisposed) {\n return;\n }\n isDisposed = true;\n for (const task of tasks) {\n task.executionEnabled = false;\n removeTask(scene, task);\n task.dispose();\n }\n // Materials still bound to the cube are reassigned by the caller before the next frame; the\n // cube itself is left for the garbage collector, since a bind group in flight may name it.\n cube = null;\n environment = null;\n },\n };\n}\n\n/**\n * Copies the six face targets into the cube's first mip and box-downsamples the rest.\n *\n * @param device - The device.\n * @param cube - The cube texture, six layers.\n * @param targets - The face targets, in cube-face order.\n * @param decodeGamma - Whether to decode gamma on the copy.\n * @returns `false` when a face target has no texture yet.\n */\nfunction blitFaces(\n device: GPUDevice,\n cube: GPUTexture,\n targets: readonly RenderTarget[],\n decodeGamma: boolean,\n): boolean {\n const pipelines = blitPipelines(device);\n const encoder = device.createCommandEncoder({ label: \"ignifx:reflection-probe-mips\" });\n for (let face = 0; face < targets.length; face += 1) {\n const target = targets[face];\n const source = target === undefined ? null : colorTextureOf(target);\n if (source === null) {\n return false;\n }\n draw(\n device,\n encoder,\n decodeGamma ? pipelines.decode : pipelines.copy,\n pipelines.sampler,\n source.createView(),\n cubeFace(cube, face, 0),\n );\n for (let mip = 1; mip < cube.mipLevelCount; mip += 1) {\n draw(\n device,\n encoder,\n pipelines.copy,\n pipelines.sampler,\n cubeFace(cube, face, mip - 1),\n cubeFace(cube, face, mip),\n );\n }\n }\n device.queue.submit([encoder.finish()]);\n return true;\n}\n\n/**\n * A 2D view of one face and mip of the cube.\n *\n * @param cube - The cube texture.\n * @param face - The layer.\n * @param mip - The mip level.\n * @returns The view.\n */\nfunction cubeFace(cube: GPUTexture, face: number, mip: number): GPUTextureView {\n return cube.createView({\n dimension: \"2d\",\n baseArrayLayer: face,\n arrayLayerCount: 1,\n baseMipLevel: mip,\n mipLevelCount: 1,\n });\n}\n\n/**\n * Encodes one full-screen blit.\n *\n * @param device - The device.\n * @param encoder - The encoder.\n * @param pipeline - The pipeline.\n * @param sampler - The linear sampler.\n * @param source - The view to read.\n * @param destination - The view to write.\n */\nfunction draw(\n device: GPUDevice,\n encoder: GPUCommandEncoder,\n pipeline: GPURenderPipeline,\n sampler: GPUSampler,\n source: GPUTextureView,\n destination: GPUTextureView,\n): void {\n const bindGroup = device.createBindGroup({\n layout: pipeline.getBindGroupLayout(0),\n entries: [\n { binding: 0, resource: source },\n { binding: 1, resource: sampler },\n ],\n });\n const pass = encoder.beginRenderPass({\n colorAttachments: [\n { view: destination, loadOp: \"clear\", storeOp: \"store\", clearValue: { r: 0, g: 0, b: 0, a: 1 } },\n ],\n });\n pass.setPipeline(pipeline);\n pass.setBindGroup(0, bindGroup);\n pass.draw(3);\n pass.end();\n}\n\n/**\n * The device's blit pipelines.\n *\n * @param device - The device.\n * @returns The pipelines, created on first use.\n */\nfunction blitPipelines(device: GPUDevice): BlitPipelines {\n pipelineCache ??= new WeakMap();\n const cached = pipelineCache.get(device);\n if (cached !== undefined) {\n return cached;\n }\n const module = device.createShaderModule({ label: \"ignifx:reflection-probe-blit\", code: BLIT_WGSL });\n const pipeline = (entryPoint: string): GPURenderPipeline =>\n device.createRenderPipeline({\n label: `ignifx:reflection-probe-${entryPoint}`,\n layout: \"auto\",\n vertex: { module, entryPoint: \"vs\" },\n fragment: { module, entryPoint, targets: [{ format: PROBE_FORMAT }] },\n primitive: { topology: \"triangle-list\" },\n });\n const created: BlitPipelines = {\n copy: pipeline(\"copy\"),\n decode: pipeline(\"decode\"),\n sampler: device.createSampler({ magFilter: \"linear\", minFilter: \"linear\" }),\n };\n pipelineCache.set(device, created);\n return created;\n}\n\n/**\n * What a material reflects: a probe's environment, where it sits, and its projection box.\n *\n * @internal\n */\nexport interface LiteProbeBinding {\n /** The probe's environment. */\n readonly environment: EnvironmentTextures;\n /** The capture position. */\n readonly position: readonly [number, number, number];\n /** The full size of the projection box, or `null` for none. */\n readonly box: readonly [number, number, number] | null;\n}\n\n/**\n * Calls `visit` for every mesh whose material is a lit, non-skybox PBR material.\n *\n * @param scene - The scene.\n * @param visit - Receives the material and the mesh's world position.\n *\n * @internal\n */\nexport function forEachReflectiveMesh(\n scene: SceneContext,\n visit: (material: PbrMaterialProps, x: number, y: number, z: number) => void,\n): void {\n const meshes = scene.meshes;\n for (let index = 0; index < meshes.length; index += 1) {\n const mesh = meshes[index];\n const material = mesh?.material;\n // Declared non-null, but Lite's mesh factories create meshes with `material: null`.\n // oxlint-disable-next-line typescript/no-unnecessary-condition\n if (mesh === undefined || material === undefined || material === null || !isPbrMaterial(material)) {\n continue;\n }\n if (getPbrUnlit(material) !== undefined || isPbrSkybox(material)) {\n continue;\n }\n const world = mesh.worldMatrix;\n visit(material, world[12] ?? 0, world[13] ?? 0, world[14] ?? 0);\n }\n}\n\n/**\n * Points a PBR material at a probe, or back at the scene environment, and rebuilds it.\n *\n * @param scene - The registered scene.\n * @param material - The material.\n * @param binding - The probe, or `null` for the scene environment.\n *\n * @internal\n */\nexport function assignReflectionProbe(\n scene: SceneContext,\n material: PbrMaterialProps,\n binding: LiteProbeBinding | null,\n): void {\n if (binding === null) {\n clearPbrLocalEnvironment(material);\n } else if (binding.box === null) {\n setPbrEnvironment(material, binding.environment);\n } else {\n setPbrLocalEnvironment(material, binding.environment, {\n shape: \"box\",\n capturePosition: binding.position,\n projectionPosition: binding.position,\n projectionSize: binding.box,\n });\n }\n rebuildMaterialPipelines(scene, material);\n}\n","import { toEntityHandle } from \"../../handles/handle.js\";\nimport {\n assignReflectionProbe,\n createLiteReflectionProbe,\n enableReflectionProbes,\n forEachReflectiveMesh,\n} from \"../../lite/gpu/reflection-probe.js\";\nimport { resolveReflectionProbeSize, selectReflectionProbe } from \"../reflection-probe.js\";\nimport { EDITOR_ONLY_METADATA_KEY } from \"../render-texture.js\";\nimport type { LiteProbeBinding, LiteReflectionProbe } from \"../../lite/gpu/reflection-probe.js\";\nimport type { NodeTag } from \"../../lite/node.js\";\nimport type { LiteEngine, LiteScene } from \"../../lite/scene.js\";\nimport type { Vec3Like } from \"../../math/types.js\";\nimport type { World } from \"../../world/world.js\";\nimport type { ReflectionProbe, ReflectionProbeCandidate } from \"../reflection-probe.js\";\n\n/**\n * The render layer's half of reflection probes (`docs/plan/2026-11-gi-phase-2-execution-plan.md`,\n * step B1): which probe captures when, and which probe each PBR material reflects. Loaded with\n * `../../lite/gpu/reflection-probe.ts` as one chunk, only once a world has a `ReflectionProbe`.\n */\n\n/**\n * How many consecutive frames one capture request renders. Lite compiles material pipelines\n * asynchronously, so a single frame right after start or after a scene change can miss meshes that\n * are still compiling; repeating it for a few frames catches them.\n */\nconst CAPTURE_FRAMES = 8;\n\n/** One component's GPU probe and what it last captured with. */\ninterface ProbeState {\n /** The GPU probe. */\n lite: LiteReflectionProbe;\n /** How many more frames capture before the probe rests. */\n framesToCapture: number;\n /** The binding materials use, rebuilt when the probe moves or its box changes. */\n binding: LiteProbeBinding | null;\n}\n\n/** A material `forEachReflectiveMesh` hands out. */\ntype ReflectiveMaterial = Parameters<typeof assignReflectionProbe>[1];\n\n/** A candidate with the binding it stands for. */\ninterface BoundCandidate extends ReflectionProbeCandidate {\n /** The binding. */\n readonly binding: LiteProbeBinding;\n}\n\n/**\n * Every reflection probe of a renderer.\n *\n * @internal\n */\nexport interface ReflectionProbeRuntime {\n /**\n * Captures what is due and points each lit PBR material at its probe. Called once per frame from\n * the `PreRender` system.\n *\n * @param world - The world the probes live in.\n * @param probes - Every `ReflectionProbe` in the world.\n * @param isHdr - Whether `rendering.hdr` is on.\n */\n update(world: World, probes: readonly ReflectionProbe[], isHdr: boolean): void;\n /** Frees every probe and hands every material back to the scene environment. */\n dispose(): void;\n}\n\n/**\n * Creates the runtime once Lite's local-cubemap shader path is loaded.\n *\n * @param engine - The engine.\n * @param scene - The registered render scene.\n * @returns The runtime.\n *\n * @internal\n */\nexport async function createReflectionProbeRuntime(\n engine: LiteEngine,\n scene: LiteScene,\n): Promise<ReflectionProbeRuntime> {\n await enableReflectionProbes();\n const states = new Map<ReflectionProbe, ProbeState>();\n const assigned = new Map<ReflectiveMaterial, LiteProbeBinding | null>();\n const seen = new Set<object>();\n const candidates: BoundCandidate[] = [];\n\n const release = (probe: ReflectionProbe, state: ProbeState): void => {\n state.lite.dispose();\n states.delete(probe);\n };\n\n const assignMaterials = (): void => {\n seen.clear();\n forEachReflectiveMesh(scene, (material, x, y, z) => {\n if (seen.has(material)) {\n return;\n }\n seen.add(material);\n const index = selectReflectionProbe(x, y, z, candidates);\n const binding = candidates[index]?.binding ?? null;\n const current = assigned.get(material);\n if (current === binding || (current === undefined && binding === null)) {\n return;\n }\n assigned.set(material, binding);\n assignReflectionProbe(scene, material, binding);\n });\n };\n\n return {\n update(world: World, probes: readonly ReflectionProbe[], isHdr: boolean): void {\n for (const [probe, state] of states) {\n if (!probes.includes(probe) || resolveReflectionProbeSize(probe.size) !== state.lite.size) {\n release(probe, state);\n }\n }\n candidates.length = 0;\n for (const probe of probes) {\n const wantsRefresh = probe.consumeRefreshRequest();\n if (!probe.isEnabledInHierarchy) {\n continue;\n }\n let state = states.get(probe);\n if (state === undefined) {\n state = {\n lite: createLiteReflectionProbe(\n engine,\n scene,\n resolveReflectionProbeSize(probe.size),\n EDITOR_ONLY_METADATA_KEY,\n cullingFilter(world, probe),\n ),\n framesToCapture: probe.refreshMode === \"once\" ? CAPTURE_FRAMES : 0,\n binding: null,\n };\n states.set(probe, state);\n }\n state.lite.resolve(!isHdr);\n const matrix = probe.entity.transform.worldMatrix;\n const x = matrix[12] ?? 0;\n const y = matrix[13] ?? 0;\n const z = matrix[14] ?? 0;\n if (wantsRefresh) {\n state.framesToCapture = CAPTURE_FRAMES;\n }\n if (state.framesToCapture > 0 || probe.refreshMode === \"everyFrame\") {\n state.lite.capture(x, y, z, probe.near, probe.far);\n state.framesToCapture = Math.max(0, state.framesToCapture - 1);\n }\n const environment = state.lite.environment;\n if (environment === null) {\n continue;\n }\n const box = probe.boxProjection;\n const binding = bindingFor(state.binding, environment, x, y, z, box);\n state.binding = binding;\n candidates.push({ x, y, z, box, binding });\n }\n assignMaterials();\n },\n dispose(): void {\n for (const [probe, state] of states) {\n release(probe, state);\n }\n for (const [material, binding] of assigned) {\n if (binding !== null) {\n assignReflectionProbe(scene, material, null);\n }\n }\n assigned.clear();\n },\n };\n}\n\n/**\n * Builds the mesh filter of a probe's capture: with a non-empty `cullingMask`, only meshes whose\n * entity is on one of its layers.\n *\n * @param world - The world, for the handle and layer tables.\n * @param probe - The probe; its mask is read on every call, so edits apply to the next capture.\n * @returns The filter.\n */\nfunction cullingFilter(world: World, probe: ReflectionProbe): (tag: NodeTag | null) => boolean {\n return (tag): boolean => {\n const mask = probe.cullingMask;\n if (mask.length === 0) {\n return true;\n }\n const entity = tag === null ? null : world.getEntityByHandle(toEntityHandle(tag.entity));\n if (entity === null) {\n return false;\n }\n for (const name of mask) {\n if (world.layers.indexOf(name) === entity.layer) {\n return true;\n }\n }\n return false;\n };\n}\n\n/**\n * The binding a probe's materials use: the previous one while nothing it holds changed, so a still\n * probe never rebuilds its materials.\n *\n * @param previous - The binding last used, or `null`.\n * @param environment - The probe's environment.\n * @param x - The probe's world X.\n * @param y - The probe's world Y.\n * @param z - The probe's world Z.\n * @param box - The projection box size, or `null`.\n * @returns The binding.\n */\nfunction bindingFor(\n previous: LiteProbeBinding | null,\n environment: LiteProbeBinding[\"environment\"],\n x: number,\n y: number,\n z: number,\n box: Vec3Like | null,\n): LiteProbeBinding {\n if (\n previous !== null &&\n previous.environment === environment &&\n previous.position[0] === x &&\n previous.position[1] === y &&\n previous.position[2] === z &&\n (box === null\n ? previous.box === null\n : previous.box !== null && previous.box[0] === box.x && previous.box[1] === box.y && previous.box[2] === box.z)\n ) {\n return previous;\n }\n return { environ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AAS,QAAQ,OACjB,SAAS,QAAQ,QAAQ,SAAS,IAAI,OAAO,IAAI,KAAK,SAAS,IAAI,OAAO,IAAI,KAAK,SAAS,IAAI,OAAO,IAAI,IAE/G,OAAO;CAET,OAAO;EAAE;EAAa,UAAU;GAAC;GAAG;GAAG;EAAC;EAAG,KAAK,QAAQ,OAAO,OAAO;GAAC,IAAI;GAAG,IAAI;GAAG,IAAI;EAAC;CAAE;AAC9F"}
1
+ {"version":3,"file":"reflection-probes-B8S9WnVX.js","names":[],"sources":["../src/lite/gpu/reflection-probe.ts","../src/render/gpu/reflection-probes.ts"],"sourcesContent":["import {\n addTask,\n buildFrameGraphTask,\n clearPbrLocalEnvironment,\n createBankedFreeCamera,\n createRenderTarget,\n createRenderTask,\n enablePbrLocalCubemap,\n getFrameGraph,\n getPbrUnlit,\n isPbrMaterial,\n isPbrSkybox,\n setPbrEnvironment,\n setPbrLocalEnvironment,\n} from \"@babylonjs/lite\";\nimport { rebuildMaterialPipelines } from \"../material.js\";\nimport { readOwnerTag } from \"../picking.js\";\nimport { readSceneEnvironment } from \"./environment.js\";\nimport { colorTextureOf, deviceOf, removeTask } from \"./render-texture.js\";\nimport type { NodeTag } from \"../node.js\";\nimport type {\n BankedFreeCamera,\n EngineContext,\n EnvironmentTextures,\n Mesh,\n PbrMaterialProps,\n RenderTarget,\n RenderTask,\n SceneContext,\n} from \"@babylonjs/lite\";\n\n/**\n * Reflection probes (`docs/plan/2026-11-gi-phase-2-execution-plan.md`, step B1). Its own chunk,\n * loaded only when a world has a `ReflectionProbe` (`CONSTITUTION.md` §2.5). Every Lite claim was\n * read from `@babylonjs/lite@1.34.0`.\n *\n * - **Capture.** Lite has no cube capture, so six render tasks (`createRenderTask`, each with its own\n * `rgba16float` target and a `createBankedFreeCamera` looking down one axis, 90° field of view,\n * square target) are appended to the frame graph, switched on for the frames that capture, like\n * `./render-texture.ts`. Faces follow the cube-map convention in Lite's left-handed space: +X, −X\n * and ±Z faces use +Y as up, +Y uses −Z and −Y uses +Z.\n * - **Cube and mips.** In the next frame's `PreRender`, a small render pipeline of ignifx's own copies\n * each face into a cube texture, decoding gamma when `rendering.hdr` is off (the faces then hold\n * tone-mapped sRGB), and box-downsamples the mip chain. It is submitted before Lite's frame, so queue\n * order makes it read the frame that rendered the faces. Mips are not GGX-prefiltered.\n * - **Environment.** The cube is wrapped in an `EnvironmentTextures` (`index.d.ts` 5598) that shares\n * the scene environment's BRDF table and spherical harmonics, so diffuse light is unchanged.\n * - **Materials.** `setPbrLocalEnvironment` (box parallax) or `setPbrEnvironment` (no box) per lit PBR\n * material, then a material rebuild (`index.d.ts` 12612–12654). `enablePbrLocalCubemap` must have\n * resolved first; it is called when the chunk loads.\n * - **Culling mask.** Render tasks have no mesh filter, so each face task's `execute` hides the meshes\n * the caller rejects and shows them again, as `./render-texture.ts` does for editor-only meshes.\n */\n\n/** The colour format of the faces and the cube. */\nconst PROBE_FORMAT: GPUTextureFormat = \"rgba16float\";\n\n/** The depth/stencil format Lite's own render tasks use. */\nconst DEPTH_STENCIL_FORMAT: GPUTextureFormat = \"depth24plus-stencil8\";\n\n/** Each face's view direction and up vector, in cube-face order +X, −X, +Y, −Y, +Z, −Z. */\nconst FACES: readonly (readonly [number, number, number, number, number, number])[] = [\n [1, 0, 0, 0, 1, 0],\n [-1, 0, 0, 0, 1, 0],\n [0, 1, 0, 0, 0, -1],\n [0, -1, 0, 0, 0, 1],\n [0, 0, 1, 0, 1, 0],\n [0, 0, -1, 0, 1, 0],\n];\n\n/** A full-screen triangle that copies, decodes, or (through a linear sampler) box-downsamples. */\nconst BLIT_WGSL = /* wgsl */ `\nstruct VsOut { @builtin(position) position: vec4<f32>, @location(0) uv: vec2<f32> };\n@vertex fn vs(@builtin(vertex_index) index: u32) -> VsOut {\n let corner = vec2<f32>(f32((index << 1u) & 2u), f32(index & 2u));\n var out: VsOut;\n out.position = vec4<f32>(corner * 2.0 - 1.0, 0.0, 1.0);\n out.uv = vec2<f32>(corner.x, 1.0 - corner.y);\n return out;\n}\n@group(0) @binding(0) var source: texture_2d<f32>;\n@group(0) @binding(1) var sourceSampler: sampler;\n@fragment fn copy(in: VsOut) -> @location(0) vec4<f32> {\n return vec4<f32>(textureSampleLevel(source, sourceSampler, in.uv, 0.0).rgb, 1.0);\n}\n@fragment fn decode(in: VsOut) -> @location(0) vec4<f32> {\n let colour = textureSampleLevel(source, sourceSampler, in.uv, 0.0).rgb;\n return vec4<f32>(pow(max(colour, vec3<f32>(0.0)), vec3<f32>(2.2)), 1.0);\n}\n`;\n\n/** The blit pipelines of one device. */\ninterface BlitPipelines {\n readonly copy: GPURenderPipeline;\n readonly decode: GPURenderPipeline;\n readonly sampler: GPUSampler;\n}\n\n/** Each device's pipelines, the map created on first use (coding standards §4). */\nlet pipelineCache: WeakMap<GPUDevice, BlitPipelines> | null = null;\n\n/**\n * One probe's capture passes and cube map.\n *\n * @internal\n */\nexport interface LiteReflectionProbe {\n /** The cube face size in pixels. */\n readonly size: number;\n /** The environment materials reflect, `null` until the first capture resolved. Stable afterwards. */\n readonly environment: EnvironmentTextures | null;\n /**\n * Renders the six faces in the coming frame.\n *\n * @param x - The world X of the capture point.\n * @param y - The world Y.\n * @param z - The world Z.\n * @param near - The near clip distance.\n * @param far - The far clip distance.\n */\n capture(x: number, y: number, z: number, near: number, far: number): void;\n /**\n * Turns the faces the last frame rendered into the cube map, when a capture ran.\n *\n * @param decodeGamma - Whether the faces hold gamma-encoded colour (`rendering.hdr` off).\n * @returns `true` when {@link LiteReflectionProbe.environment} was created by this call.\n */\n resolve(decodeGamma: boolean): boolean;\n /** Removes the passes and frees the textures. Idempotent. */\n dispose(): void;\n}\n\n/**\n * Loads Lite's local-cubemap shader path. Resolve it before assigning any probe.\n *\n * @returns A promise that resolves once the path is registered.\n *\n * @internal\n */\nexport function enableReflectionProbes(): Promise<void> {\n return enablePbrLocalCubemap();\n}\n\n/**\n * Creates a probe's six face passes, switched off, at the end of the scene's frame graph.\n *\n * @param engine - The WebGPU engine.\n * @param scene - The registered render scene.\n * @param size - The face size in pixels, a power of two.\n * @param excludeKey - The `metadata` key that, set to `true` on a mesh, keeps it out of the faces.\n * @param accept - Whether a mesh's owner may be captured; `false` hides it during the faces.\n * @returns The probe.\n *\n * @internal\n */\nexport function createLiteReflectionProbe(\n engine: EngineContext,\n scene: SceneContext,\n size: number,\n excludeKey: string,\n accept: (tag: NodeTag | null) => boolean,\n): LiteReflectionProbe {\n const targets: RenderTarget[] = [];\n const tasks: RenderTask[] = [];\n const cameras: BankedFreeCamera[] = [];\n const hidden: Mesh[] = [];\n for (const face of FACES) {\n const target = createRenderTarget({\n lbl: \"ignifx:reflection-probe-face\",\n format: PROBE_FORMAT,\n dFormat: DEPTH_STENCIL_FORMAT,\n samples: 1,\n size: { width: size, height: size },\n });\n const camera = createBankedFreeCamera(\n { x: 0, y: 0, z: 0 },\n { x: face[0], y: face[1], z: face[2] },\n {\n x: face[3],\n y: face[4],\n z: face[5],\n },\n );\n camera.fov = Math.PI / 2;\n const task = createRenderTask({ name: \"ignifx:reflection-probe\", rt: target, cam: camera }, engine, scene);\n task.executionEnabled = false;\n const execute = task.execute?.bind(task);\n if (execute === undefined) {\n throw new TypeError(\"Lite's render task has no execute(); reflection-probe.ts needs updating for this Lite.\");\n }\n task.execute = (): number => {\n for (const mesh of scene.meshes) {\n if (mesh.visible !== false && (mesh.metadata?.[excludeKey] === true || !accept(readOwnerTag(mesh)))) {\n mesh.visible = false;\n hidden.push(mesh);\n }\n }\n try {\n return execute();\n } finally {\n for (const mesh of hidden) {\n mesh.visible = true;\n }\n hidden.length = 0;\n }\n };\n addTask(scene, task);\n buildFrameGraphTask(getFrameGraph(scene), task);\n targets.push(target);\n tasks.push(task);\n cameras.push(camera);\n }\n let cube: GPUTexture | null = null;\n let environment: EnvironmentTextures | null = null;\n let isCapturing = false;\n let isDisposed = false;\n return {\n size,\n get environment(): EnvironmentTextures | null {\n return environment;\n },\n capture(x: number, y: number, z: number, near: number, far: number): void {\n if (isDisposed) {\n return;\n }\n for (let index = 0; index < FACES.length; index += 1) {\n const face = FACES[index];\n const camera = cameras[index];\n const task = tasks[index];\n if (face === undefined || camera === undefined || task === undefined) {\n continue;\n }\n camera.position.set(x, y, z);\n camera.target.set(x + face[0], y + face[1], z + face[2]);\n camera.nearPlane = near;\n camera.farPlane = far;\n task.executionEnabled = true;\n }\n isCapturing = true;\n },\n resolve(decodeGamma: boolean): boolean {\n if (isDisposed || !isCapturing) {\n return false;\n }\n isCapturing = false;\n for (const task of tasks) {\n task.executionEnabled = false;\n }\n const device = deviceOf(engine);\n const base = readSceneEnvironment(scene);\n if (device === null || base === null) {\n return false;\n }\n cube ??= device.createTexture({\n label: \"ignifx:reflection-probe\",\n size: [size, size, FACES.length],\n format: PROBE_FORMAT,\n mipLevelCount: Math.log2(size) + 1,\n usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,\n });\n if (!blitFaces(device, cube, targets, decodeGamma)) {\n return false;\n }\n if (environment !== null) {\n return false;\n }\n environment = {\n specularCube: cube,\n specularCubeView: cube.createView({ dimension: \"cube\" }),\n brdfLut: base.brdfLut,\n brdfLutView: base.brdfLutView,\n cubeSampler: base.cubeSampler,\n brdfSampler: base.brdfSampler,\n irradianceSH: base.irradianceSH,\n sphericalHarmonics: base.sphericalHarmonics,\n lodGenerationScale: base.lodGenerationScale,\n lodGenerationOffset: base.lodGenerationOffset ?? 0,\n };\n return true;\n },\n dispose(): void {\n if (isDisposed) {\n return;\n }\n isDisposed = true;\n for (const task of tasks) {\n task.executionEnabled = false;\n removeTask(scene, task);\n task.dispose();\n }\n // Materials still bound to the cube are reassigned by the caller before the next frame; the\n // cube itself is left for the garbage collector, since a bind group in flight may name it.\n cube = null;\n environment = null;\n },\n };\n}\n\n/**\n * Copies the six face targets into the cube's first mip and box-downsamples the rest.\n *\n * @param device - The device.\n * @param cube - The cube texture, six layers.\n * @param targets - The face targets, in cube-face order.\n * @param decodeGamma - Whether to decode gamma on the copy.\n * @returns `false` when a face target has no texture yet.\n */\nfunction blitFaces(\n device: GPUDevice,\n cube: GPUTexture,\n targets: readonly RenderTarget[],\n decodeGamma: boolean,\n): boolean {\n const pipelines = blitPipelines(device);\n const encoder = device.createCommandEncoder({ label: \"ignifx:reflection-probe-mips\" });\n for (let face = 0; face < targets.length; face += 1) {\n const target = targets[face];\n const source = target === undefined ? null : colorTextureOf(target);\n if (source === null) {\n return false;\n }\n draw(\n device,\n encoder,\n decodeGamma ? pipelines.decode : pipelines.copy,\n pipelines.sampler,\n source.createView(),\n cubeFace(cube, face, 0),\n );\n for (let mip = 1; mip < cube.mipLevelCount; mip += 1) {\n draw(\n device,\n encoder,\n pipelines.copy,\n pipelines.sampler,\n cubeFace(cube, face, mip - 1),\n cubeFace(cube, face, mip),\n );\n }\n }\n device.queue.submit([encoder.finish()]);\n return true;\n}\n\n/**\n * A 2D view of one face and mip of the cube.\n *\n * @param cube - The cube texture.\n * @param face - The layer.\n * @param mip - The mip level.\n * @returns The view.\n */\nfunction cubeFace(cube: GPUTexture, face: number, mip: number): GPUTextureView {\n return cube.createView({\n dimension: \"2d\",\n baseArrayLayer: face,\n arrayLayerCount: 1,\n baseMipLevel: mip,\n mipLevelCount: 1,\n });\n}\n\n/**\n * Encodes one full-screen blit.\n *\n * @param device - The device.\n * @param encoder - The encoder.\n * @param pipeline - The pipeline.\n * @param sampler - The linear sampler.\n * @param source - The view to read.\n * @param destination - The view to write.\n */\nfunction draw(\n device: GPUDevice,\n encoder: GPUCommandEncoder,\n pipeline: GPURenderPipeline,\n sampler: GPUSampler,\n source: GPUTextureView,\n destination: GPUTextureView,\n): void {\n const bindGroup = device.createBindGroup({\n layout: pipeline.getBindGroupLayout(0),\n entries: [\n { binding: 0, resource: source },\n { binding: 1, resource: sampler },\n ],\n });\n const pass = encoder.beginRenderPass({\n colorAttachments: [\n { view: destination, loadOp: \"clear\", storeOp: \"store\", clearValue: { r: 0, g: 0, b: 0, a: 1 } },\n ],\n });\n pass.setPipeline(pipeline);\n pass.setBindGroup(0, bindGroup);\n pass.draw(3);\n pass.end();\n}\n\n/**\n * The device's blit pipelines.\n *\n * @param device - The device.\n * @returns The pipelines, created on first use.\n */\nfunction blitPipelines(device: GPUDevice): BlitPipelines {\n pipelineCache ??= new WeakMap();\n const cached = pipelineCache.get(device);\n if (cached !== undefined) {\n return cached;\n }\n const module = device.createShaderModule({ label: \"ignifx:reflection-probe-blit\", code: BLIT_WGSL });\n const pipeline = (entryPoint: string): GPURenderPipeline =>\n device.createRenderPipeline({\n label: `ignifx:reflection-probe-${entryPoint}`,\n layout: \"auto\",\n vertex: { module, entryPoint: \"vs\" },\n fragment: { module, entryPoint, targets: [{ format: PROBE_FORMAT }] },\n primitive: { topology: \"triangle-list\" },\n });\n const created: BlitPipelines = {\n copy: pipeline(\"copy\"),\n decode: pipeline(\"decode\"),\n sampler: device.createSampler({ magFilter: \"linear\", minFilter: \"linear\" }),\n };\n pipelineCache.set(device, created);\n return created;\n}\n\n/**\n * What a material reflects: a probe's environment, where it sits, and its projection box.\n *\n * @internal\n */\nexport interface LiteProbeBinding {\n /** The probe's environment. */\n readonly environment: EnvironmentTextures;\n /** The capture position. */\n readonly position: readonly [number, number, number];\n /** The full size of the projection box, or `null` for none. */\n readonly box: readonly [number, number, number] | null;\n}\n\n/**\n * Calls `visit` for every mesh whose material is a lit, non-skybox PBR material.\n *\n * @param scene - The scene.\n * @param visit - Receives the material and the mesh's world position.\n *\n * @internal\n */\nexport function forEachReflectiveMesh(\n scene: SceneContext,\n visit: (material: PbrMaterialProps, x: number, y: number, z: number) => void,\n): void {\n const meshes = scene.meshes;\n for (let index = 0; index < meshes.length; index += 1) {\n const mesh = meshes[index];\n const material = mesh?.material;\n // Declared non-null, but Lite's mesh factories create meshes with `material: null`.\n // oxlint-disable-next-line typescript/no-unnecessary-condition\n if (mesh === undefined || material === undefined || material === null || !isPbrMaterial(material)) {\n continue;\n }\n if (getPbrUnlit(material) !== undefined || isPbrSkybox(material)) {\n continue;\n }\n const world = mesh.worldMatrix;\n visit(material, world[12] ?? 0, world[13] ?? 0, world[14] ?? 0);\n }\n}\n\n/**\n * Points a PBR material at a probe, or back at the scene environment, and rebuilds it.\n *\n * @param scene - The registered scene.\n * @param material - The material.\n * @param binding - The probe, or `null` for the scene environment.\n *\n * @internal\n */\nexport function assignReflectionProbe(\n scene: SceneContext,\n material: PbrMaterialProps,\n binding: LiteProbeBinding | null,\n): void {\n if (binding === null) {\n clearPbrLocalEnvironment(material);\n } else if (binding.box === null) {\n setPbrEnvironment(material, binding.environment);\n } else {\n setPbrLocalEnvironment(material, binding.environment, {\n shape: \"box\",\n capturePosition: binding.position,\n projectionPosition: binding.position,\n projectionSize: binding.box,\n });\n }\n rebuildMaterialPipelines(scene, material);\n}\n","import { toEntityHandle } from \"../../handles/handle.js\";\nimport {\n assignReflectionProbe,\n createLiteReflectionProbe,\n enableReflectionProbes,\n forEachReflectiveMesh,\n} from \"../../lite/gpu/reflection-probe.js\";\nimport { resolveReflectionProbeSize, selectReflectionProbe } from \"../reflection-probe.js\";\nimport { EDITOR_ONLY_METADATA_KEY } from \"../render-texture.js\";\nimport type { LiteProbeBinding, LiteReflectionProbe } from \"../../lite/gpu/reflection-probe.js\";\nimport type { NodeTag } from \"../../lite/node.js\";\nimport type { LiteEngine, LiteScene } from \"../../lite/scene.js\";\nimport type { Vec3Like } from \"../../math/types.js\";\nimport type { World } from \"../../world/world.js\";\nimport type { ReflectionProbe, ReflectionProbeCandidate } from \"../reflection-probe.js\";\n\n/**\n * The render layer's half of reflection probes (`docs/plan/2026-11-gi-phase-2-execution-plan.md`,\n * step B1): which probe captures when, and which probe each PBR material reflects. Loaded with\n * `../../lite/gpu/reflection-probe.ts` as one chunk, only once a world has a `ReflectionProbe`.\n */\n\n/**\n * How many consecutive frames one capture request renders. Lite compiles material pipelines\n * asynchronously, so a single frame right after start or after a scene change can miss meshes that\n * are still compiling; repeating it for a few frames catches them.\n */\nconst CAPTURE_FRAMES = 8;\n\n/** One component's GPU probe and what it last captured with. */\ninterface ProbeState {\n /** The GPU probe. */\n lite: LiteReflectionProbe;\n /** How many more frames capture before the probe rests. */\n framesToCapture: number;\n /** The binding materials use, rebuilt when the probe moves or its box changes. */\n binding: LiteProbeBinding | null;\n}\n\n/** A material `forEachReflectiveMesh` hands out. */\ntype ReflectiveMaterial = Parameters<typeof assignReflectionProbe>[1];\n\n/** A candidate with the binding it stands for. */\ninterface BoundCandidate extends ReflectionProbeCandidate {\n /** The binding. */\n readonly binding: LiteProbeBinding;\n}\n\n/**\n * Every reflection probe of a renderer.\n *\n * @internal\n */\nexport interface ReflectionProbeRuntime {\n /**\n * Captures what is due and points each lit PBR material at its probe. Called once per frame from\n * the `PreRender` system.\n *\n * @param world - The world the probes live in.\n * @param probes - Every `ReflectionProbe` in the world.\n * @param isHdr - Whether `rendering.hdr` is on.\n */\n update(world: World, probes: readonly ReflectionProbe[], isHdr: boolean): void;\n /** Frees every probe and hands every material back to the scene environment. */\n dispose(): void;\n}\n\n/**\n * Creates the runtime once Lite's local-cubemap shader path is loaded.\n *\n * @param engine - The engine.\n * @param scene - The registered render scene.\n * @returns The runtime.\n *\n * @internal\n */\nexport async function createReflectionProbeRuntime(\n engine: LiteEngine,\n scene: LiteScene,\n): Promise<ReflectionProbeRuntime> {\n await enableReflectionProbes();\n const states = new Map<ReflectionProbe, ProbeState>();\n const assigned = new Map<ReflectiveMaterial, LiteProbeBinding | null>();\n const seen = new Set<object>();\n const candidates: BoundCandidate[] = [];\n\n const release = (probe: ReflectionProbe, state: ProbeState): void => {\n state.lite.dispose();\n states.delete(probe);\n };\n\n const assignMaterials = (): void => {\n seen.clear();\n forEachReflectiveMesh(scene, (material, x, y, z) => {\n if (seen.has(material)) {\n return;\n }\n seen.add(material);\n const index = selectReflectionProbe(x, y, z, candidates);\n const binding = candidates[index]?.binding ?? null;\n const current = assigned.get(material);\n if (current === binding || (current === undefined && binding === null)) {\n return;\n }\n assigned.set(material, binding);\n assignReflectionProbe(scene, material, binding);\n });\n };\n\n return {\n update(world: World, probes: readonly ReflectionProbe[], isHdr: boolean): void {\n for (const [probe, state] of states) {\n if (!probes.includes(probe) || resolveReflectionProbeSize(probe.size) !== state.lite.size) {\n release(probe, state);\n }\n }\n candidates.length = 0;\n for (const probe of probes) {\n const wantsRefresh = probe.consumeRefreshRequest();\n if (!probe.isEnabledInHierarchy) {\n continue;\n }\n let state = states.get(probe);\n if (state === undefined) {\n state = {\n lite: createLiteReflectionProbe(\n engine,\n scene,\n resolveReflectionProbeSize(probe.size),\n EDITOR_ONLY_METADATA_KEY,\n cullingFilter(world, probe),\n ),\n framesToCapture: probe.refreshMode === \"once\" ? CAPTURE_FRAMES : 0,\n binding: null,\n };\n states.set(probe, state);\n }\n state.lite.resolve(!isHdr);\n const matrix = probe.entity.transform.worldMatrix;\n const x = matrix[12] ?? 0;\n const y = matrix[13] ?? 0;\n const z = matrix[14] ?? 0;\n if (wantsRefresh) {\n state.framesToCapture = CAPTURE_FRAMES;\n }\n if (state.framesToCapture > 0 || probe.refreshMode === \"everyFrame\") {\n state.lite.capture(x, y, z, probe.near, probe.far);\n state.framesToCapture = Math.max(0, state.framesToCapture - 1);\n }\n const environment = state.lite.environment;\n if (environment === null) {\n continue;\n }\n const box = probe.boxProjection;\n const binding = bindingFor(state.binding, environment, x, y, z, box);\n state.binding = binding;\n candidates.push({ x, y, z, box, binding });\n }\n assignMaterials();\n },\n dispose(): void {\n for (const [probe, state] of states) {\n release(probe, state);\n }\n for (const [material, binding] of assigned) {\n if (binding !== null) {\n assignReflectionProbe(scene, material, null);\n }\n }\n assigned.clear();\n },\n };\n}\n\n/**\n * Builds the mesh filter of a probe's capture: with a non-empty `cullingMask`, only meshes whose\n * entity is on one of its layers.\n *\n * @param world - The world, for the handle and layer tables.\n * @param probe - The probe; its mask is read on every call, so edits apply to the next capture.\n * @returns The filter.\n */\nfunction cullingFilter(world: World, probe: ReflectionProbe): (tag: NodeTag | null) => boolean {\n return (tag): boolean => {\n const mask = probe.cullingMask;\n if (mask.length === 0) {\n return true;\n }\n const entity = tag === null ? null : world.getEntityByHandle(toEntityHandle(tag.entity));\n if (entity === null) {\n return false;\n }\n for (const name of mask) {\n if (world.layers.indexOf(name) === entity.layer) {\n return true;\n }\n }\n return false;\n };\n}\n\n/**\n * The binding a probe's materials use: the previous one while nothing it holds changed, so a still\n * probe never rebuilds its materials.\n *\n * @param previous - The binding last used, or `null`.\n * @param environment - The probe's environment.\n * @param x - The probe's world X.\n * @param y - The probe's world Y.\n * @param z - The probe's world Z.\n * @param box - The projection box size, or `null`.\n * @returns The binding.\n */\nfunction bindingFor(\n previous: LiteProbeBinding | null,\n environment: LiteProbeBinding[\"environment\"],\n x: number,\n y: number,\n z: number,\n box: Vec3Like | null,\n): LiteProbeBinding {\n if (\n previous !== null &&\n previous.environment === environment &&\n previous.position[0] === x &&\n previous.position[1] === y &&\n previous.position[2] === z &&\n (box === null\n ? previous.box === null\n : previous.box !== null && previous.box[0] === box.x && previous.box[1] === box.y && previous.box[2] === box.z)\n ) {\n return previous;\n }\n return { environment, position: [x, y, z], box: box === null ? null : [box.x, box.y, box.z] };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,MAAM,eAAiC;;AAGvC,MAAM,uBAAyC;;AAG/C,MAAM,QAAgF;CACpF;EAAC;EAAG;EAAG;EAAG;EAAG;EAAG;CAAC;CACjB;EAAC;EAAI;EAAG;EAAG;EAAG;EAAG;CAAC;CAClB;EAAC;EAAG;EAAG;EAAG;EAAG;EAAG;CAAE;CAClB;EAAC;EAAG;EAAI;EAAG;EAAG;EAAG;CAAC;CAClB;EAAC;EAAG;EAAG;EAAG;EAAG;EAAG;CAAC;CACjB;EAAC;EAAG;EAAG;EAAI;EAAG;EAAG;CAAC;AACpB;;AAGA,MAAM,YAAuB;;;;;;;;;;;;;;;;;;;;AA4B7B,IAAI,gBAA0D;;;;;;;;AAwC9D,SAAgB,yBA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CAAC,OAAO,UAAU,QAC3B,QAAQ,OAAO,KAAK;GAEtB,KAAK,MAAM,CAAC,UAAU,YAAY,UAChC,IAAI,YAAY,MACd,sBAAsB,OAAO,UAAU,IAAI;GAG/C,SAAS,MAAM;EACjB;CACF;AACF;;;;;;;;;AAUA,SAAS,cAAc,OAAc,OAA0D;CAC7F,QAAQ,QAAiB;EACvB,MAAM,OAAO,MAAM;EACnB,IAAI,KAAK,WAAW,GAClB,OAAO;EAET,MAAM,SAAS,QAAQ,OAAO,OAAO,MAAM,kBAAkB,eAAe,IAAI,MAAM,CAAC;EACvF,IAAI,WAAW,MACb,OAAO;EAET,KAAK,MAAM,QAAQ,MACjB,IAAI,MAAM,OAAO,QAAQ,IAAI,MAAM,OAAO,OACxC,OAAO;EAGX,OAAO;CACT;AACF;;;;;;;;;;;;;AAcA,SAAS,WACP,UACA,aACA,GACA,GACA,GACA,KACkB;CAClB,IACE,aAAa,QACb,SAAS,gBAAgB,eACzB,SAAS,SAAS,OAAO,KACzB,SAAS,SAAS,OAAO,KACzB,SAAS,SAAS,OAAO,MACxB,QAAQ,OACL,SAAS,QAAQ,OACjB,SAAS,QAAQ,QAAQ,SAAS,IAAI,OAAO,IAAI,KAAK,SAAS,IAAI,OAAO,IAAI,KAAK,SAAS,IAAI,OAAO,IAAI,IAE/G,OAAO;CAET,OAAO;EAAE;EAAa,UAAU;GAAC;GAAG;GAAG;EAAC;EAAG,KAAK,QAAQ,OAAO,OAAO;GAAC,IAAI;GAAG,IAAI;GAAG,IAAI;EAAC;CAAE;AAC9F"}
@@ -156,11 +156,12 @@ function installOffscreenRenderPath(engine, scene) {
156
156
  scenePass: {
157
157
  task: sceneTask,
158
158
  target: sceneColor,
159
- format: engine.format
159
+ format: engine.format,
160
+ isTargetWritable: false
160
161
  }
161
162
  };
162
163
  }
163
164
  //#endregion
164
165
  export { markHdrScene as i, installOffscreenRenderPath as n, isHdrScene as r, DEPTH_STENCIL_FORMAT as t };
165
166
 
166
- //# sourceMappingURL=render-path-Be7WgN7r.js.map
167
+ //# sourceMappingURL=render-path-D11i_7X8.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"render-path-Be7WgN7r.js","names":[],"sources":["../src/lite/gpu/render-path.ts"],"sourcesContent":["import { addTask, createCopyToTextureTask, createRenderTarget, createRenderTask } from \"@babylonjs/lite\";\nimport type {\n EngineContext,\n RenderTarget,\n RenderTargetTextureResult,\n SceneContext,\n Task,\n Texture2D,\n} from \"@babylonjs/lite\";\n\n/**\n * The offscreen render path (`docs/architecture/07-rendering.md` §2.7): the frame graph a scene gets\n * when the project declares `rendering.features.postProcessing`.\n *\n * Everything here needs a device.\n *\n * ## Why the default render task is not good enough\n *\n * `createSceneContext` appends a task named `\"scene\"` that draws straight into the surface's\n * swapchain target — `surface.scRT` for a single-sample surface, or an MSAA colour target that\n * resolves into `scRT` (`lib/scene/scene-core.js` 74-79). Either way the scene's colour ends up in\n * the swapchain texture, and a post-process pass cannot read it: `createSurface` configures the\n * canvas context with no `usage` (`lib/engine/surface.js` 30), so the swapchain texture is\n * `RENDER_ATTACHMENT` only. Binding it as a sampled texture fails WebGPU validation, the whole\n * frame's command buffer is rejected, and the page presents black. That is exactly what the Phase 2\n * visual suite measured, and it is why this module exists.\n *\n * Lite offers no way to retarget the default task after the fact — `RenderTaskConfig.rt` is read\n * when the task is created, and `FrameGraph`'s public surface is only `build`/`execute`/`dispose`\n * (`index.d.ts` 5367). So the scene is created with `defaultRenderTask: false` and this module\n * builds the replacement.\n *\n * ## The graph it builds\n *\n * ```text\n * [shadow] → scene ──→ sceneColor ──→ present ──→ swapchain\n * └─ (a PostProcessStack appends its effects here, and disables present)\n * ```\n *\n * - `scene` is a normal `createRenderTask`. With MSAA it draws into a multisampled colour target\n * that owns its depth and resolves into `sceneColor` through `rst`; without MSAA it draws into\n * `sceneColor` directly with a separate depth target, which is the same split Lite's own default\n * uses (`RenderTaskConfig.depth`, `index.d.ts` 9782).\n * - `sceneColor` is an ordinary `createRenderTarget`, so `buildRenderTarget` allocates it with\n * `RENDER_ATTACHMENT | TEXTURE_BINDING | COPY_SRC | COPY_DST` (`lib/engine/render-target.js`) —\n * the `TEXTURE_BINDING` the swapchain lacks.\n * - `present` is a `createCopyToTextureTask` from `sceneColor` to the swapchain. Copying *into* the\n * swapchain is supported and takes the blit path (`lib/frame-graph/copy-to-texture-task.js`,\n * `swapAsView`); copying *out of* it is refused (Lite error 80), which is the same limit stated\n * from the other side.\n * - The swapchain is written every frame whatever else happens: with no chain, `present` does it;\n * with a chain, the chain's last effect does it and `present` is switched off\n * ({@link ScenePresenter.setPresentEnabled}).\n *\n * ## Resize\n *\n * Every target here is sized by passing the **surface** as `RenderTargetDescriptor.size`, which\n * `resolveSize` re-reads from `canvas.width`/`canvas.height` on every `buildRenderTarget`\n * (`lib/engine/render-target.js`). A surface resize calls the scene's `_resize`, which is\n * `frameGraph.build()` (`lib/scene/scene-core.js` 67-68): every target is reallocated at the new\n * size and every task re-records, which is also what refreshes the bind groups that captured the old\n * texture views. Nothing here has to observe the canvas itself, and nothing is eagerly allocated —\n * `createRenderTargetTexture` would be, and Lite rejects a surface as its size for exactly that\n * reason.\n */\n\n/**\n * The depth/stencil format Lite's own default render task uses (`lib/scene/scene-core.js` 76-77).\n *\n * @internal\n */\nexport const DEPTH_STENCIL_FORMAT: GPUTextureFormat = \"depth24plus-stencil8\";\n\n/**\n * The HDR half of a presenter, when `rendering.hdr` built one (`./hdr-output.ts`).\n *\n * @internal\n */\nexport interface HdrOutputHandle {\n /** The scene's linear `rgba16float` colour, as a sampled texture. Values may exceed 1. */\n readonly sceneTexture: Texture2D;\n /** The render target behind {@link HdrOutputHandle.sceneTexture}, for a pass that writes it back (TAA). */\n readonly sceneTarget: RenderTarget;\n /** The `\"scene\"` render task, whose scene uniforms the TAA jitter offsets. */\n readonly sceneTask: Task;\n /**\n * The auto exposure result, a 1×1 `r32float` texture holding `log2` of the multiplier the output\n * pass applies (`./auto-exposure.ts`); `null` when `rendering.autoExposure` is off.\n */\n readonly exposureTexture: Texture2D | null;\n /**\n * The same target with its sampled facade and resize hook: what HDR bloom (step G12) samples,\n * writes back into, and rebinds on resize.\n */\n readonly sceneTargetTexture: RenderTargetTextureResult;\n /**\n * The per-frame work: uploads the scene's exposure, contrast and curve when they changed, and\n * gives every new PBR material the linear-output plugin.\n *\n * @param isSceneRegistered - Whether Lite has built the scene, so a patched material needs a\n * rebuild.\n */\n update(isSceneRegistered: boolean): void;\n /**\n * Puts a task between the scene pass and the output pass, where it reads and writes linear\n * colour: a `PostProcessStack`'s custom effects ordered before any built-in one (GI plan G3).\n *\n * @param task - The task; it must write an `rgba16float` target.\n * @param isFrameGraphBuilt - Whether the scene is registered, so the task has to be recorded now.\n */\n insertLinearTask(task: Task, isFrameGraphBuilt: boolean): void;\n /**\n * Points the output pass at another linear texture, or back at the scene's.\n *\n * @param texture - The last linear effect's output, or `null` for {@link HdrOutputHandle.sceneTexture}.\n */\n setOutputSource(texture: Texture2D | null): void;\n}\n\n/** The scenes `rendering.hdr` built, created on first use so the module has no import-time work. */\nlet hdrScenes: WeakSet<SceneContext> | null = null;\n\n/**\n * Records that a scene renders through the HDR path, so code outside the HDR chunk (a custom\n * shader's build) can ask without importing it.\n *\n * @param scene - The scene `./hdr-output.ts` built a render path for.\n *\n * @internal\n */\nexport function markHdrScene(scene: SceneContext): void {\n hdrScenes ??= new WeakSet();\n hdrScenes.add(scene);\n}\n\n/**\n * Whether a scene renders through the HDR path, where every colour writer must write linear colour.\n *\n * @param scene - The scene.\n * @returns `true` once `./hdr-output.ts` has built the scene's render path.\n *\n * @internal\n */\nexport function isHdrScene(scene: SceneContext): boolean {\n return hdrScenes?.has(scene) === true;\n}\n\n/**\n * A scene's offscreen render path: the colour a `PostProcessStack` reads, and the compositing blit\n * it takes over from.\n *\n * @internal\n */\nexport interface ScenePresenter {\n /**\n * The single-sample colour target the scene ends up in — resolved when MSAA is on. It carries\n * `TEXTURE_BINDING`, so it is a legal `sourceTexture` for a post-process task.\n */\n readonly sceneColor: RenderTarget;\n /** The surface's swapchain target, where the last pass of the frame has to land. */\n readonly swapchain: RenderTarget;\n /**\n * Switches the compositing blit on or off.\n *\n * @param enabled - `false` while an effect chain writes the swapchain itself.\n */\n setPresentEnabled(enabled: boolean): void;\n /** Whether the compositing blit currently runs. */\n readonly isPresentEnabled: boolean;\n /** The HDR output pass, when `rendering.hdr` is on; `null` for the plain offscreen path. */\n readonly hdr: HdrOutputHandle | null;\n /**\n * The scene's render task and the single-sample colour target it ends in: {@link\n * ScenePresenter.sceneColor} on the plain path, the `rgba16float` target under `rendering.hdr`.\n * Scene-colour effects (contact shadows, SSGI) insert their tasks right after `task` and write their\n * result back into `target`, so everything downstream reads it.\n */\n readonly scenePass: ScenePass;\n}\n\n/**\n * The scene's render task and its resolved colour target.\n *\n * @internal\n */\nexport interface ScenePass {\n /** The task named `\"scene\"`. */\n readonly task: Task;\n /** The single-sample colour target the scene ends in; it carries `TEXTURE_BINDING` and `COPY_DST`. */\n readonly target: RenderTarget;\n /** That target's colour format. */\n readonly format: GPUTextureFormat;\n}\n\n/**\n * Builds the scene's render task into an offscreen target and the blit that composites it, and\n * appends both to the scene's frame graph.\n *\n * @remarks\n * Call it immediately after `createSceneContext(engine, { defaultRenderTask: false })` and before\n * `registerScene`: `addTask` appends, so calling it first is what puts `\"scene\"` ahead of everything\n * a feature adds later, and `registerSceneWithShadowSupport` still unshifts its own `\"shadow\"` task\n * in front of both.\n *\n * @param engine - The engine, which is also the primary surface.\n * @param scene - The scene created with no default render task.\n * @returns The presenter a `PostProcessStack` builds its chain against.\n *\n * @example\n * ```ts\n * const scene = createSceneContext(engine, { defaultRenderTask: false });\n * const presenter = installOffscreenRenderPath(engine, scene);\n * ```\n *\n * @internal\n */\nexport function installOffscreenRenderPath(engine: EngineContext, scene: SceneContext): ScenePresenter {\n const isMultisampled = engine.msaaSamples > 1;\n const sceneColor = createRenderTarget({\n lbl: \"ignifx:scene-color\",\n format: engine.format,\n samples: 1,\n size: engine,\n });\n const colorTarget = isMultisampled\n ? createRenderTarget({\n lbl: \"ignifx:scene-color-msaa\",\n format: engine.format,\n dFormat: DEPTH_STENCIL_FORMAT,\n samples: engine.msaaSamples,\n size: engine,\n })\n : sceneColor;\n const config: {\n name: string;\n rt: RenderTarget;\n rst?: RenderTarget;\n depth?: RenderTarget;\n } = { name: \"scene\", rt: colorTarget };\n if (isMultisampled) {\n config.rst = sceneColor;\n } else {\n // A colour target that carries no `dFormat` allocates no depth of its own, so the pass needs a\n // separate one — the arrangement Lite's own single-sample default task uses.\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\n const present: Task = createCopyToTextureTask(\n { name: \"ignifx:present\", sourceTexture: sceneColor, targetTexture: engine.scRT },\n engine,\n scene,\n );\n addTask(scene, present);\n\n let isPresentEnabled = true;\n return {\n sceneColor,\n swapchain: engine.scRT,\n setPresentEnabled(enabled: boolean): void {\n isPresentEnabled = enabled;\n present.executionEnabled = enabled;\n },\n get isPresentEnabled(): boolean {\n return isPresentEnabled;\n },\n hdr: null,\n scenePass: { task: sceneTask, target: sceneColor, format: engine.format },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,MAAa,uBAAyC;;AAiDtD,IAAI,YAA0C;;;;;;;;;AAU9C,SAAgB,aAAa,OAA2B;CACtD,8BAAc,IAAI,QAAQ;CAC1B,UAAU,IAAI,KAAK;AACrB;;;;;;;;;AAUA,SAAgB,WAAW,OAA8B;CACvD,OAAO,WAAW,IAAI,KAAK,MAAM;AACnC;;;;;;;;;;;;;;;;;;;;;;;AAuEA,SAAgB,2BAA2B,QAAuB,OAAqC;CACrG,MAAM,iBAAiB,OAAO,cAAc;CAC5C,MAAM,aAAa,mBAAmB;EACpC,KAAK;EACL,QAAQ,OAAO;EACf,SAAS;EACT,MAAM;CACR,CAAC;CAUD,MAAM,SAKF;EAAE,MAAM;EAAS,IAdD,iBAChB,mBAAmB;GACjB,KAAK;GACL,QAAQ,OAAO;GACf,SAAS;GACT,SAAS,OAAO;GAChB,MAAM;EACR,CAAC,IACD;CAMiC;CACrC,IAAI,gBACF,OAAO,MAAM;MAIb,OAAO,QAAQ,mBAAmB;EAChC,KAAK;EACL,SAAS;EACT,SAAS;EACT,MAAM;CACR,CAAC;CAEH,MAAM,YAAkB,iBAAiB,QAAQ,QAAQ,KAAK;CAC9D,QAAQ,OAAO,SAAS;CAExB,MAAM,UAAgB,wBACpB;EAAE,MAAM;EAAkB,eAAe;EAAY,eAAe,OAAO;CAAK,GAChF,QACA,KACF;CACA,QAAQ,OAAO,OAAO;CAEtB,IAAI,mBAAmB;CACvB,OAAO;EACL;EACA,WAAW,OAAO;EAClB,kBAAkB,SAAwB;GACxC,mBAAmB;GACnB,QAAQ,mBAAmB;EAC7B;EACA,IAAI,mBAA4B;GAC9B,OAAO;EACT;EACA,KAAK;EACL,WAAW;GAAE,MAAM;GAAW,QAAQ;GAAY,QAAQ,OAAO;EAAO;CAC1E;AACF"}
1
+ {"version":3,"file":"render-path-D11i_7X8.js","names":[],"sources":["../src/lite/gpu/render-path.ts"],"sourcesContent":["import { addTask, createCopyToTextureTask, createRenderTarget, createRenderTask } from \"@babylonjs/lite\";\nimport type {\n EngineContext,\n RenderTarget,\n RenderTargetTextureResult,\n SceneContext,\n Task,\n Texture2D,\n} from \"@babylonjs/lite\";\n\n/**\n * The offscreen render path (`docs/architecture/07-rendering.md` §2.7): the frame graph a scene gets\n * when the project declares `rendering.features.postProcessing`.\n *\n * Everything here needs a device.\n *\n * ## Why the default render task is not good enough\n *\n * `createSceneContext` appends a task named `\"scene\"` that draws straight into the surface's\n * swapchain target — `surface.scRT` for a single-sample surface, or an MSAA colour target that\n * resolves into `scRT` (`lib/scene/scene-core.js` 74-79). Either way the scene's colour ends up in\n * the swapchain texture, and a post-process pass cannot read it: `createSurface` configures the\n * canvas context with no `usage` (`lib/engine/surface.js` 30), so the swapchain texture is\n * `RENDER_ATTACHMENT` only. Binding it as a sampled texture fails WebGPU validation, the whole\n * frame's command buffer is rejected, and the page presents black. That is exactly what the Phase 2\n * visual suite measured, and it is why this module exists.\n *\n * Lite offers no way to retarget the default task after the fact — `RenderTaskConfig.rt` is read\n * when the task is created, and `FrameGraph`'s public surface is only `build`/`execute`/`dispose`\n * (`index.d.ts` 5367). So the scene is created with `defaultRenderTask: false` and this module\n * builds the replacement.\n *\n * ## The graph it builds\n *\n * ```text\n * [shadow] → scene ──→ sceneColor ──→ present ──→ swapchain\n * └─ (a PostProcessStack appends its effects here, and disables present)\n * ```\n *\n * - `scene` is a normal `createRenderTask`. With MSAA it draws into a multisampled colour target\n * that owns its depth and resolves into `sceneColor` through `rst`; without MSAA it draws into\n * `sceneColor` directly with a separate depth target, which is the same split Lite's own default\n * uses (`RenderTaskConfig.depth`, `index.d.ts` 9782).\n * - `sceneColor` is an ordinary `createRenderTarget`, so `buildRenderTarget` allocates it with\n * `RENDER_ATTACHMENT | TEXTURE_BINDING | COPY_SRC | COPY_DST` (`lib/engine/render-target.js`) —\n * the `TEXTURE_BINDING` the swapchain lacks.\n * - `present` is a `createCopyToTextureTask` from `sceneColor` to the swapchain. Copying *into* the\n * swapchain is supported and takes the blit path (`lib/frame-graph/copy-to-texture-task.js`,\n * `swapAsView`); copying *out of* it is refused (Lite error 80), which is the same limit stated\n * from the other side.\n * - The swapchain is written every frame whatever else happens: with no chain, `present` does it;\n * with a chain, the chain's last effect does it and `present` is switched off\n * ({@link ScenePresenter.setPresentEnabled}).\n *\n * ## Resize\n *\n * Every target here is sized by passing the **surface** as `RenderTargetDescriptor.size`, which\n * `resolveSize` re-reads from `canvas.width`/`canvas.height` on every `buildRenderTarget`\n * (`lib/engine/render-target.js`). A surface resize calls the scene's `_resize`, which is\n * `frameGraph.build()` (`lib/scene/scene-core.js` 67-68): every target is reallocated at the new\n * size and every task re-records, which is also what refreshes the bind groups that captured the old\n * texture views. Nothing here has to observe the canvas itself, and nothing is eagerly allocated —\n * `createRenderTargetTexture` would be, and Lite rejects a surface as its size for exactly that\n * reason.\n */\n\n/**\n * The depth/stencil format Lite's own default render task uses (`lib/scene/scene-core.js` 76-77).\n *\n * @internal\n */\nexport const DEPTH_STENCIL_FORMAT: GPUTextureFormat = \"depth24plus-stencil8\";\n\n/**\n * The HDR half of a presenter, when `rendering.hdr` built one (`./hdr-output.ts`).\n *\n * @internal\n */\nexport interface HdrOutputHandle {\n /** The scene's linear `rgba16float` colour, as a sampled texture. Values may exceed 1. */\n readonly sceneTexture: Texture2D;\n /** The render target behind {@link HdrOutputHandle.sceneTexture}, for a pass that writes it back (TAA). */\n readonly sceneTarget: RenderTarget;\n /** The `\"scene\"` render task, whose scene uniforms the TAA jitter offsets. */\n readonly sceneTask: Task;\n /**\n * The auto exposure result, a 1×1 `r32float` texture holding `log2` of the multiplier the output\n * pass applies (`./auto-exposure.ts`); `null` when `rendering.autoExposure` is off.\n */\n readonly exposureTexture: Texture2D | null;\n /**\n * The same target with its sampled facade and resize hook: what HDR bloom (step G12) samples,\n * writes back into, and rebinds on resize.\n */\n readonly sceneTargetTexture: RenderTargetTextureResult;\n /**\n * The per-frame work: uploads the scene's exposure, contrast and curve when they changed, and\n * gives every new PBR material the linear-output plugin.\n *\n * @param isSceneRegistered - Whether Lite has built the scene, so a patched material needs a\n * rebuild.\n */\n update(isSceneRegistered: boolean): void;\n /**\n * Puts a task between the scene pass and the output pass, where it reads and writes linear\n * colour: a `PostProcessStack`'s custom effects ordered before any built-in one (GI plan G3).\n *\n * @param task - The task; it must write an `rgba16float` target.\n * @param isFrameGraphBuilt - Whether the scene is registered, so the task has to be recorded now.\n */\n insertLinearTask(task: Task, isFrameGraphBuilt: boolean): void;\n /**\n * Points the output pass at another linear texture, or back at the scene's.\n *\n * @param texture - The last linear effect's output, or `null` for {@link HdrOutputHandle.sceneTexture}.\n */\n setOutputSource(texture: Texture2D | null): void;\n}\n\n/** The scenes `rendering.hdr` built, created on first use so the module has no import-time work. */\nlet hdrScenes: WeakSet<SceneContext> | null = null;\n\n/**\n * Records that a scene renders through the HDR path, so code outside the HDR chunk (a custom\n * shader's build) can ask without importing it.\n *\n * @param scene - The scene `./hdr-output.ts` built a render path for.\n *\n * @internal\n */\nexport function markHdrScene(scene: SceneContext): void {\n hdrScenes ??= new WeakSet();\n hdrScenes.add(scene);\n}\n\n/**\n * Whether a scene renders through the HDR path, where every colour writer must write linear colour.\n *\n * @param scene - The scene.\n * @returns `true` once `./hdr-output.ts` has built the scene's render path.\n *\n * @internal\n */\nexport function isHdrScene(scene: SceneContext): boolean {\n return hdrScenes?.has(scene) === true;\n}\n\n/**\n * A scene's offscreen render path: the colour a `PostProcessStack` reads, and the compositing blit\n * it takes over from.\n *\n * @internal\n */\nexport interface ScenePresenter {\n /**\n * The single-sample colour target the scene ends up in — resolved when MSAA is on. It carries\n * `TEXTURE_BINDING`, so it is a legal `sourceTexture` for a post-process task.\n */\n readonly sceneColor: RenderTarget;\n /** The surface's swapchain target, where the last pass of the frame has to land. */\n readonly swapchain: RenderTarget;\n /**\n * Switches the compositing blit on or off.\n *\n * @param enabled - `false` while an effect chain writes the swapchain itself.\n */\n setPresentEnabled(enabled: boolean): void;\n /** Whether the compositing blit currently runs. */\n readonly isPresentEnabled: boolean;\n /** The HDR output pass, when `rendering.hdr` is on; `null` for the plain offscreen path. */\n readonly hdr: HdrOutputHandle | null;\n /**\n * The scene's render task and the single-sample colour target it ends in: {@link\n * ScenePresenter.sceneColor} on the plain path, the `rgba16float` target under `rendering.hdr`.\n * Scene-colour effects (contact shadows, SSGI) insert their tasks right after `task` and write their\n * result back into `target`, so everything downstream reads it.\n */\n readonly scenePass: ScenePass;\n}\n\n/**\n * The scene's render task and its resolved colour target.\n *\n * @internal\n */\nexport interface ScenePass {\n /** The task named `\"scene\"`. */\n readonly task: Task;\n /** The single-sample colour target the scene ends in; it carries `TEXTURE_BINDING` and `COPY_DST`. */\n readonly target: RenderTarget;\n /** That target's colour format. */\n readonly format: GPUTextureFormat;\n /**\n * Whether a post-process task may write {@link ScenePass.target} directly. `false` on the plain\n * path: its target is allocated lazily, and a post-process task that writes it reallocates it in\n * `record()` (Lite's `buildRenderTarget`, `lib/engine/render-target.js`), destroying the texture\n * the scene task and every pass recorded before it hold, so the frame is rejected and presents\n * black. The HDR target is eager and survives that.\n */\n readonly isTargetWritable: boolean;\n}\n\n/**\n * Builds the scene's render task into an offscreen target and the blit that composites it, and\n * appends both to the scene's frame graph.\n *\n * @remarks\n * Call it immediately after `createSceneContext(engine, { defaultRenderTask: false })` and before\n * `registerScene`: `addTask` appends, so calling it first is what puts `\"scene\"` ahead of everything\n * a feature adds later, and `registerSceneWithShadowSupport` still unshifts its own `\"shadow\"` task\n * in front of both.\n *\n * @param engine - The engine, which is also the primary surface.\n * @param scene - The scene created with no default render task.\n * @returns The presenter a `PostProcessStack` builds its chain against.\n *\n * @example\n * ```ts\n * const scene = createSceneContext(engine, { defaultRenderTask: false });\n * const presenter = installOffscreenRenderPath(engine, scene);\n * ```\n *\n * @internal\n */\nexport function installOffscreenRenderPath(engine: EngineContext, scene: SceneContext): ScenePresenter {\n const isMultisampled = engine.msaaSamples > 1;\n const sceneColor = createRenderTarget({\n lbl: \"ignifx:scene-color\",\n format: engine.format,\n samples: 1,\n size: engine,\n });\n const colorTarget = isMultisampled\n ? createRenderTarget({\n lbl: \"ignifx:scene-color-msaa\",\n format: engine.format,\n dFormat: DEPTH_STENCIL_FORMAT,\n samples: engine.msaaSamples,\n size: engine,\n })\n : sceneColor;\n const config: {\n name: string;\n rt: RenderTarget;\n rst?: RenderTarget;\n depth?: RenderTarget;\n } = { name: \"scene\", rt: colorTarget };\n if (isMultisampled) {\n config.rst = sceneColor;\n } else {\n // A colour target that carries no `dFormat` allocates no depth of its own, so the pass needs a\n // separate one — the arrangement Lite's own single-sample default task uses.\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\n const present: Task = createCopyToTextureTask(\n { name: \"ignifx:present\", sourceTexture: sceneColor, targetTexture: engine.scRT },\n engine,\n scene,\n );\n addTask(scene, present);\n\n let isPresentEnabled = true;\n return {\n sceneColor,\n swapchain: engine.scRT,\n setPresentEnabled(enabled: boolean): void {\n isPresentEnabled = enabled;\n present.executionEnabled = enabled;\n },\n get isPresentEnabled(): boolean {\n return isPresentEnabled;\n },\n hdr: null,\n scenePass: { task: sceneTask, target: sceneColor, format: engine.format, isTargetWritable: false },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,MAAa,uBAAyC;;AAiDtD,IAAI,YAA0C;;;;;;;;;AAU9C,SAAgB,aAAa,OAA2B;CACtD,8BAAc,IAAI,QAAQ;CAC1B,UAAU,IAAI,KAAK;AACrB;;;;;;;;;AAUA,SAAgB,WAAW,OAA8B;CACvD,OAAO,WAAW,IAAI,KAAK,MAAM;AACnC;;;;;;;;;;;;;;;;;;;;;;;AA+EA,SAAgB,2BAA2B,QAAuB,OAAqC;CACrG,MAAM,iBAAiB,OAAO,cAAc;CAC5C,MAAM,aAAa,mBAAmB;EACpC,KAAK;EACL,QAAQ,OAAO;EACf,SAAS;EACT,MAAM;CACR,CAAC;CAUD,MAAM,SAKF;EAAE,MAAM;EAAS,IAdD,iBAChB,mBAAmB;GACjB,KAAK;GACL,QAAQ,OAAO;GACf,SAAS;GACT,SAAS,OAAO;GAChB,MAAM;EACR,CAAC,IACD;CAMiC;CACrC,IAAI,gBACF,OAAO,MAAM;MAIb,OAAO,QAAQ,mBAAmB;EAChC,KAAK;EACL,SAAS;EACT,SAAS;EACT,MAAM;CACR,CAAC;CAEH,MAAM,YAAkB,iBAAiB,QAAQ,QAAQ,KAAK;CAC9D,QAAQ,OAAO,SAAS;CAExB,MAAM,UAAgB,wBACpB;EAAE,MAAM;EAAkB,eAAe;EAAY,eAAe,OAAO;CAAK,GAChF,QACA,KACF;CACA,QAAQ,OAAO,OAAO;CAEtB,IAAI,mBAAmB;CACvB,OAAO;EACL;EACA,WAAW,OAAO;EAClB,kBAAkB,SAAwB;GACxC,mBAAmB;GACnB,QAAQ,mBAAmB;EAC7B;EACA,IAAI,mBAA4B;GAC9B,OAAO;EACT;EACA,KAAK;EACL,WAAW;GAAE,MAAM;GAAW,QAAQ;GAAY,QAAQ,OAAO;GAAQ,kBAAkB;EAAM;CACnG;AACF"}
@@ -14,23 +14,23 @@ import { addTaskAfter, buildFrameGraphTask, createCopyToTextureTask, createRende
14
14
  * @internal
15
15
  */
16
16
  function installSceneColorPasses(engine, scene, presenter, passes, isFrameGraphBuilt) {
17
- const { task: sceneTask, target: sceneTarget, format } = presenter.scenePass;
18
- const scratch = createRenderTarget({
19
- lbl: "ignifx:scene-color-scratch",
20
- format,
21
- samples: 1,
22
- size: engine
23
- });
17
+ const { task: sceneTask, target: sceneTarget, format, isTargetWritable } = presenter.scenePass;
18
+ const scratches = [];
24
19
  const tasks = [];
25
20
  let source = sceneTarget;
26
21
  for (const pass of passes) {
27
- const target = source === sceneTarget ? scratch : sceneTarget;
22
+ const target = sceneColorPassTarget(source, sceneTarget, isTargetWritable, scratches, (index) => createRenderTarget({
23
+ lbl: index === 0 ? "ignifx:scene-color-scratch" : "ignifx:scene-color-scratch-2",
24
+ format,
25
+ samples: 1,
26
+ size: engine
27
+ }));
28
28
  tasks.push(pass.create(source, target));
29
29
  source = target;
30
30
  }
31
31
  if (source !== sceneTarget) tasks.push(createCopyToTextureTask({
32
32
  name: "ignifx:scene-color-copy",
33
- sourceTexture: scratch,
33
+ sourceTexture: source,
34
34
  targetTexture: sceneTarget
35
35
  }, engine, scene));
36
36
  let after = sceneTask;
@@ -55,11 +55,34 @@ function installSceneColorPasses(engine, scene, presenter, passes, isFrameGraphB
55
55
  if (list !== null && index >= 0) list.splice(index, 1);
56
56
  task.dispose();
57
57
  }
58
- disposeRenderTarget(scratch);
58
+ for (const scratch of scratches) disposeRenderTarget(scratch);
59
59
  }
60
60
  };
61
61
  }
62
+ /**
63
+ * Picks where the next scene-colour pass writes: back into the scene target when that is allowed
64
+ * and the pass does not read it, otherwise the scratch target the pass does not read.
65
+ *
66
+ * @param source - What the pass reads.
67
+ * @param sceneTarget - The scene's colour target.
68
+ * @param isTargetWritable - Whether a pass may write `sceneTarget` (`ScenePass.isTargetWritable` in `./render-path.ts`).
69
+ * @param scratches - The scratch targets made so far; a new one is appended when needed.
70
+ * @param createScratch - Makes the scratch target at an index, 0 or 1.
71
+ * @returns The target, never `source`.
72
+ *
73
+ * @internal
74
+ */
75
+ function sceneColorPassTarget(source, sceneTarget, isTargetWritable, scratches, createScratch) {
76
+ if (source !== sceneTarget && isTargetWritable) return sceneTarget;
77
+ const index = source === scratches[0] ? 1 : 0;
78
+ let scratch = scratches[index];
79
+ if (scratch === void 0) {
80
+ scratch = createScratch(index);
81
+ scratches[index] = scratch;
82
+ }
83
+ return scratch;
84
+ }
62
85
  //#endregion
63
- export { installSceneColorPasses };
86
+ export { installSceneColorPasses, sceneColorPassTarget };
64
87
 
65
- //# sourceMappingURL=scene-color-passes-DlNr-qyZ.js.map
88
+ //# sourceMappingURL=scene-color-passes-B93qTOka.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scene-color-passes-B93qTOka.js","names":[],"sources":["../src/lite/gpu/scene-color-passes.ts"],"sourcesContent":["import {\n addTaskAfter,\n buildFrameGraphTask,\n createCopyToTextureTask,\n createRenderTarget,\n disposeRenderTarget,\n getFrameGraph,\n} from \"@babylonjs/lite\";\nimport { frameGraphTasks } from \"./scene-inputs.js\";\nimport type { ScenePresenter } from \"./render-path.js\";\nimport type { EngineContext, RenderTarget, SceneContext, Task } from \"@babylonjs/lite\";\n\n/**\n * Scene-colour passes (`docs/architecture/07-rendering.md` §2.7, GI plan steps G10 and G11): Lite\n * screen-space effects that read the lit scene colour and the shared scene-input depth, and whose\n * result replaces the scene colour before anything else reads it. Its own chunk, loaded with the\n * first such effect (`CONSTITUTION.md` §2.5).\n *\n * ```text\n * scene ─→ S ─ pass 1 ─→ scratch ─ pass 2 ─→ S ─ … [─ copy ─→ S] ─→ present / output pass / chain\n * ```\n *\n * `S` is the presenter's {@link ScenePresenter.scenePass} target: `sceneColor` on the plain path,\n * the linear `rgba16float` target under `rendering.hdr`, so the passes see linear colour ahead of\n * the output pass there. Lite's composite cannot write its own source, so under HDR the passes\n * ping-pong between `S` and one scratch target of the same format, and a copy brings an odd count\n * back into `S`. On the plain path no pass may write `S` (`ScenePass.isTargetWritable` in `./render-path.ts`): the\n * passes ping-pong between two scratch targets and the copy always runs. Every task sits right after\n * the scene task, ahead of the present blit, the HDR output pass and a `PostProcessStack` chain\n * alike, which therefore need no change.\n */\n\n/**\n * One scene-colour effect, as the installer sees it.\n *\n * @internal\n */\nexport interface SceneColorPass {\n /**\n * Creates the effect's task.\n *\n * @param source - The colour it reads.\n * @param target - The colour it writes; never `source`.\n * @returns The task.\n */\n create(source: RenderTarget, target: RenderTarget): Task;\n}\n\n/**\n * The installed passes.\n *\n * @internal\n */\nexport interface InstalledSceneColorPasses {\n /** How many tasks were added, copy included. */\n readonly taskCount: number;\n /** Removes and disposes every task and the scratch target. Idempotent. */\n dispose(): void;\n}\n\n/**\n * Inserts the passes after the scene task, in order.\n *\n * @param engine - The engine; also the surface the scratch target is sized by.\n * @param scene - The scene.\n * @param presenter - The offscreen render path.\n * @param passes - The effects, first to last.\n * @param isFrameGraphBuilt - Whether the scene is registered, so each task is recorded now.\n * @returns The handle that takes them out again.\n *\n * @internal\n */\nexport function installSceneColorPasses(\n engine: EngineContext,\n scene: SceneContext,\n presenter: ScenePresenter,\n passes: readonly SceneColorPass[],\n isFrameGraphBuilt: boolean,\n): InstalledSceneColorPasses {\n const { task: sceneTask, target: sceneTarget, format, isTargetWritable } = presenter.scenePass;\n const scratches: RenderTarget[] = [];\n const tasks: Task[] = [];\n let source = sceneTarget;\n for (const pass of passes) {\n const target = sceneColorPassTarget(source, sceneTarget, isTargetWritable, scratches, (index) =>\n createRenderTarget({\n lbl: index === 0 ? \"ignifx:scene-color-scratch\" : \"ignifx:scene-color-scratch-2\",\n format,\n samples: 1,\n size: engine,\n }),\n );\n tasks.push(pass.create(source, target));\n source = target;\n }\n if (source !== sceneTarget) {\n tasks.push(\n createCopyToTextureTask(\n { name: \"ignifx:scene-color-copy\", sourceTexture: source, targetTexture: sceneTarget },\n engine,\n scene,\n ),\n );\n }\n let after = sceneTask;\n for (const task of tasks) {\n addTaskAfter(scene, task, after);\n after = task;\n }\n if (isFrameGraphBuilt) {\n const graph = getFrameGraph(scene);\n for (const task of tasks) {\n buildFrameGraphTask(graph, task);\n }\n }\n let isDisposed = false;\n return {\n taskCount: tasks.length,\n dispose(): void {\n if (isDisposed) {\n return;\n }\n isDisposed = true;\n const list = frameGraphTasks(scene);\n for (const task of tasks) {\n // Disable first: a disposed task that still executes is a use-after-free.\n task.executionEnabled = false;\n const index = list?.indexOf(task) ?? -1;\n if (list !== null && index >= 0) {\n list.splice(index, 1);\n }\n task.dispose();\n }\n for (const scratch of scratches) {\n disposeRenderTarget(scratch);\n }\n },\n };\n}\n\n/**\n * Picks where the next scene-colour pass writes: back into the scene target when that is allowed\n * and the pass does not read it, otherwise the scratch target the pass does not read.\n *\n * @param source - What the pass reads.\n * @param sceneTarget - The scene's colour target.\n * @param isTargetWritable - Whether a pass may write `sceneTarget` (`ScenePass.isTargetWritable` in `./render-path.ts`).\n * @param scratches - The scratch targets made so far; a new one is appended when needed.\n * @param createScratch - Makes the scratch target at an index, 0 or 1.\n * @returns The target, never `source`.\n *\n * @internal\n */\nexport function sceneColorPassTarget<T>(\n source: T,\n sceneTarget: T,\n isTargetWritable: boolean,\n scratches: T[],\n createScratch: (index: number) => T,\n): T {\n if (source !== sceneTarget && isTargetWritable) {\n return sceneTarget;\n }\n const index = source === scratches[0] ? 1 : 0;\n let scratch = scratches[index];\n if (scratch === undefined) {\n scratch = createScratch(index);\n scratches[index] = scratch;\n }\n return scratch;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAwEA,SAAgB,wBACd,QACA,OACA,WACA,QACA,mBAC2B;CAC3B,MAAM,EAAE,MAAM,WAAW,QAAQ,aAAa,QAAQ,qBAAqB,UAAU;CACrF,MAAM,YAA4B,CAAC;CACnC,MAAM,QAAgB,CAAC;CACvB,IAAI,SAAS;CACb,KAAK,MAAM,QAAQ,QAAQ;EACzB,MAAM,SAAS,qBAAqB,QAAQ,aAAa,kBAAkB,YAAY,UACrF,mBAAmB;GACjB,KAAK,UAAU,IAAI,+BAA+B;GAClD;GACA,SAAS;GACT,MAAM;EACR,CAAC,CACH;EACA,MAAM,KAAK,KAAK,OAAO,QAAQ,MAAM,CAAC;EACtC,SAAS;CACX;CACA,IAAI,WAAW,aACb,MAAM,KACJ,wBACE;EAAE,MAAM;EAA2B,eAAe;EAAQ,eAAe;CAAY,GACrF,QACA,KACF,CACF;CAEF,IAAI,QAAQ;CACZ,KAAK,MAAM,QAAQ,OAAO;EACxB,aAAa,OAAO,MAAM,KAAK;EAC/B,QAAQ;CACV;CACA,IAAI,mBAAmB;EACrB,MAAM,QAAQ,cAAc,KAAK;EACjC,KAAK,MAAM,QAAQ,OACjB,oBAAoB,OAAO,IAAI;CAEnC;CACA,IAAI,aAAa;CACjB,OAAO;EACL,WAAW,MAAM;EACjB,UAAgB;GACd,IAAI,YACF;GAEF,aAAa;GACb,MAAM,OAAO,gBAAgB,KAAK;GAClC,KAAK,MAAM,QAAQ,OAAO;IAExB,KAAK,mBAAmB;IACxB,MAAM,QAAQ,MAAM,QAAQ,IAAI,KAAK;IACrC,IAAI,SAAS,QAAQ,SAAS,GAC5B,KAAK,OAAO,OAAO,CAAC;IAEtB,KAAK,QAAQ;GACf;GACA,KAAK,MAAM,WAAW,WACpB,oBAAoB,OAAO;EAE/B;CACF;AACF;;;;;;;;;;;;;;AAeA,SAAgB,qBACd,QACA,aACA,kBACA,WACA,eACG;CACH,IAAI,WAAW,eAAe,kBAC5B,OAAO;CAET,MAAM,QAAQ,WAAW,UAAU,KAAK,IAAI;CAC5C,IAAI,UAAU,UAAU;CACxB,IAAI,YAAY,KAAA,GAAW;EACzB,UAAU,cAAc,KAAK;EAC7B,UAAU,SAAS;CACrB;CACA,OAAO;AACT"}
@@ -1,8 +1,8 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
2
- import { o as CoreErrorCode, t as IgnifxError } from "./ignifx-error-Der0bpHK.js";
3
- import { M as setOwnJsonProperty } from "./prefab-overrides-DGiGTSN-.js";
2
+ import { o as CoreErrorCode, t as IgnifxError } from "./ignifx-error-B8ByiSfJ.js";
3
+ import { M as setOwnJsonProperty } from "./prefab-overrides-DT-wHHAJ.js";
4
4
  import { t as Color } from "./color-DrR6GFTd.js";
5
- import { r as isHdrScene } from "./render-path-Be7WgN7r.js";
5
+ import { r as isHdrScene } from "./render-path-D11i_7X8.js";
6
6
  import { n as IGNIFX_UNIFORM_TYPES, r as LITE_SYSTEM_UNIFORM_NAMES, t as IGNIFX_UNIFORM_NAMES } from "./shader-declaration-5q__jycG.js";
7
7
  //#region src/render/shader-material.ts
8
8
  var shader_material_exports = /* @__PURE__ */ __exportAll({
@@ -163,7 +163,7 @@ let adapter = null;
163
163
  */
164
164
  async function loadShaderMaterialAdapter() {
165
165
  if (adapter !== null) return;
166
- const loaded = await import("./shader-material-DCjYDdkh.js");
166
+ const loaded = await import("./shader-material-CaAkv5nT.js");
167
167
  loaded.enableShaderUniformCaching();
168
168
  adapter = loaded;
169
169
  }
@@ -1010,4 +1010,4 @@ function shapeMismatch(declaration, material, expected, actual) {
1010
1010
  //#endregion
1011
1011
  export { shader_material_exports as n, shaderMaterialsOf as t };
1012
1012
 
1013
- //# sourceMappingURL=shader-material-Cjfq7nFS.js.map
1013
+ //# sourceMappingURL=shader-material-C2_UCYdO.js.map