@ignifx/core 0.21.0 → 0.22.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/README.md +22 -0
- package/dist/{agx-tone-mapping-Cgt844j6.js → agx-tone-mapping-CCdGk_ly.js} +2 -2
- package/dist/agx-tone-mapping-CCdGk_ly.js.map +1 -0
- package/dist/auto-exposure-uzPn0beO.js.map +1 -1
- package/dist/{bloom-hdr-CLtQj-oY.js → bloom-hdr-xPwkIdHG.js} +5 -6
- package/dist/bloom-hdr-xPwkIdHG.js.map +1 -0
- package/dist/contact-shadows-T523EXaP.js.map +1 -1
- package/dist/effect-task-CMbuO6Kb.js.map +1 -1
- package/dist/{environment-Bf4aphSb.js → environment-7fJbN402.js} +2 -2
- package/dist/{environment-Bf4aphSb.js.map → environment-7fJbN402.js.map} +1 -1
- package/dist/{gtao-Bpu5-0Ne.js → gtao-CVAYWBEJ.js} +10 -11
- package/dist/gtao-CVAYWBEJ.js.map +1 -0
- package/dist/{hdr-output-DBQwMphy.js → hdr-output-_2TU-jWy.js} +8 -8
- package/dist/hdr-output-_2TU-jWy.js.map +1 -0
- package/dist/index.d.ts +61 -48
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +148 -129
- package/dist/index.js.map +1 -1
- package/dist/{instanced-mesh-instance-B-fXKSrY.js → instanced-mesh-instance-BLdAJTj8.js} +3 -3
- package/dist/instanced-mesh-instance-BLdAJTj8.js.map +1 -0
- package/dist/{light-probe-asset-BqfSrJe9.js → light-probe-asset-DGNIwKNb.js} +2 -2
- package/dist/light-probe-asset-DGNIwKNb.js.map +1 -0
- package/dist/{light-probes-DDojYajw.js → light-probes-C8jharz9.js} +6 -6
- package/dist/light-probes-C8jharz9.js.map +1 -0
- package/dist/lightmaps-BUUIIkt9.js.map +1 -1
- package/dist/material-myMbl9mW.js.map +1 -1
- package/dist/{material-plugin-DapJNj04.js → material-plugin-BBxIy6eo.js} +4 -4
- package/dist/material-plugin-BBxIy6eo.js.map +1 -0
- package/dist/{overlay-CjVgsfrm.js → overlay-DokHzP6_.js} +2 -3
- package/dist/overlay-DokHzP6_.js.map +1 -0
- package/dist/{post-effect-Cu3Enpz7.js → post-effect-DEZD-r0I.js} +3 -3
- package/dist/post-effect-DEZD-r0I.js.map +1 -0
- package/dist/{post-effect-compiler-cCq9lcHt.js → post-effect-compiler-unDD3hod.js} +4 -4
- package/dist/post-effect-compiler-unDD3hod.js.map +1 -0
- package/dist/{prefab-overrides-C2GsgOQc.js → prefab-overrides-Bb7jVm7A.js} +3 -3
- package/dist/prefab-overrides-Bb7jVm7A.js.map +1 -0
- package/dist/{prefab-overrides-htDc_5Po.d.ts → prefab-overrides-CkwXhp5A.d.ts} +84 -64
- package/dist/{prefab-overrides-htDc_5Po.d.ts.map → prefab-overrides-CkwXhp5A.d.ts.map} +1 -1
- package/dist/prefab.d.ts +1 -1
- package/dist/prefab.js +1 -1
- package/dist/{reflection-probe-QkD1Fo_d.js → reflection-probe-C2jcreI1.js} +5 -5
- package/dist/reflection-probe-C2jcreI1.js.map +1 -0
- package/dist/{reflection-probes-CAzSuqf8.js → reflection-probes-BMVQfbhm.js} +10 -10
- package/dist/reflection-probes-BMVQfbhm.js.map +1 -0
- package/dist/{render-path-D11i_7X8.js → render-path-CWXHrRa2.js} +2 -2
- package/dist/render-path-CWXHrRa2.js.map +1 -0
- package/dist/scene-color-passes-CM_T2KF-.js +177 -0
- package/dist/scene-color-passes-CM_T2KF-.js.map +1 -0
- package/dist/scene-inputs-CbTkrkOw.js +489 -0
- package/dist/scene-inputs-CbTkrkOw.js.map +1 -0
- package/dist/{shader-declaration-5q__jycG.js → shader-declaration-BGprFBLq.js} +4 -4
- package/dist/shader-declaration-BGprFBLq.js.map +1 -0
- package/dist/{shader-material-TM4f8eKA.js → shader-material-C9sYMGWw.js} +8 -9
- package/dist/shader-material-C9sYMGWw.js.map +1 -0
- package/dist/{shader-material-CJIDFvSb.js → shader-material-vmkJ25II.js} +3 -3
- package/dist/shader-material-vmkJ25II.js.map +1 -0
- package/dist/{shader-pragma-ljmAbVc2.js → shader-pragma-D0MjCOIg.js} +3 -3
- package/dist/shader-pragma-D0MjCOIg.js.map +1 -0
- package/dist/ssgi-Dk20U3oR.js +492 -0
- package/dist/ssgi-Dk20U3oR.js.map +1 -0
- package/dist/{surface-shader-rpPpeosD.js → surface-shader-BfADq9Wx.js} +6 -6
- package/dist/surface-shader-BfADq9Wx.js.map +1 -0
- package/dist/{taa-BwBZLy11.js → taa-nxVA78Ur.js} +5 -6
- package/dist/taa-nxVA78Ur.js.map +1 -0
- package/dist/vec3-2C3LBZnt.js.map +1 -1
- package/package.json +1 -1
- package/dist/agx-tone-mapping-Cgt844j6.js.map +0 -1
- package/dist/bloom-hdr-CLtQj-oY.js.map +0 -1
- package/dist/gtao-Bpu5-0Ne.js.map +0 -1
- package/dist/hdr-output-DBQwMphy.js.map +0 -1
- package/dist/instanced-mesh-instance-B-fXKSrY.js.map +0 -1
- package/dist/light-probe-asset-BqfSrJe9.js.map +0 -1
- package/dist/light-probes-DDojYajw.js.map +0 -1
- package/dist/material-plugin-DapJNj04.js.map +0 -1
- package/dist/overlay-CjVgsfrm.js.map +0 -1
- package/dist/post-effect-Cu3Enpz7.js.map +0 -1
- package/dist/post-effect-compiler-cCq9lcHt.js.map +0 -1
- package/dist/prefab-overrides-C2GsgOQc.js.map +0 -1
- package/dist/reflection-probe-QkD1Fo_d.js.map +0 -1
- package/dist/reflection-probes-CAzSuqf8.js.map +0 -1
- package/dist/render-path-D11i_7X8.js.map +0 -1
- package/dist/scene-color-passes-B93qTOka.js +0 -88
- package/dist/scene-color-passes-B93qTOka.js.map +0 -1
- package/dist/scene-inputs-BxGOsnIZ.js +0 -318
- package/dist/scene-inputs-BxGOsnIZ.js.map +0 -1
- package/dist/shader-declaration-5q__jycG.js.map +0 -1
- package/dist/shader-material-CJIDFvSb.js.map +0 -1
- package/dist/shader-material-TM4f8eKA.js.map +0 -1
- package/dist/shader-pragma-ljmAbVc2.js.map +0 -1
- package/dist/ssgi-DSnhqotl.js +0 -113
- package/dist/ssgi-DSnhqotl.js.map +0 -1
- package/dist/surface-shader-rpPpeosD.js.map +0 -1
- package/dist/taa-BwBZLy11.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay-DokHzP6_.js","names":[],"sources":["../src/lite/gpu/overlay.ts"],"sourcesContent":["import {\n addTask,\n addToScene,\n buildFrameGraphTask,\n createHemisphericLight,\n createRenderTarget,\n createRenderTask,\n createSceneContext,\n disposeScene,\n getFrameGraph,\n getRenderingContexts,\n onBeforeRender,\n registerScene,\n unregisterScene,\n} from \"@babylonjs/lite\";\nimport type { EngineContext, RenderTask, SceneContext } from \"@babylonjs/lite\";\n\n/**\n * The render overlay (`docs/architecture/07-rendering.md` §2.10, ADR-0031): a second Lite scene drawn\n * over the finished frame, for an editor's gizmos, selection outlines and other helpers.\n *\n * Everything here needs a device.\n *\n * ## Why core does not call `createUtilityLayer`\n *\n * `createUtilityLayer` (`index.d.ts` 4109) builds its scene with Lite's default render task, and\n * `registerScene` (11268) then fixes that task up against the **last** registered rendering\n * context (`lib/scene/swapchain-overlay.js` 11). Two things go wrong in an ignifx app:\n *\n * - When `@ignifx/ui`'s text renderer or `@ignifx/2d`'s sprite renderer was registered after the\n * render scene, it is the last context. It has no frame graph, so Lite configures nothing and the\n * layer's task clears the frame to transparent black.\n * - With MSAA on, Lite borrows the base scene's multisampled colour view, and switches the layer\n * off unless that scene resolves straight into the swapchain (`swapchain-overlay.js` 19-27). With\n * `rendering.features.postProcessing` the render scene resolves into an offscreen target, so the\n * layer never draws.\n *\n * ## What this module builds instead\n *\n * Only public Lite calls:\n *\n * 1. A scene with no default render task (`createSceneContext`, 3663) that shares the render\n * scene's camera, plus the hemispheric light `createUtilityLayer` would add, so Lite's gizmo\n * materials look the same.\n * 2. `registerScene` while its frame graph is **empty**. Lite's fix-up looks for a task that targets\n * the swapchain (`swapchain-overlay.js` 5-7), finds none, and changes nothing.\n * 3. One render task (`createRenderTask`, 3620) added afterwards and recorded with\n * `buildFrameGraphTask` (1501). It draws into the swapchain with `clr: false`, so it keeps the\n * frame's colour, and `sharedRt: true`, so it never builds or frees the swapchain target\n * (`RenderTaskConfig`, 11635). It has a single-sample depth target of its own, which it clears,\n * so helpers draw on top of the scene. It never touches the scene's targets, so the scene's MSAA\n * setting and render path do not matter: it reads whatever the frame's last pass presented.\n *\n * ## Staying last\n *\n * Lite renders the contexts in registration order (`renderFrame`, `lib/engine/engine.js` 246-251),\n * and the 2D and UI extensions register theirs lazily, when the first sprite or text appears. A\n * sprite renderer in `\"sprite\"` mode clears the frame, so one registered after the overlay would\n * erase it. Each frame the overlay checks `getRenderingContexts` (6921); when a context other than\n * another overlay follows it, it moves itself to the end after the frame: unregister, drop its task\n * so the re-registration again finds no swapchain task, register, and build a fresh task. The frame\n * in between draws no overlay. A move that fails (a lost device, a pipeline that does not compile) is\n * reported and tried again on the next animation frame, {@link MOVE_ATTEMPTS} times in all; after\n * that the overlay stays detached until it is disposed.\n *\n * A screenshot is taken after every context has recorded (`_captureService`, same function), so it\n * includes the overlay.\n */\n\n/** The depth/stencil format Lite's own single-sample scene task uses (`lib/scene/scene-core.js` 76-77). */\nconst DEPTH_STENCIL_FORMAT: GPUTextureFormat = \"depth24plus-stencil8\";\n\n/** The name the overlay's task carries in Lite's frame graph and in per-task GPU timings. */\nexport const OVERLAY_TASK_NAME = \"ignifx:overlay\";\n\n/** The light `createUtilityLayer` adds by default (`lib/gizmo/utility-layer.js` 24-36). */\nconst LIGHT_INTENSITY = 2;\n\n/** The ground colour of that light. */\nconst LIGHT_GROUND = 0.5;\n\n/** How many times a move to the end of the context list is tried before the overlay gives up. */\nconst MOVE_ATTEMPTS = 3;\n\n/**\n * What an overlay reports to its owner.\n *\n * @internal\n */\nexport interface OverlayCallbacks {\n /**\n * Answers whether a rendering context is another overlay, which may follow this one.\n *\n * @param context - A registered rendering context.\n * @returns `true` for another overlay.\n */\n isPeer(context: object): boolean;\n /**\n * Called once when the overlay is disposed.\n *\n * @param scene - The overlay's scene.\n */\n onDispose(scene: object): void;\n /**\n * Receives a failed move to the end of the context list.\n *\n * @param error - What `registerScene` rejected with.\n */\n onError(error: unknown): void;\n}\n\n/**\n * The overlay scene and the render scene, in the shape Lite's gizmo constructors take as a\n * `UtilityLayer` (`index.d.ts` 15747).\n *\n * @internal\n */\nexport interface OverlaySceneHandles {\n /** The overlay scene. Add helpers to it. */\n readonly scene: SceneContext;\n /** The render scene, whose camera the overlay scene follows. */\n readonly mainScene: SceneContext;\n}\n\n/**\n * An open overlay scene.\n *\n * @internal\n */\nexport interface OverlayScene {\n /** The Lite scenes. */\n readonly lite: OverlaySceneHandles;\n /** Unregisters and disposes the overlay scene, its task and its depth target. Idempotent. */\n dispose(): void;\n}\n\n/**\n * Builds an overlay scene and registers it after every rendering context on the surface.\n *\n * @remarks\n * Call it only after the render scene is registered: the overlay draws after it because it is\n * registered after it.\n *\n * @param engine - The WebGPU engine, which is also the primary surface.\n * @param mainScene - The render scene whose camera the overlay follows.\n * @param callbacks - The owner's peer test, disposal hook and error sink.\n * @returns The overlay, drawing from the next frame.\n * @throws Whatever the first `registerScene` rejects with; the overlay is disposed first.\n *\n * @example\n * ```ts\n * const overlay = await openOverlayScene(engine, scene, {\n * isPeer: () => false,\n * onDispose: () => {},\n * onError: (error) => console.error(error),\n * });\n * overlay.dispose();\n * ```\n *\n * @internal\n */\nexport async function openOverlayScene(\n engine: EngineContext,\n mainScene: SceneContext,\n callbacks: OverlayCallbacks,\n): Promise<OverlayScene> {\n const overlay = new LiteOverlayScene(engine, mainScene, callbacks);\n try {\n await overlay.attach();\n } catch (error) {\n overlay.dispose();\n throw error;\n }\n return overlay;\n}\n\n/** The overlay scene, its registration and its place in the context list. */\nclass LiteOverlayScene implements OverlayScene {\n readonly lite: OverlaySceneHandles;\n\n readonly #engine: EngineContext;\n\n readonly #scene: SceneContext;\n\n readonly #callbacks: OverlayCallbacks;\n\n #isDisposed = false;\n\n #isMoving = false;\n\n /**\n * Creates the scene, with the light `createUtilityLayer` would add, following the render scene's\n * camera. It is not registered yet.\n *\n * @param engine - The WebGPU engine.\n * @param mainScene - The render scene.\n * @param callbacks - The owner's peer test, disposal hook and error sink.\n */\n constructor(engine: EngineContext, mainScene: SceneContext, callbacks: OverlayCallbacks) {\n const scene = createSceneContext(engine, { defaultRenderTask: false });\n scene.name = OVERLAY_TASK_NAME;\n scene.camera = mainScene.camera;\n const light = createHemisphericLight([0, 1, 0], LIGHT_INTENSITY);\n light.groundColor = [LIGHT_GROUND, LIGHT_GROUND, LIGHT_GROUND];\n addToScene(scene, light);\n this.lite = { scene, mainScene };\n this.#engine = engine;\n this.#scene = scene;\n this.#callbacks = callbacks;\n onBeforeRender(scene, () => {\n // The render scene's camera can change from frame to frame (the highest-priority `Camera` wins).\n if (scene.camera !== mainScene.camera) {\n scene.camera = mainScene.camera;\n }\n this.#keepLast();\n });\n }\n\n /**\n * Registers the scene at the end of the context list and builds its task.\n *\n * @returns A promise that settles once the overlay draws from the next frame.\n */\n async attach(): Promise<void> {\n // Registered while its frame graph is empty, so Lite's swapchain fix-up finds nothing to change.\n await registerScene(this.#scene);\n if (this.#isDisposed) {\n return;\n }\n const task = createOverlayTask(this.#engine, this.#scene);\n addTask(this.#scene, task);\n buildFrameGraphTask(getFrameGraph(this.#scene), task);\n }\n\n dispose(): void {\n if (this.#isDisposed) {\n return;\n }\n this.#isDisposed = true;\n unregisterScene(this.#scene);\n disposeScene(this.#scene);\n this.#callbacks.onDispose(this.#scene);\n }\n\n /** Schedules a move to the end of the context list when a context that is not an overlay follows. */\n #keepLast(): void {\n if (this.#isMoving || !this.#isFollowed()) {\n return;\n }\n // Not now: Lite is walking the context list. The microtask runs once the frame has been submitted.\n this.#isMoving = true;\n queueMicrotask(() => {\n this.#move(MOVE_ATTEMPTS);\n });\n }\n\n /**\n * Moves the overlay to the end, reporting a failure and trying again on the next animation frame.\n *\n * @param attemptsLeft - How many attempts remain, this one included.\n */\n #move(attemptsLeft: number): void {\n this.#moveToEnd().then(\n () => {\n this.#isMoving = false;\n },\n (error: unknown) => {\n this.#callbacks.onError(error);\n if (attemptsLeft > 1 && !this.#isDisposed) {\n // The overlay is unregistered now, so its own frame callback no longer runs to retry.\n requestAnimationFrame(() => {\n this.#move(attemptsLeft - 1);\n });\n return;\n }\n this.#isMoving = false;\n },\n );\n }\n\n /**\n * Whether a rendering context other than another overlay is registered after this one.\n *\n * @returns `true` when the overlay has to move.\n */\n #isFollowed(): boolean {\n const contexts = getRenderingContexts(this.#engine);\n for (let index = contexts.indexOf(this.#scene) + 1; index < contexts.length; index += 1) {\n const context = contexts[index];\n if (context !== undefined && !this.#callbacks.isPeer(context)) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Re-registers the overlay at the end of the context list.\n *\n * @returns A promise that settles once it draws last.\n */\n async #moveToEnd(): Promise<void> {\n if (this.#isDisposed) {\n return;\n }\n unregisterScene(this.#scene);\n // Disposing the graph drops the task, which also frees its depth target.\n getFrameGraph(this.#scene).dispose();\n await this.attach();\n }\n}\n\n/**\n * Creates the overlay's render task: into the swapchain, keeping its colour, over a depth buffer of\n * its own that it clears.\n *\n * @param engine - The engine.\n * @param scene - The overlay scene.\n * @returns The task, not yet added to a frame graph.\n */\nfunction createOverlayTask(engine: EngineContext, scene: SceneContext): RenderTask {\n return createRenderTask(\n {\n name: OVERLAY_TASK_NAME,\n rt: engine.scRT,\n sharedRt: true,\n depth: createRenderTarget({\n lbl: \"ignifx:overlay-depth\",\n dFormat: DEPTH_STENCIL_FORMAT,\n samples: 1,\n size: engine,\n }),\n clr: false,\n },\n engine,\n scene,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEA,MAAM,uBAAyC;;AAG/C,MAAa,oBAAoB;;AAGjC,MAAM,kBAAkB;;AAGxB,MAAM,eAAe;;AAGrB,MAAM,gBAA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,qBAAqB;GACnB,KAAK,MAAM,aAAa;EAC1B,CAAC;CACH;;;;;;CAOA,MAAM,cAA4B;EAChC,KAAK,WAAW,CAAC,CAAC,WACV;GACJ,KAAK,YAAY;EACnB,IACC,UAAmB;GAClB,KAAK,WAAW,QAAQ,KAAK;GAC7B,IAAI,eAAe,KAAK,CAAC,KAAK,aAAa;IAEzC,4BAA4B;KAC1B,KAAK,MAAM,eAAe,CAAC;IAC7B,CAAC;IACD;GACF;GACA,KAAK,YAAY;EACnB,CACF;CACF;;;;;;CAOA,cAAuB;EACrB,MAAM,WAAW,qBAAqB,KAAK,OAAO;EAClD,KAAK,IAAI,QAAQ,SAAS,QAAQ,KAAK,MAAM,IAAI,GAAG,QAAQ,SAAS,QAAQ,SAAS,GAAG;GACvF,MAAM,UAAU,SAAS;GACzB,IAAI,YAAY,KAAA,KAAa,CAAC,KAAK,WAAW,OAAO,OAAO,GAC1D,OAAO;EAEX;EACA,OAAO;CACT;;;;;;CAOA,MAAM,aAA4B;EAChC,IAAI,KAAK,aACP;EAEF,gBAAgB,KAAK,MAAM;EAE3B,cAAc,KAAK,MAAM,CAAC,CAAC,QAAQ;EACnC,MAAM,KAAK,OAAO;CACpB;AACF;;;;;;;;;AAUA,SAAS,kBAAkB,QAAuB,OAAiC;CACjF,OAAO,iBACL;EACE,MAAM;EACN,IAAI,OAAO;EACX,UAAU;EACV,OAAO,mBAAmB;GACxB,KAAK;GACL,SAAS;GACT,SAAS;GACT,MAAM;EACR,CAAC;EACD,KAAK;CACP,GACA,QACA,KACF;AACF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { F as asJsonObject, I as setOwnJsonProperty } from "./prefab-overrides-
|
|
1
|
+
import { F as asJsonObject, I as setOwnJsonProperty } from "./prefab-overrides-Bb7jVm7A.js";
|
|
2
2
|
//#region src/render/post-effect.ts
|
|
3
3
|
/**
|
|
4
4
|
* What a `PostProcessStack` needs to describe a custom `// @ignifx post` effect: its settings record,
|
|
5
5
|
* the uniforms every effect gets for free, and the schema codec its `values` round-trip through
|
|
6
|
-
* (
|
|
6
|
+
* (ADR-0024).
|
|
7
7
|
*
|
|
8
8
|
* `PostProcessStack` is in every game's static graph, so the WGSL generator and the uniform layout
|
|
9
9
|
* live in `./post-effect-compiler.ts`, which the `.wgsl` loader pulls in only for a `post` file.
|
|
@@ -126,4 +126,4 @@ function postEffectValuesCodec() {
|
|
|
126
126
|
//#endregion
|
|
127
127
|
export { postEffectValuesCodec as a, declaredTextureBinding as i, POST_EFFECT_FUNCTION as n, customEffect as r, POST_EFFECT_BUILTIN_UNIFORMS as t };
|
|
128
128
|
|
|
129
|
-
//# sourceMappingURL=post-effect-
|
|
129
|
+
//# sourceMappingURL=post-effect-DEZD-r0I.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"post-effect-DEZD-r0I.js","names":[],"sources":["../src/render/post-effect.ts"],"sourcesContent":["import { setOwnJsonProperty } from \"../schema/json.js\";\nimport { asJsonObject } from \"../serialization/json-view.js\";\nimport type { ShaderAsset } from \"./shader-asset.js\";\nimport type { ShaderTextureDeclaration, ShaderUniformType } from \"./shader-declaration.js\";\nimport type { TextureAsset } from \"./texture-asset.js\";\nimport type { AssetHandle } from \"../assets/types.js\";\nimport type { JsonValue } from \"../schema/json.js\";\nimport type { CustomFieldCodec } from \"../schema/types.js\";\n\n/**\n * What a `PostProcessStack` needs to describe a custom `// @ignifx post` effect: its settings record,\n * the uniforms every effect gets for free, and the schema codec its `values` round-trip through\n * (ADR-0024).\n *\n * `PostProcessStack` is in every game's static graph, so the WGSL generator and the uniform layout\n * live in `./post-effect-compiler.ts`, which the `.wgsl` loader pulls in only for a `post` file.\n */\n\n/**\n * The name a `// @ignifx post` file gives its fragment function.\n *\n * @public\n */\nexport const POST_EFFECT_FUNCTION = \"mainFragment\";\n\n/**\n * The uniforms every post effect's `shaderUniforms` block carries before the file's own, in this\n * order.\n *\n * @remarks\n * `screenSize` is in backing-store pixels — `canvas.width`/`canvas.height` — like everything else\n * the engine reports (`docs/architecture/07-rendering.md` §3). The three clocks are the app's, so\n * `time` freezes under `app.pause()` and `unscaledTime` does not.\n *\n * @public\n */\nexport const POST_EFFECT_BUILTIN_UNIFORMS: readonly { readonly name: string; readonly type: ShaderUniformType }[] =\n Object.freeze([\n { name: \"screenSize\", type: \"vec2<f32>\" },\n { name: \"time\", type: \"f32\" },\n { name: \"unscaledTime\", type: \"f32\" },\n { name: \"deltaTime\", type: \"f32\" },\n ]);\n\n/**\n * One custom effect on a `PostProcessStack` (`docs/architecture/07-rendering.md` §2.7).\n *\n * @public\n */\nexport interface CustomEffectSettings {\n /** The `// @ignifx post` shader; `null` records nothing. */\n shader: AssetHandle<ShaderAsset> | null;\n /** Whether the effect runs. */\n enabled: boolean;\n /** Position in the chain; lower runs first, alongside bloom's and SMAA's `order`. */\n order: number;\n /** Overrides of the file's declared uniform defaults, by declared name. */\n values: Record<string, number | readonly number[]>;\n /** Textures for the file's declared samplers, by declared name. */\n textures: Record<string, AssetHandle<TextureAsset> | null>;\n}\n\n/**\n * What {@link customEffect} accepts: a shader and whichever fields differ from the defaults.\n *\n * @public\n */\nexport interface CustomEffectInit {\n /** The `// @ignifx post` shader. */\n readonly shader: AssetHandle<ShaderAsset> | null;\n /** Whether the effect runs. Defaults to `true`. */\n readonly enabled?: boolean;\n /** Position in the chain. Defaults to `10`, which is after the built-ins' defaults. */\n readonly order?: number;\n /** Overrides of the file's declared uniform defaults. */\n readonly values?: Readonly<Record<string, number | readonly number[]>>;\n /** Textures for the file's declared samplers. */\n readonly textures?: Readonly<Record<string, AssetHandle<TextureAsset> | null>>;\n}\n\n/**\n * Fills in a custom effect's defaults, so a caller names only what it means to set.\n *\n * @param init - The shader and the fields to set.\n * @returns A complete settings record, ready to push onto `PostProcessStack.custom`.\n *\n * @example\n * ```ts\n * stack.custom.push(customEffect({ shader: vignette, order: 5, values: { amount: 0.6 } }));\n * ```\n *\n * @public\n */\nexport function customEffect(init: CustomEffectInit): CustomEffectSettings {\n return {\n shader: init.shader,\n enabled: init.enabled ?? true,\n order: init.order ?? 10,\n values: { ...init.values },\n textures: { ...init.textures },\n };\n}\n\n/**\n * The binding index of the chain's current colour.\n *\n * @internal\n */\nexport const INPUT_TEXTURE_BINDING = 1;\n\n/**\n * The binding index of the chain's current colour sampler.\n *\n * @internal\n */\nexport const INPUT_SAMPLER_BINDING = 2;\n\n/** The first binding index a declared texture takes. */\nconst FIRST_DECLARED_BINDING = 3;\n\n/**\n * The binding index of one declared texture, and of its sampler.\n *\n * @param index - The texture's index in declaration order.\n * @returns The texture's binding; the sampler is one higher.\n *\n * @internal\n */\nexport function declaredTextureBinding(index: number): number {\n return FIRST_DECLARED_BINDING + index * 2;\n}\n\n/**\n * One member of a compiled effect's uniform struct, with the byte offset the generated WGSL puts it\n * at.\n *\n * @internal\n */\nexport interface PostEffectUniformField {\n /** The WGSL member name. */\n readonly name: string;\n /** The WGSL type. */\n readonly type: ShaderUniformType;\n /** How many floats the value holds. */\n readonly components: number;\n /** Where the member starts in the uniform buffer, in bytes. */\n readonly byteOffset: number;\n}\n\n/**\n * A `// @ignifx post` file compiled into what Babylon Lite's fullscreen effect path needs.\n *\n * @internal\n */\nexport interface CompiledPostEffect {\n /** The shader's address, for diagnostics and for the chain's identity. */\n readonly address: string;\n /** The whole fragment module: the bindings, the generated structs, the file, and the entry point. */\n readonly fragmentWGSL: string;\n /** The uniform members, built-ins first, in struct order. */\n readonly uniforms: readonly PostEffectUniformField[];\n /** The members by name, for a value write. */\n readonly byName: ReadonlyMap<string, PostEffectUniformField>;\n /** How large the uniform buffer has to be. */\n readonly uniformByteLength: number;\n /** The file's declared samplers, in declaration order. */\n readonly textures: readonly ShaderTextureDeclaration[];\n}\n\n/**\n * The codec that round-trips a custom effect's `values` record through a scene file.\n *\n * @remarks\n * A schema field cannot describe these: the uniforms are declared by the `.wgsl`, so `map(f32)`\n * would drop every vector and colour uniform and `map(vec4)` would write `amount: 0.6` as four\n * floats. The codec round-trips exactly what a shader file allows — a number or an array of numbers.\n *\n * @returns The codec, for a `custom()` field.\n *\n * @internal\n */\nexport function postEffectValuesCodec(): CustomFieldCodec<Record<string, number | readonly number[]>> {\n return {\n createDefault(): Record<string, number | readonly number[]> {\n return {};\n },\n serialize(value: Record<string, number | readonly number[]>): JsonValue {\n const json: Record<string, JsonValue> = {};\n // Lexicographic, so two saves of the same state are byte-identical\n // (`docs/architecture/06-serialization-and-scene-format.md` §1).\n for (const name of Object.keys(value).toSorted()) {\n const entry = value[name];\n setOwnJsonProperty(json, name, typeof entry === \"number\" ? entry : [...(entry ?? [])]);\n }\n return json;\n },\n deserialize(json: JsonValue): Record<string, number | readonly number[]> {\n const value: Record<string, number | readonly number[]> = {};\n const object = asJsonObject(json);\n if (object === null) {\n return value;\n }\n for (const name of Object.keys(object)) {\n const entry = object[name];\n // Defined, not assigned: a `__proto__` key from a file stays a name instead of a prototype.\n if (typeof entry === \"number\") {\n setOwnJsonProperty(value, name, entry);\n } else if (Array.isArray(entry)) {\n setOwnJsonProperty(\n value,\n name,\n entry.map((component) => (typeof component === \"number\" ? component : 0)),\n );\n }\n }\n return value;\n },\n jsonSchema: {\n type: \"object\",\n additionalProperties: {\n oneOf: [{ type: \"number\" }, { type: \"array\", items: { type: \"number\" } }],\n },\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAuBA,MAAa,uBAAuB;;;;;;;;;;;;AAapC,MAAa,+BACX,OAAO,OAAO;CACZ;EAAE,MAAM;EAAc,MAAM;CAAY;CACxC;EAAE,MAAM;EAAQ,MAAM;CAAM;CAC5B;EAAE,MAAM;EAAgB,MAAM;CAAM;CACpC;EAAE,MAAM;EAAa,MAAM;CAAM;AACnC,CAAC;;;;;;;;;;;;;;AAmDH,SAAgB,aAAa,MAA8C;CACzE,OAAO;EACL,QAAQ,KAAK;EACb,SAAS,KAAK,WAAW;EACzB,OAAO,KAAK,SAAS;EACrB,QAAQ,EAAE,GAAG,KAAK,OAAO;EACzB,UAAU,EAAE,GAAG,KAAK,SAAS;CAC/B;AACF;;AAiBA,MAAM,yBAAyB;;;;;;;;;AAU/B,SAAgB,uBAAuB,OAAuB;CAC5D,OAAO,yBAAyB,QAAQ;AAC1C;;;;;;;;;;;;;AAmDA,SAAgB,wBAAsF;CACpG,OAAO;EACL,gBAA4D;GAC1D,OAAO,CAAC;EACV;EACA,UAAU,OAA8D;GACtE,MAAM,OAAkC,CAAC;GAGzC,KAAK,MAAM,QAAQ,OAAO,KAAK,KAAK,CAAC,CAAC,SAAS,GAAG;IAChD,MAAM,QAAQ,MAAM;IACpB,mBAAmB,MAAM,MAAM,OAAO,UAAU,WAAW,QAAQ,CAAC,GAAI,SAAS,CAAC,CAAE,CAAC;GACvF;GACA,OAAO;EACT;EACA,YAAY,MAA6D;GACvE,MAAM,QAAoD,CAAC;GAC3D,MAAM,SAAS,aAAa,IAAI;GAChC,IAAI,WAAW,MACb,OAAO;GAET,KAAK,MAAM,QAAQ,OAAO,KAAK,MAAM,GAAG;IACtC,MAAM,QAAQ,OAAO;IAErB,IAAI,OAAO,UAAU,UACnB,mBAAmB,OAAO,MAAM,KAAK;SAChC,IAAI,MAAM,QAAQ,KAAK,GAC5B,mBACE,OACA,MACA,MAAM,KAAK,cAAe,OAAO,cAAc,WAAW,YAAY,CAAE,CAC1E;GAEJ;GACA,OAAO;EACT;EACA,YAAY;GACV,MAAM;GACN,sBAAsB,EACpB,OAAO,CAAC,EAAE,MAAM,SAAS,GAAG;IAAE,MAAM;IAAS,OAAO,EAAE,MAAM,SAAS;GAAE,CAAC,EAC1E;EACF;CACF;AACF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { n as assertNever, o as CoreErrorCode, t as IgnifxError } from "./ignifx-error-DwIZKxA2.js";
|
|
2
|
-
import { i as declaredTextureBinding, n as POST_EFFECT_FUNCTION, t as POST_EFFECT_BUILTIN_UNIFORMS } from "./post-effect-
|
|
2
|
+
import { i as declaredTextureBinding, n as POST_EFFECT_FUNCTION, t as POST_EFFECT_BUILTIN_UNIFORMS } from "./post-effect-DEZD-r0I.js";
|
|
3
3
|
//#region src/render/post-effect-compiler.ts
|
|
4
4
|
/**
|
|
5
5
|
* Turns a `// @ignifx post` file into the fragment module and uniform layout Babylon Lite's
|
|
6
|
-
* fullscreen-effect path needs (
|
|
6
|
+
* fullscreen-effect path needs (ADR-0024).
|
|
7
7
|
*
|
|
8
8
|
* `mainFragment` is a plain function, not an entry point: Lite hard-codes the entry-point names
|
|
9
9
|
* `effectFullscreenVertex` and `effectFragment` (`lib/effect/effect-renderer.js` 7, 258-260), so the
|
|
@@ -136,7 +136,7 @@ function writePostEffectValues(effect, shader, values, out) {
|
|
|
136
136
|
* The rules are the WGSL specification's: a member's offset is its predecessor's end rounded up to
|
|
137
137
|
* the member's alignment, and the struct's size is the last member's end rounded up to the struct's
|
|
138
138
|
* alignment — the largest member alignment, and in the **uniform** address space never less than
|
|
139
|
-
* 16. `vec3<f32>` is the one that catches people out: 16-aligned, 12 wide
|
|
139
|
+
* 16. `vec3<f32>` is the one that catches people out: 16-aligned, 12 wide.
|
|
140
140
|
*
|
|
141
141
|
* @param members - The members, in declaration order.
|
|
142
142
|
* @returns The layout.
|
|
@@ -308,4 +308,4 @@ function isBuiltinUniformName(name) {
|
|
|
308
308
|
//#endregion
|
|
309
309
|
export { compilePostEffect, compiledPostEffect, writePostEffectValues };
|
|
310
310
|
|
|
311
|
-
//# sourceMappingURL=post-effect-compiler-
|
|
311
|
+
//# sourceMappingURL=post-effect-compiler-unDD3hod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"post-effect-compiler-unDD3hod.js","names":[],"sources":["../src/render/post-effect-compiler.ts"],"sourcesContent":["import { CoreErrorCode } from \"../errors/error-codes.js\";\nimport { assertNever, IgnifxError } from \"../errors/ignifx-error.js\";\nimport {\n declaredTextureBinding,\n INPUT_SAMPLER_BINDING,\n INPUT_TEXTURE_BINDING,\n POST_EFFECT_BUILTIN_UNIFORMS,\n POST_EFFECT_FUNCTION,\n} from \"./post-effect.js\";\nimport type { CompiledPostEffect, PostEffectUniformField } from \"./post-effect.js\";\nimport type { ShaderAsset } from \"./shader-asset.js\";\nimport type { ShaderUniformType } from \"./shader-declaration.js\";\n\n/**\n * Turns a `// @ignifx post` file into the fragment module and uniform layout Babylon Lite's\n * fullscreen-effect path needs (ADR-0024).\n *\n * `mainFragment` is a plain function, not an entry point: Lite hard-codes the entry-point names\n * `effectFullscreenVertex` and `effectFragment` (`lib/effect/effect-renderer.js` 7, 258-260), so the\n * entry point is generated here and forwards to it. `createEffectWrapper` takes a byte length and a\n * raw writer and computes no offsets, so the struct's member offsets are worked out here from WGSL's\n * own alignment rules and kept in step with the generated struct.\n *\n * Everything in this module is device-free and deterministic, so it is asserted in Node. It is\n * reached through `./post-effect-support.ts` so a game with no custom post effect never loads it.\n */\n\n/**\n * Compiles a `// @ignifx post` file into a full fragment module and a uniform layout.\n *\n * @remarks\n * Device-free and deterministic, so the whole thing is unit-testable: the result is a WGSL string\n * and a set of byte offsets. It is memoised per shader asset by {@link compiledPostEffect}, because\n * the chain asks for it on every rebuild.\n *\n * @param shader - The loaded shader asset.\n * @returns The compiled effect.\n * @throws IgnifxError with code `IGX-0709` when the file is not a `post` one, or `IGX-0723` when it\n * declares no `mainFragment` function.\n *\n * @example\n * ```ts\n * const compiled = compilePostEffect(vignette.value);\n * compiled.byName.get(\"amount\")?.byteOffset; // 20, right after the four built-ins\n * ```\n *\n * @internal\n */\nexport function compilePostEffect(shader: ShaderAsset): CompiledPostEffect {\n if (shader.declaration.kind !== \"post\") {\n throw new IgnifxError(\n CoreErrorCode.invalidAssetFile,\n `${shader.address} declares @ignifx ${shader.declaration.kind}, not @ignifx post.`,\n {\n context: { file: shader.address, format: \"@ignifx post\", kind: shader.declaration.kind },\n hint: \"A PostProcessStack custom effect takes a .post.wgsl file whose pragma is @ignifx post.\",\n },\n );\n }\n if (!new RegExp(`\\\\bfn\\\\s+${POST_EFFECT_FUNCTION}\\\\s*\\\\(`, \"u\").test(shader.source)) {\n throw new IgnifxError(\n CoreErrorCode.surfaceHookMissing,\n `${shader.address} declares no ${POST_EFFECT_FUNCTION} function.`,\n {\n context: { asset: shader.address, hook: POST_EFFECT_FUNCTION },\n hint: `Add fn ${POST_EFFECT_FUNCTION}(in: PostInput) -> vec4<f32>; the @fragment entry point is generated.`,\n },\n );\n }\n const declared = shader.declaration.uniforms.filter((uniform) => !isBuiltinUniformName(uniform.name));\n const layout = layOutUniforms([\n ...POST_EFFECT_BUILTIN_UNIFORMS,\n ...declared.map((uniform) => ({ name: uniform.name, type: uniform.type })),\n ]);\n const byName = new Map<string, PostEffectUniformField>();\n for (const field of layout.fields) {\n byName.set(field.name, field);\n }\n return {\n address: shader.address,\n fragmentWGSL: buildFragmentModule(shader, layout.fields),\n uniforms: layout.fields,\n byName,\n uniformByteLength: layout.byteLength,\n textures: shader.declaration.textures,\n };\n}\n\n/** The compiled form of each shader asset, so a chain rebuild recompiles nothing. */\nlet compiled: WeakMap<ShaderAsset, CompiledPostEffect> | null = null;\n\n/**\n * The compiled form of a post-effect shader, compiled once per asset.\n *\n * @remarks\n * Keyed on the `ShaderAsset` itself, so a hot reload — which replaces the asset object — recompiles\n * for free.\n *\n * @param shader - The loaded shader asset.\n * @returns The compiled effect.\n * @throws IgnifxError as {@link compilePostEffect} documents.\n *\n * @internal\n */\nexport function compiledPostEffect(shader: ShaderAsset): CompiledPostEffect {\n const cache = (compiled ??= new WeakMap<ShaderAsset, CompiledPostEffect>());\n const hit = cache.get(shader);\n if (hit !== undefined) {\n return hit;\n }\n const built = compilePostEffect(shader);\n cache.set(shader, built);\n return built;\n}\n\n/**\n * Writes an effect's current values into the bytes its uniform buffer takes.\n *\n * @remarks\n * The built-in clocks and `screenSize` are written by the caller through the same `out` buffer, so\n * this only fills in the declared members: the declaration's default first, then the settings'\n * override. Unknown names are refused, which is what makes a typo in a `.scene.json` visible.\n *\n * @param effect - The compiled effect.\n * @param shader - The shader, for its declared defaults.\n * @param values - The overrides.\n * @param out - The uniform bytes, at least `effect.uniformByteLength` long.\n * @throws IgnifxError with code `IGX-0712` for an undeclared name, or `IGX-0713` for a wrongly\n * shaped value.\n *\n * @internal\n */\nexport function writePostEffectValues(\n effect: CompiledPostEffect,\n shader: ShaderAsset,\n values: Readonly<Record<string, number | readonly number[]>>,\n out: Float32Array,\n): void {\n for (const uniform of shader.declaration.uniforms) {\n const field = effect.byName.get(uniform.name);\n if (field === undefined) {\n continue;\n }\n writeField(field, uniform.defaultValue, effect.address, out);\n }\n // `for…in` rather than `Object.keys`: the chain calls this every frame for every recorded effect\n // and a key array per effect per frame is per-frame allocation (coding standards §7).\n for (const name in values) {\n if (!Object.hasOwn(values, name)) {\n continue;\n }\n const field = effect.byName.get(name);\n const value = values[name];\n if (value === undefined) {\n continue;\n }\n if (field === undefined || isBuiltinUniformName(name)) {\n throw new IgnifxError(\n CoreErrorCode.unknownShaderBinding,\n `${effect.address} declares no uniform named ${name}.`,\n {\n context: { material: effect.address, asset: effect.address, name },\n hint: `It declares ${[...effect.byName.keys()].join(\", \")}.`,\n },\n );\n }\n writeField(field, value, effect.address, out);\n }\n}\n\n/** The result of laying out a uniform struct. */\ninterface UniformLayout {\n /** The members, in struct order. */\n readonly fields: readonly PostEffectUniformField[];\n /** The struct's size, in bytes. */\n readonly byteLength: number;\n}\n\n/**\n * Computes the byte offsets WGSL gives a struct of these members, in this order.\n *\n * @remarks\n * The rules are the WGSL specification's: a member's offset is its predecessor's end rounded up to\n * the member's alignment, and the struct's size is the last member's end rounded up to the struct's\n * alignment — the largest member alignment, and in the **uniform** address space never less than\n * 16. `vec3<f32>` is the one that catches people out: 16-aligned, 12 wide.\n *\n * @param members - The members, in declaration order.\n * @returns The layout.\n */\nfunction layOutUniforms(\n members: readonly { readonly name: string; readonly type: ShaderUniformType }[],\n): UniformLayout {\n const fields: PostEffectUniformField[] = [];\n let offset = 0;\n // WGSL's uniform address space rounds a struct's alignment up to a multiple of 16, so the block's\n // size is always a multiple of 16 whatever its members are.\n let structAlignment = 16;\n for (const member of members) {\n const alignment = typeAlignment(member.type);\n const size = typeSize(member.type);\n structAlignment = Math.max(structAlignment, alignment);\n offset = roundUp(offset, alignment);\n fields.push({\n name: member.name,\n type: member.type,\n components: componentCount(member.type),\n byteOffset: offset,\n });\n offset += size;\n }\n return { fields, byteLength: roundUp(offset, structAlignment) };\n}\n\n/**\n * A WGSL type's alignment in the uniform address space, in bytes.\n *\n * @param type - The type.\n * @returns The alignment.\n */\nfunction typeAlignment(type: ShaderUniformType): number {\n switch (type) {\n case \"vec2<f32>\": {\n return 8;\n }\n case \"vec3<f32>\":\n case \"vec4<f32>\":\n case \"mat4x4<f32>\": {\n return 16;\n }\n case \"f32\":\n case \"u32\":\n case \"i32\": {\n return 4;\n }\n default: {\n return assertNever(type, \"shader uniform type\");\n }\n }\n}\n\n/**\n * A WGSL type's size, in bytes.\n *\n * @param type - The type.\n * @returns The size.\n */\nfunction typeSize(type: ShaderUniformType): number {\n switch (type) {\n case \"vec2<f32>\": {\n return 8;\n }\n case \"vec3<f32>\": {\n return 12;\n }\n case \"vec4<f32>\": {\n return 16;\n }\n case \"mat4x4<f32>\": {\n return 64;\n }\n case \"f32\":\n case \"u32\":\n case \"i32\": {\n return 4;\n }\n default: {\n return assertNever(type, \"shader uniform type\");\n }\n }\n}\n\n/**\n * How many floats one uniform of a declared type occupies.\n *\n * @remarks\n * A private copy of `material-plugin.ts`'s `uniformComponentCount`. `PostProcessStack` is in every\n * game's static graph, and importing it from there would drag `defineMaterialPlugin` and the\n * reserved-name table into a bundle that draws no custom shader at all.\n *\n * @param type - The declared WGSL type.\n * @returns The component count: 1, 2, 3, 4, or 16.\n */\nfunction componentCount(type: ShaderUniformType): number {\n switch (type) {\n case \"vec2<f32>\": {\n return 2;\n }\n case \"vec3<f32>\": {\n return 3;\n }\n case \"vec4<f32>\": {\n return 4;\n }\n case \"mat4x4<f32>\": {\n return 16;\n }\n case \"f32\":\n case \"u32\":\n case \"i32\": {\n return 1;\n }\n default: {\n return assertNever(type, \"shader uniform type\");\n }\n }\n}\n\n/**\n * Rounds a value up to a multiple of an alignment.\n *\n * @param value - The value.\n * @param alignment - The alignment, a power of two.\n * @returns The rounded value.\n */\nfunction roundUp(value: number, alignment: number): number {\n return Math.ceil(value / alignment) * alignment;\n}\n\n/**\n * The whole fragment module: bindings, generated structs, the author's file, and the entry point\n * Lite's pipeline looks for.\n *\n * @param shader - The shader asset.\n * @param fields - The uniform members, in struct order.\n * @returns The WGSL.\n */\nfunction buildFragmentModule(shader: ShaderAsset, fields: readonly PostEffectUniformField[]): string {\n const members = fields.map((field) => `${field.name}:${field.type},`).join(\"\");\n const lines: string[] = [\n `struct PostUniforms{${members}}`,\n \"@group(0)@binding(0)var<uniform>shaderUniforms:PostUniforms;\",\n `@group(0)@binding(${String(INPUT_TEXTURE_BINDING)})var inputTexture:texture_2d<f32>;`,\n `@group(0)@binding(${String(INPUT_SAMPLER_BINDING)})var inputTextureSampler:sampler;`,\n ];\n // `for…of` with an index: the iterator yields the element type rather than `T | undefined`, and\n // this runs once per compiled shader rather than per frame.\n let index = -1;\n for (const declaration of shader.declaration.textures) {\n index += 1;\n const binding = declaredTextureBinding(index);\n const type = declaration.array ? \"texture_2d_array<f32>\" : \"texture_2d<f32>\";\n lines.push(\n `@group(0)@binding(${String(binding)})var ${declaration.name}:${type};`,\n `@group(0)@binding(${String(binding + 1)})var ${declaration.name}Sampler:sampler;`,\n );\n }\n lines.push(\n \"struct PostInput{uv:vec2<f32>,position:vec2<f32>,}\",\n shader.source,\n \"@fragment fn effectFragment(fragment:EffectVertexOutput)->@location(0)vec4<f32>{\",\n \"var ignifxPostInput:PostInput;\",\n // Lite's effect vertex puts uv (0, 0) at the bottom-left, but a texture's origin is the top-left,\n // so an unflipped uv mirrors the frame on every pass (`lib/effect/effect-renderer.js` 7).\n \"ignifxPostInput.uv=vec2<f32>(fragment.uv.x,1.0-fragment.uv.y);\",\n \"ignifxPostInput.position=fragment.position.xy;\",\n `return ${POST_EFFECT_FUNCTION}(ignifxPostInput);`,\n \"}\",\n );\n return lines.join(\"\\n\");\n}\n\n/**\n * Writes one member's value into the uniform bytes.\n *\n * @param field - The member.\n * @param value - The value.\n * @param asset - The shader's address, for diagnostics.\n * @param out - The uniform floats.\n * @throws IgnifxError with code `IGX-0713` when the shape does not match.\n */\nfunction writeField(\n field: PostEffectUniformField,\n value: number | readonly number[],\n asset: string,\n out: Float32Array,\n): void {\n const index = field.byteOffset / 4;\n if (typeof value === \"number\") {\n if (field.components !== 1) {\n throw mismatch(field, asset, \"a single number\");\n }\n out[index] = value;\n return;\n }\n if (value.length !== field.components) {\n throw mismatch(field, asset, `${String(value.length)} floats`);\n }\n out.set(value instanceof Float32Array ? value : Float32Array.from(value), index);\n}\n\n/**\n * The `IGX-0713` failure a wrongly shaped value produces.\n *\n * @param field - The member.\n * @param asset - The shader's address.\n * @param actual - What the caller passed.\n * @returns The error to throw.\n */\nfunction mismatch(field: PostEffectUniformField, asset: string, actual: string): IgnifxError {\n return new IgnifxError(\n CoreErrorCode.shaderValueMismatch,\n `${field.name} on ${asset} expects ${field.type} (${String(field.components)} floats), not ${actual}.`,\n {\n context: { name: field.name, material: asset, expected: field.type, actual },\n hint: \"A post effect's values are numbers and numeric arrays; a colour takes its three or four components.\",\n },\n );\n}\n\n/**\n * Whether a name is one of the four uniforms every post effect gets for free.\n *\n * @param name - The candidate.\n * @returns `true` when the engine writes it.\n */\nfunction isBuiltinUniformName(name: string): boolean {\n for (const builtin of POST_EFFECT_BUILTIN_UNIFORMS) {\n if (builtin.name === name) {\n return true;\n }\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,kBAAkB,QAAyC;CACzE,IAAI,OAAO,YAAY,SAAS,QAC9B,MAAM,IAAI,YACR,cAAc,kBACd,GAAG,OAAO,QAAQ,oBAAoB,OAAO,YAAY,KAAK,sBAC9D;E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A,SAAS,WACP,OACA,OACA,OACA,KACM;CACN,MAAM,QAAQ,MAAM,aAAa;CACjC,IAAI,OAAO,UAAU,UAAU;EAC7B,IAAI,MAAM,eAAe,GACvB,MAAM,SAAS,OAAO,OAAO,iBAAiB;EAEhD,IAAI,SAAS;EACb;CACF;CACA,IAAI,MAAM,WAAW,MAAM,YACzB,MAAM,SAAS,OAAO,OAAO,GAAG,OAAO,MAAM,MAAM,EAAE,QAAQ;CAE/D,IAAI,IAAI,iBAAiB,eAAe,QAAQ,aAAa,KAAK,KAAK,GAAG,KAAK;AACjF;;;;;;;;;AAUA,SAAS,SAAS,OAA+B,OAAe,QAA6B;CAC3F,OAAO,IAAI,YACT,cAAc,qBACd,GAAG,MAAM,KAAK,MAAM,MAAM,WAAW,MAAM,KAAK,IAAI,OAAO,MAAM,UAAU,EAAE,gBAAgB,OAAO,IACpG;EACE,SAAS;GAAE,MAAM,MAAM;GAAM,UAAU;GAAO,UAAU,MAAM;GAAM;EAAO;EAC3E,MAAM;CACR,CACF;AACF;;;;;;;AAQA,SAAS,qBAAqB,MAAuB;CACnD,KAAK,MAAM,WAAW,8BACpB,IAAI,QAAQ,SAAS,MACnB,OAAO;CAGX,OAAO;AACT"}
|
|
@@ -1210,8 +1210,8 @@ function isSceneFileHeader(value) {
|
|
|
1210
1210
|
/**
|
|
1211
1211
|
* The draft 2020-12 JSON Schema for a scene file, with `components[].props` narrowed per registered
|
|
1212
1212
|
* component `typeId` (`docs/architecture/06-serialization-and-scene-format.md` §8). The Vite plugin
|
|
1213
|
-
*
|
|
1214
|
-
*
|
|
1213
|
+
* validates scene files against it at build time when a project supplies it
|
|
1214
|
+
* (`ignifx({ schemas })`); written to a file, it gives an editor autocompletion for scene files.
|
|
1215
1215
|
*
|
|
1216
1216
|
* @param registry - The component table whose registered classes narrow `props`. Classes without a
|
|
1217
1217
|
* schema contribute a `type` match with a free-form `props` object.
|
|
@@ -2830,4 +2830,4 @@ function withOverrides(instance, overrides, hash) {
|
|
|
2830
2830
|
//#endregion
|
|
2831
2831
|
export { childPath as A, MEMORY_ADDRESS_PREFIX as B, canonicalizeNumber as C, encodeValue as D, encodeProps as E, asJsonObject as F, splitFragment as G, joinRoot as H, setOwnJsonProperty as I, SchemaIssueCode as L, isArray as M, isPlainObject as N, COLOR_CHANNELS as O, asJsonArray as P, issue as R, toJsonSchema as S, decodeValue as T, matchExtension as U, isAbsoluteAddress as V, normalizeExtension as W, describeSceneFileFormat as _, applyOverrides as a, stringifySceneFile as b, remapInstancePath as c, createSceneAsset as d, findSceneDependency as f, SCENE_FORMAT_VERSION as g, SCENE_FILE_FORMAT as h, resolveInstancePath as i, indexPath as j, VECTOR_COMPONENTS as k, SceneAssetToken as l, SCENE_FILE_EXTENSIONS as m, revertOverrides as n, parseOverridePath as o, SCENE_ASSET_TYPE as p, enumerateInstanceTargets as r, instancePathResolver as s, applyOverridesToAsset as t, computeSceneHash as u, isSceneFileHeader as v, decodeProps as w, describeSchema as x, sceneFileJsonSchema as y, throwSchemaError as z };
|
|
2832
2832
|
|
|
2833
|
-
//# sourceMappingURL=prefab-overrides-
|
|
2833
|
+
//# sourceMappingURL=prefab-overrides-Bb7jVm7A.js.map
|