@ignifx/core 0.14.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/decoders/draco3dgltf.LICENSE.md +201 -0
- package/decoders/draco_decoder.js +116 -0
- package/decoders/draco_decoder_gltf.wasm +0 -0
- package/decoders/vendored.json +22 -0
- package/dist/agx-tone-mapping-Cgt844j6.js +53 -0
- package/dist/agx-tone-mapping-Cgt844j6.js.map +1 -0
- package/dist/auto-exposure-uzPn0beO.js +246 -0
- package/dist/auto-exposure-uzPn0beO.js.map +1 -0
- package/dist/bloom-hdr-CLtQj-oY.js +315 -0
- package/dist/bloom-hdr-CLtQj-oY.js.map +1 -0
- package/dist/contact-shadows-T523EXaP.js +84 -0
- package/dist/contact-shadows-T523EXaP.js.map +1 -0
- package/dist/{decoders-CHJ7vduE.js → decoders-BUQrlS8U.js} +3 -2
- package/dist/decoders-BUQrlS8U.js.map +1 -0
- package/dist/{environment-Cq2BmA96.js → environment-DPi0_0SP.js} +18 -4
- package/dist/environment-DPi0_0SP.js.map +1 -0
- package/dist/gtao-_nr0b6-E.js +630 -0
- package/dist/gtao-_nr0b6-E.js.map +1 -0
- package/dist/hdr-output-BrUvpAsE.js +525 -0
- package/dist/hdr-output-BrUvpAsE.js.map +1 -0
- package/dist/index.d.ts +509 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1522 -512
- package/dist/index.js.map +1 -1
- package/dist/{instanced-mesh-instance-DYwH0vLi.js → instanced-mesh-instance-NnODkvqK.js} +2 -2
- package/dist/{instanced-mesh-instance-DYwH0vLi.js.map → instanced-mesh-instance-NnODkvqK.js.map} +1 -1
- package/dist/mat4-D6exvAuO.js +949 -0
- package/dist/mat4-D6exvAuO.js.map +1 -0
- package/dist/{render-path-Dx0learj.js → render-path-Be7WgN7r.js} +35 -4
- package/dist/render-path-Be7WgN7r.js.map +1 -0
- package/dist/{render-texture-IuR0iFVa.js → render-texture-C_TnaSz2.js} +28 -2
- package/dist/render-texture-C_TnaSz2.js.map +1 -0
- package/dist/scene-color-passes-DlNr-qyZ.js +65 -0
- package/dist/scene-color-passes-DlNr-qyZ.js.map +1 -0
- package/dist/scene-inputs-BxGOsnIZ.js +318 -0
- package/dist/scene-inputs-BxGOsnIZ.js.map +1 -0
- package/dist/{shader-material-CDQ0Y5kN.js → shader-material-B6p66wB8.js} +17 -6
- package/dist/shader-material-B6p66wB8.js.map +1 -0
- package/dist/{shader-material-BPb_oEZQ.js → shader-material-C0TAUr4t.js} +102 -4
- package/dist/shader-material-C0TAUr4t.js.map +1 -0
- package/dist/ssgi-Dm-maZrc.js +113 -0
- package/dist/ssgi-Dm-maZrc.js.map +1 -0
- package/dist/{surface-shader-CwQ03yHG.js → surface-shader-BaK0kvBB.js} +2 -2
- package/dist/{surface-shader-CwQ03yHG.js.map → surface-shader-BaK0kvBB.js.map} +1 -1
- package/dist/taa-BwBZLy11.js +480 -0
- package/dist/taa-BwBZLy11.js.map +1 -0
- package/dist/{vec3-T2PasQZv.js → vec3-D-0Y2mzE.js} +4 -948
- package/dist/vec3-D-0Y2mzE.js.map +1 -0
- package/package.json +4 -2
- package/dist/decoders-CHJ7vduE.js.map +0 -1
- package/dist/environment-Cq2BmA96.js.map +0 -1
- package/dist/hdr-output-DDpIo4Q5.js +0 -300
- package/dist/hdr-output-DDpIo4Q5.js.map +0 -1
- package/dist/render-path-Dx0learj.js.map +0 -1
- package/dist/render-texture-IuR0iFVa.js.map +0 -1
- package/dist/shader-material-BPb_oEZQ.js.map +0 -1
- package/dist/shader-material-CDQ0Y5kN.js.map +0 -1
- package/dist/vec3-T2PasQZv.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as readSceneEnvironment } from "./environment-
|
|
1
|
+
import { i as readSceneEnvironment } from "./environment-DPi0_0SP.js";
|
|
2
2
|
import { createShaderMaterial, createTexture2DArrayFromPixels, createTexture2DFromPixels, enableShaderMaterialUniformCaching, setShaderMatrix, setShaderStorageBuffer, setShaderTexture, setShaderUniform } from "@babylonjs/lite";
|
|
3
3
|
//#region src/lite/gpu/shader-material.ts
|
|
4
4
|
/** The RGBA bytes of each 1x1 fallback texture. */
|
|
@@ -36,10 +36,11 @@ const FALLBACK_PIXELS = Object.freeze({
|
|
|
36
36
|
* @internal
|
|
37
37
|
*/
|
|
38
38
|
function createShaderMaterialFromOptions(options) {
|
|
39
|
+
const premultiplied = options.blend?.color.srcFactor === "one";
|
|
39
40
|
return createShaderMaterial({
|
|
40
41
|
name: options.name,
|
|
41
42
|
vertexSource: options.source,
|
|
42
|
-
fragmentSource: options.source,
|
|
43
|
+
fragmentSource: options.linearOutput === true ? linearOutputFragment(options.source, premultiplied) : options.source,
|
|
43
44
|
attributes: options.attributes,
|
|
44
45
|
uniforms: options.uniforms,
|
|
45
46
|
samplers: options.samplers,
|
|
@@ -55,6 +56,103 @@ function createShaderMaterialFromOptions(options) {
|
|
|
55
56
|
...options.depthCompare === null ? {} : { depthCompare: options.depthCompare }
|
|
56
57
|
});
|
|
57
58
|
}
|
|
59
|
+
/** The name a wrapped `mainFragment` is renamed to. */
|
|
60
|
+
const WRAPPED_FRAGMENT = "ignifxDisplayFragment";
|
|
61
|
+
/**
|
|
62
|
+
* Wraps a custom shader's `mainFragment` so that, under `rendering.hdr`, it writes linear colour
|
|
63
|
+
* (`docs/plan/2026-11-gi-phase-1-execution-plan.md`, step G3).
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* A custom shader writes the colour that is displayed: with HDR off it lands on the swapchain as
|
|
67
|
+
* is. With HDR on it lands in the linear scene target and the output pass encodes it, so the
|
|
68
|
+
* wrapper decodes it first with the exact inverse of that encode (`pow(c, 2.2)`). The user's entry
|
|
69
|
+
* point loses its `@fragment` and is renamed; a new `mainFragment` with the same parameters calls
|
|
70
|
+
* it. A premultiplied colour is divided by alpha before the decode and multiplied after it, so the
|
|
71
|
+
* blend still sees premultiplied colour. Only a single `@location(0) vec4<f32>` return can be
|
|
72
|
+
* wrapped; anything else (a struct of outputs) is returned unchanged.
|
|
73
|
+
*
|
|
74
|
+
* @param source - The `.wgsl` file.
|
|
75
|
+
* @param premultiplied - Whether the material blends premultiplied colour.
|
|
76
|
+
* @returns The fragment source.
|
|
77
|
+
*
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
function linearOutputFragment(source, premultiplied) {
|
|
81
|
+
const entry = /@fragment\s+fn\s+mainFragment\s*\(/u.exec(source);
|
|
82
|
+
if (entry === null) return source;
|
|
83
|
+
const open = entry.index + entry[0].length - 1;
|
|
84
|
+
const close = matchingParen(source, open);
|
|
85
|
+
if (close < 0) return source;
|
|
86
|
+
const after = source.slice(close + 1);
|
|
87
|
+
const result = /^\s*->\s*@location\(\s*0\s*\)\s*vec4\s*<\s*f32\s*>\s*\{/u.exec(after);
|
|
88
|
+
if (result === null) return source;
|
|
89
|
+
const parameters = source.slice(open + 1, close);
|
|
90
|
+
const names = parameterNames(parameters);
|
|
91
|
+
const decode = premultiplied ? "select(pow(max(c.rgb,vec3<f32>(0.0)),vec3<f32>(2.2)),pow(max(c.rgb/c.a,vec3<f32>(0.0)),vec3<f32>(2.2))*c.a,c.a>0.0)" : "pow(max(c.rgb,vec3<f32>(0.0)),vec3<f32>(2.2))";
|
|
92
|
+
return [
|
|
93
|
+
`${source.slice(0, entry.index)}fn ${WRAPPED_FRAGMENT}(${stripAttributes(parameters)})->vec4<f32>{${after.slice(result[0].length)}`,
|
|
94
|
+
`@fragment fn mainFragment(${parameters})->@location(0) vec4<f32>{`,
|
|
95
|
+
`let c=${WRAPPED_FRAGMENT}(${names.join(",")});`,
|
|
96
|
+
`return vec4<f32>(${decode},c.a);`,
|
|
97
|
+
"}"
|
|
98
|
+
].join("\n");
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Finds the parenthesis that closes the one at `open`.
|
|
102
|
+
*
|
|
103
|
+
* @param text - The source.
|
|
104
|
+
* @param open - The index of a `(`.
|
|
105
|
+
* @returns The index of its `)`, or `-1`.
|
|
106
|
+
*/
|
|
107
|
+
function matchingParen(text, open) {
|
|
108
|
+
let depth = 0;
|
|
109
|
+
for (let index = open; index < text.length; index += 1) {
|
|
110
|
+
const char = text[index];
|
|
111
|
+
if (char === "(") depth += 1;
|
|
112
|
+
else if (char === ")") {
|
|
113
|
+
depth -= 1;
|
|
114
|
+
if (depth === 0) return index;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return -1;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Removes WGSL attributes (`@builtin(position)`, `@location(0)`, `@interpolate(flat)`) from a
|
|
121
|
+
* parameter list, which a plain function's parameters may not carry.
|
|
122
|
+
*
|
|
123
|
+
* @param parameters - The parameter list.
|
|
124
|
+
* @returns The list without attributes.
|
|
125
|
+
*/
|
|
126
|
+
function stripAttributes(parameters) {
|
|
127
|
+
return parameters.replaceAll(/@\w+\s*(\([^)]*\))?\s*/gu, "");
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The parameter names of a WGSL parameter list, attributes stripped.
|
|
131
|
+
*
|
|
132
|
+
* @param parameters - The text between an entry point's parentheses.
|
|
133
|
+
* @returns The names, in order.
|
|
134
|
+
*/
|
|
135
|
+
function parameterNames(parameters) {
|
|
136
|
+
const names = [];
|
|
137
|
+
let depth = 0;
|
|
138
|
+
let start = 0;
|
|
139
|
+
const take = (end) => {
|
|
140
|
+
const piece = stripAttributes(parameters.slice(start, end)).trim();
|
|
141
|
+
const colon = piece.indexOf(":");
|
|
142
|
+
if (colon > 0) names.push(piece.slice(0, colon).trim());
|
|
143
|
+
};
|
|
144
|
+
for (let index = 0; index < parameters.length; index += 1) {
|
|
145
|
+
const char = parameters[index];
|
|
146
|
+
if (char === "(" || char === "<") depth += 1;
|
|
147
|
+
else if (char === ")" || char === ">") depth -= 1;
|
|
148
|
+
else if (char === "," && depth === 0) {
|
|
149
|
+
take(index);
|
|
150
|
+
start = index + 1;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
take(parameters.length);
|
|
154
|
+
return names;
|
|
155
|
+
}
|
|
58
156
|
/**
|
|
59
157
|
* Writes a declared scalar, vector, or matrix uniform.
|
|
60
158
|
*
|
|
@@ -202,6 +300,6 @@ function readSceneAmbient(scene, out) {
|
|
|
202
300
|
return true;
|
|
203
301
|
}
|
|
204
302
|
//#endregion
|
|
205
|
-
export { createFallbackTexture, createShaderMaterialFromOptions, enableShaderUniformCaching, readSceneAmbient, resolveFallbackTexture, writeShaderMatrix, writeShaderStorageBuffer, writeShaderTexture, writeShaderUniform };
|
|
303
|
+
export { createFallbackTexture, createShaderMaterialFromOptions, enableShaderUniformCaching, linearOutputFragment, readSceneAmbient, resolveFallbackTexture, writeShaderMatrix, writeShaderStorageBuffer, writeShaderTexture, writeShaderUniform };
|
|
206
304
|
|
|
207
|
-
//# sourceMappingURL=shader-material-
|
|
305
|
+
//# sourceMappingURL=shader-material-C0TAUr4t.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shader-material-C0TAUr4t.js","names":[],"sources":["../src/lite/gpu/shader-material.ts"],"sourcesContent":["import {\n createShaderMaterial,\n createTexture2DArrayFromPixels,\n createTexture2DFromPixels,\n enableShaderMaterialUniformCaching,\n setShaderMatrix,\n setShaderStorageBuffer,\n setShaderTexture,\n setShaderUniform,\n} from \"@babylonjs/lite\";\nimport { readSceneEnvironment } from \"./environment.js\";\nimport type {\n EngineContext,\n SceneContext,\n ShaderAttributeName,\n ShaderMaterial,\n ShaderSystemUniformName,\n ShaderUniformType,\n StorageBuffer,\n Texture2D,\n} from \"@babylonjs/lite\";\n\n/**\n * The custom-WGSL half of the Babylon Lite adapter: `createShaderMaterial`, the `setShader*`\n * setters, and the 1x1 fallback textures a declared sampler falls back to\n * (`docs/plan/2026-09-terrain-particles-shaders.md` §3.1, ADR-0024). Everything here is `@internal`.\n *\n * Lite exports one barrel, so a static import of `createShaderMaterial` anywhere in the reachable\n * graph pulls `lib/material/shader/**` into every entry chunk. This module is therefore reached with\n * `await import(...)` from `../../render/shader-support.ts`, and only loading a `.wgsl` triggers the\n * fetch. `./storage-buffer.ts` is a separate file for the same reason: `StorageBufferAsset`\n * allocates synchronously, so it cannot wait for this chunk.\n *\n * Two Lite facts it is written around:\n *\n * - Nothing may be left unbound: `createShaderBindGroup` throws (errors 309 and 310) when a declared\n * sampler has no texture or a declared storage buffer has no buffer, which is what\n * {@link createFallbackTexture} exists for.\n * - There is no front-face culling; `ShaderMaterialOptions` carries only `backFaceCulling`\n * (`lib/material/shader/shader-pipeline.js`), so the pragma parser refuses `cull front`.\n */\n\n/**\n * A Babylon Lite custom WGSL material, re-exported under an ignifx name\n * (`CONSTITUTION.md` §3.4, coding standards §4).\n *\n * @remarks\n * Unstable; excluded from the stability guarantees of `CONSTITUTION.md` Article IV.\n *\n * @public\n */\nexport type LiteShaderMaterial = ShaderMaterial;\n\n/** The RGBA bytes of each 1x1 fallback texture. */\nconst FALLBACK_PIXELS: Readonly<Record<string, readonly [number, number, number, number]>> = Object.freeze({\n white: [255, 255, 255, 255],\n black: [0, 0, 0, 255],\n transparent: [0, 0, 0, 0],\n});\n\n/**\n * One declared uniform in the form Babylon Lite's factory takes: either the name of a system\n * uniform it fills in itself, or a custom declaration with its initial value.\n *\n * @internal\n */\nexport type ShaderUniformEntry =\n | ShaderSystemUniformName\n | {\n /** The WGSL identifier. */\n readonly name: string;\n /** The WGSL type. */\n readonly type: ShaderUniformType;\n /** The initial value, **linear** for a colour. */\n readonly defaultValue: number | readonly number[];\n };\n\n/**\n * One declared sampler in the form Babylon Lite's factory takes.\n *\n * @internal\n */\nexport interface ShaderSamplerEntry {\n /** The WGSL identifier; Lite generates `<name>Sampler` beside it. */\n readonly name: string;\n /** `\"2d-array\"` for a `texture_2d_array<f32>` binding. */\n readonly viewDimension: \"2d\" | \"2d-array\";\n}\n\n/**\n * One declared storage buffer in the form Babylon Lite's factory takes.\n *\n * @internal\n */\nexport interface ShaderStorageEntry {\n /** The WGSL identifier. */\n readonly name: string;\n /** The WGSL variable type, verbatim. */\n readonly type: string;\n}\n\n/**\n * Everything Babylon Lite's `createShaderMaterial` needs, in ignifx's own vocabulary so that the\n * mapping from a `ShaderDeclaration` can be built and asserted without a device or a Lite import\n * (`src/render/shader-material.ts`).\n *\n * @remarks\n * A `null` blend state or depth comparison means \"leave Babylon Lite's own default in place\", so\n * this module never restates a Lite default that could change.\n *\n * @internal\n */\nexport interface ShaderMaterialBuildOptions {\n /** The material's name, used in pipeline and shader-module labels. */\n readonly name: string;\n /** The WGSL source, handed to Lite as both the vertex and the fragment source. */\n readonly source: string;\n /**\n * Whether the scene renders through `rendering.hdr`, where the fragment's display colour is\n * decoded to linear before it is written (see {@link linearOutputFragment}). Absent means `false`.\n */\n readonly linearOutput?: boolean;\n /** The vertex attributes the vertex stage reads; `position` is mandatory. */\n readonly attributes: readonly ShaderAttributeName[];\n /** The system and custom uniforms, in binding-declaration order. */\n readonly uniforms: readonly ShaderUniformEntry[];\n /** The samplers. */\n readonly samplers: readonly ShaderSamplerEntry[];\n /** The read-only storage buffers. */\n readonly storageBuffers: readonly ShaderStorageEntry[];\n /** The WGSL `const` declarations, resolved from the file's defaults and the material's overrides. */\n readonly defines: Readonly<Record<string, boolean | number>>;\n /** Whether the thin-instance RGBA stream is bound and injected into `VertexInput`. */\n readonly useThinInstanceColors: boolean;\n /** Whether the surface is alpha-blended. */\n readonly needAlphaBlending: boolean;\n /** Which of Lite's two blend equations to use when no explicit state is given. */\n readonly blendMode: \"alpha\" | \"additive\";\n /** An explicit colour-target blend state, which replaces the derived one; `null` to derive it. */\n readonly blend: GPUBlendState | null;\n /** Whether the surface samples the opaque scene colour behind it. */\n readonly transmissive: boolean;\n /** Whether back faces are culled. */\n readonly backFaceCulling: boolean;\n /** Whether the draw writes depth. */\n readonly depthWrite: boolean;\n /** The depth comparison, or `null` for Lite's own reverse-Z default. */\n readonly depthCompare: GPUCompareFunction | null;\n}\n\n/**\n * Builds a Babylon Lite custom WGSL material.\n *\n * @remarks\n * Validation is eager and compilation is lazy, so this runs under the null engine; the pipeline is\n * compiled the first time a mesh wearing the material is drawn.\n *\n * @param options - The sources and the declared attribute, uniform, sampler, and storage layout.\n * @returns The material.\n * @throws Error from Babylon Lite when the declaration is not one it can build.\n *\n * @internal\n */\nexport function createShaderMaterialFromOptions(options: ShaderMaterialBuildOptions): ShaderMaterial {\n const premultiplied = options.blend?.color.srcFactor === \"one\";\n return createShaderMaterial({\n name: options.name,\n vertexSource: options.source,\n fragmentSource:\n options.linearOutput === true ? linearOutputFragment(options.source, premultiplied) : options.source,\n attributes: options.attributes,\n uniforms: options.uniforms,\n samplers: options.samplers,\n storageBuffers: options.storageBuffers,\n defines: options.defines,\n useThinInstanceColors: options.useThinInstanceColors,\n needAlphaBlending: options.needAlphaBlending,\n blendMode: options.blendMode,\n ...(options.blend === null ? {} : { blend: options.blend }),\n transmissive: options.transmissive,\n backFaceCulling: options.backFaceCulling,\n depthWrite: options.depthWrite,\n ...(options.depthCompare === null ? {} : { depthCompare: options.depthCompare }),\n });\n}\n\n/** The name a wrapped `mainFragment` is renamed to. */\nconst WRAPPED_FRAGMENT = \"ignifxDisplayFragment\";\n\n/**\n * Wraps a custom shader's `mainFragment` so that, under `rendering.hdr`, it writes linear colour\n * (`docs/plan/2026-11-gi-phase-1-execution-plan.md`, step G3).\n *\n * @remarks\n * A custom shader writes the colour that is displayed: with HDR off it lands on the swapchain as\n * is. With HDR on it lands in the linear scene target and the output pass encodes it, so the\n * wrapper decodes it first with the exact inverse of that encode (`pow(c, 2.2)`). The user's entry\n * point loses its `@fragment` and is renamed; a new `mainFragment` with the same parameters calls\n * it. A premultiplied colour is divided by alpha before the decode and multiplied after it, so the\n * blend still sees premultiplied colour. Only a single `@location(0) vec4<f32>` return can be\n * wrapped; anything else (a struct of outputs) is returned unchanged.\n *\n * @param source - The `.wgsl` file.\n * @param premultiplied - Whether the material blends premultiplied colour.\n * @returns The fragment source.\n *\n * @internal\n */\nexport function linearOutputFragment(source: string, premultiplied: boolean): string {\n const entry = /@fragment\\s+fn\\s+mainFragment\\s*\\(/u.exec(source);\n if (entry === null) {\n return source;\n }\n const open = entry.index + entry[0].length - 1;\n const close = matchingParen(source, open);\n if (close < 0) {\n return source;\n }\n const after = source.slice(close + 1);\n const result = /^\\s*->\\s*@location\\(\\s*0\\s*\\)\\s*vec4\\s*<\\s*f32\\s*>\\s*\\{/u.exec(after);\n if (result === null) {\n return source;\n }\n const parameters = source.slice(open + 1, close);\n const names = parameterNames(parameters);\n const decode = premultiplied\n ? \"select(pow(max(c.rgb,vec3<f32>(0.0)),vec3<f32>(2.2)),pow(max(c.rgb/c.a,vec3<f32>(0.0)),vec3<f32>(2.2))*c.a,c.a>0.0)\"\n : \"pow(max(c.rgb,vec3<f32>(0.0)),vec3<f32>(2.2))\";\n return [\n // A plain function may not carry the entry point's `@location(0)` on its return type.\n `${source.slice(0, entry.index)}fn ${WRAPPED_FRAGMENT}(${stripAttributes(parameters)})->vec4<f32>{${after.slice(result[0].length)}`,\n `@fragment fn mainFragment(${parameters})->@location(0) vec4<f32>{`,\n `let c=${WRAPPED_FRAGMENT}(${names.join(\",\")});`,\n `return vec4<f32>(${decode},c.a);`,\n \"}\",\n ].join(\"\\n\");\n}\n\n/**\n * Finds the parenthesis that closes the one at `open`.\n *\n * @param text - The source.\n * @param open - The index of a `(`.\n * @returns The index of its `)`, or `-1`.\n */\nfunction matchingParen(text: string, open: number): number {\n let depth = 0;\n for (let index = open; index < text.length; index += 1) {\n const char = text[index];\n if (char === \"(\") {\n depth += 1;\n } else if (char === \")\") {\n depth -= 1;\n if (depth === 0) {\n return index;\n }\n }\n }\n return -1;\n}\n\n/**\n * Removes WGSL attributes (`@builtin(position)`, `@location(0)`, `@interpolate(flat)`) from a\n * parameter list, which a plain function's parameters may not carry.\n *\n * @param parameters - The parameter list.\n * @returns The list without attributes.\n */\nfunction stripAttributes(parameters: string): string {\n return parameters.replaceAll(/@\\w+\\s*(\\([^)]*\\))?\\s*/gu, \"\");\n}\n\n/**\n * The parameter names of a WGSL parameter list, attributes stripped.\n *\n * @param parameters - The text between an entry point's parentheses.\n * @returns The names, in order.\n */\nfunction parameterNames(parameters: string): string[] {\n const names: string[] = [];\n let depth = 0;\n let start = 0;\n const take = (end: number): void => {\n const piece = stripAttributes(parameters.slice(start, end)).trim();\n const colon = piece.indexOf(\":\");\n if (colon > 0) {\n names.push(piece.slice(0, colon).trim());\n }\n };\n for (let index = 0; index < parameters.length; index += 1) {\n const char = parameters[index];\n if (char === \"(\" || char === \"<\") {\n depth += 1;\n } else if (char === \")\" || char === \">\") {\n depth -= 1;\n } else if (char === \",\" && depth === 0) {\n take(index);\n start = index + 1;\n }\n }\n take(parameters.length);\n return names;\n}\n\n/**\n * Writes a declared scalar, vector, or matrix uniform.\n *\n * @remarks\n * Lite compares the incoming numbers with the ones it holds and bumps the material's uniform\n * version only when one changed, so calling this every frame with an unchanged value costs a few\n * comparisons and no upload (`lib/material/shader/shader-material.js`, `setUniformValue`).\n *\n * @param material - The material to write to.\n * @param name - The declared uniform name.\n * @param value - The value; its length must match the declared type.\n * @throws Error from Babylon Lite when the name is not declared or the length is wrong.\n *\n * @internal\n */\nexport function writeShaderUniform(\n material: ShaderMaterial,\n name: string,\n value: number | readonly number[] | Float32Array,\n): void {\n setShaderUniform(material, name, value);\n}\n\n/**\n * Writes a declared `mat4x4<f32>` uniform from sixteen column-major floats.\n *\n * @param material - The material to write to.\n * @param name - The declared uniform name.\n * @param value - The matrix.\n *\n * @internal\n */\nexport function writeShaderMatrix(material: ShaderMaterial, name: string, value: Float32Array): void {\n setShaderMatrix(material, name, value);\n}\n\n/**\n * Binds or clears a declared sampler's texture.\n *\n * @param material - The material to write to.\n * @param name - The declared sampler name.\n * @param texture - The texture, or `null` to unbind. An unbound sampler makes the material\n * unbuildable, so ignifx always binds a fallback instead.\n *\n * @internal\n */\nexport function writeShaderTexture(material: ShaderMaterial, name: string, texture: Texture2D | null): void {\n setShaderTexture(material, name, texture);\n}\n\n/**\n * Binds or clears a declared storage buffer.\n *\n * @param material - The material to write to.\n * @param name - The declared storage buffer name.\n * @param buffer - The buffer, or `null` to unbind.\n *\n * @internal\n */\nexport function writeShaderStorageBuffer(material: ShaderMaterial, name: string, buffer: StorageBuffer | null): void {\n setShaderStorageBuffer(material, name, buffer);\n}\n\n/**\n * The 1x1 texture a declared-but-unbound sampler is filled with, created on first use and shared for\n * the life of the app.\n *\n * @param engine - The engine that owns the texture.\n * @param cache - The app's fallback textures, keyed by kind; a miss is created and stored.\n * @param fallback - `\"white\"`, `\"black\"`, or `\"transparent\"`; `null` means white.\n * @param array - `true` for a one-layer `texture_2d_array<f32>`.\n * @returns The texture.\n *\n * @internal\n */\nexport function resolveFallbackTexture(\n engine: EngineContext,\n cache: Map<string, Texture2D>,\n fallback: string | null,\n array: boolean,\n): Texture2D {\n const kind = fallback ?? \"white\";\n const key = array ? `${kind}:array` : kind;\n const cached = cache.get(key);\n if (cached !== undefined) {\n return cached;\n }\n const created = createFallbackTexture(engine, kind, array);\n cache.set(key, created);\n return created;\n}\n\n/**\n * Creates the 1x1 texture a declared-but-unbound sampler is filled with.\n *\n * @remarks\n * Babylon Lite refuses to build a bind group for a sampler with nothing bound (error 309), so a\n * material whose file declares `// @ignifx texture noise` and whose `.material.json` binds nothing\n * would be undrawable. One 1x1 texture per fallback kind per app is what makes it legal, which is\n * also Godot's `hint_default_white` behaviour.\n *\n * @param engine - The engine that owns the texture.\n * @param fallback - `\"white\"`, `\"black\"`, or `\"transparent\"`.\n * @param array - `true` for a one-layer `texture_2d_array<f32>`, which is what a sampler declared\n * `array` binds.\n * @returns The texture.\n *\n * @internal\n */\nexport function createFallbackTexture(engine: EngineContext, fallback: string, array: boolean): Texture2D {\n const rgba = FALLBACK_PIXELS[fallback] ?? FALLBACK_PIXELS[\"white\"];\n const pixels = Uint8Array.from(rgba ?? [255, 255, 255, 255]);\n return array\n ? createTexture2DArrayFromPixels(engine, pixels, 1, 1, 1, { mipMaps: false })\n : createTexture2DFromPixels(engine, pixels, 1, 1, {});\n}\n\n/**\n * Turns on Babylon Lite's cached uniform serialization plans for shader materials.\n *\n * @remarks\n * Process-global and idempotent: it installs two writer functions that keep a `WeakMap` of layout\n * plans per material and rewrite only the custom uniform slots whose value changed\n * (`lib/material/shader/enable-shader-material-uniform-caching.js`). That is exactly the shape of\n * ignifx's per-frame `time` upload, so the adapter enables it as it loads rather than making every\n * project remember to.\n *\n * @internal\n */\nexport function enableShaderUniformCaching(): void {\n enableShaderMaterialUniformCaching();\n}\n\n/**\n * Reads the installed environment's ambient irradiance — the `L00` band of its diffuse spherical\n * harmonics — into `out`.\n *\n * @remarks\n * `EnvironmentTextures.sphericalHarmonics` is declared: 36 floats in a stride-4 layout beginning\n * `[L00.rgb, 0, …]` (`index.d.ts`), the same block Babylon Lite writes into the scene uniform buffer\n * as `scene.vSphericalL00` and friends (`lib/scene/scene-ubo-extras.js`, `writeEnvUbo`). So the\n * value ignifx uploads as `ambientColor` is exactly what a shader could read for itself as\n * `scene.vSphericalL00.rgb`, which is the documented alternative for a shader that would rather not\n * declare the uniform. Reaching the slot goes through `./environment.ts`, which is the one place\n * ignifx touches the undeclared `scene._envTextures` field\n * (`docs/architecture/07-rendering.md` §2.5, §8).\n *\n * @param scene - The render scene.\n * @param out - Receives the three linear channels; left untouched when nothing is installed.\n * @returns `true` when an environment supplied harmonics.\n *\n * @internal\n */\nexport function readSceneAmbient(scene: SceneContext, out: Float32Array): boolean {\n const harmonics = readSceneEnvironment(scene)?.sphericalHarmonics;\n if (harmonics === undefined || harmonics.length < 3) {\n return false;\n }\n out[0] = harmonics[0] ?? 0;\n out[1] = harmonics[1] ?? 0;\n out[2] = harmonics[2] ?? 0;\n return true;\n}\n\n/**\n * The subset of this module `src/render/shader-material.ts` reaches through its dynamic `import()`,\n * named so the memo has a type that does not have to be written as `typeof import(…)` (which the\n * `consistent-type-imports` rule forbids).\n *\n * @remarks\n * Assigning the imported module namespace to this type is what checks the two against each other,\n * so a signature that drifts is a compile error rather than a runtime surprise.\n *\n * @internal\n */\nexport interface ShaderMaterialAdapter {\n /** {@link createShaderMaterialFromOptions}. */\n readonly createShaderMaterialFromOptions: (options: ShaderMaterialBuildOptions) => ShaderMaterial;\n /** {@link writeShaderUniform}. */\n readonly writeShaderUniform: (\n material: ShaderMaterial,\n name: string,\n value: number | readonly number[] | Float32Array,\n ) => void;\n /** {@link writeShaderMatrix}. */\n readonly writeShaderMatrix: (material: ShaderMaterial, name: string, value: Float32Array) => void;\n /** {@link writeShaderTexture}. */\n readonly writeShaderTexture: (material: ShaderMaterial, name: string, texture: Texture2D | null) => void;\n /** {@link writeShaderStorageBuffer}. */\n readonly writeShaderStorageBuffer: (material: ShaderMaterial, name: string, buffer: StorageBuffer | null) => void;\n /** {@link resolveFallbackTexture}. */\n readonly resolveFallbackTexture: (\n engine: EngineContext,\n cache: Map<string, Texture2D>,\n fallback: string | null,\n array: boolean,\n ) => Texture2D;\n /** {@link enableShaderUniformCaching}. */\n readonly enableShaderUniformCaching: () => void;\n /** {@link readSceneAmbient}. */\n readonly readSceneAmbient: (scene: SceneContext, out: Float32Array) => boolean;\n}\n"],"mappings":";;;;AAsDA,MAAM,kBAAuF,OAAO,OAAO;CACzG,OAAO;EAAC;EAAK;EAAK;EAAK;CAAG;CAC1B,OAAO;EAAC;EAAG;EAAG;EAAG;CAAG;CACpB,aAAa;EAAC;EAAG;EAAG;EAAG;CAAC;AAC1B,CAAC;;;;;;;;;;;;;;AAyGD,SAAgB,gCAAgC,SAAqD;CACnG,MAAM,gBAAgB,QAAQ,OAAO,MAAM,cAAc;CACzD,OAAO,qBAAqB;EAC1B,MAAM,QAAQ;EACd,cAAc,QAAQ;EACtB,gBACE,QAAQ,iBAAiB,OAAO,qBAAqB,QAAQ,QAAQ,aAAa,IAAI,QAAQ;EAChG,YAAY,QAAQ;EACpB,UAAU,QAAQ;EAClB,UAAU,QAAQ;EAClB,gBAAgB,QAAQ;EACxB,SAAS,QAAQ;EACjB,uBAAuB,QAAQ;EAC/B,mBAAmB,QAAQ;EAC3B,WAAW,QAAQ;EACnB,GAAI,QAAQ,UAAU,OAAO,CAAC,IAAI,EAAE,OAAO,QAAQ,MAAM;EACzD,cAAc,QAAQ;EACtB,iBAAiB,QAAQ;EACzB,YAAY,QAAQ;EACpB,GAAI,QAAQ,iBAAiB,OAAO,CAAC,IAAI,EAAE,cAAc,QAAQ,aAAa;CAChF,CAAC;AACH;;AAGA,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;AAqBzB,SAAgB,qBAAqB,QAAgB,eAAgC;CACnF,MAAM,QAAQ,sCAAsC,KAAK,MAAM;CAC/D,IAAI,UAAU,MACZ,OAAO;CAET,MAAM,OAAO,MAAM,QAAQ,MAAM,EAAE,CAAC,SAAS;CAC7C,MAAM,QAAQ,cAAc,QAAQ,IAAI;CACxC,IAAI,QAAQ,GACV,OAAO;CAET,MAAM,QAAQ,OAAO,MAAM,QAAQ,CAAC;CACpC,MAAM,SAAS,2DAA2D,KAAK,KAAK;CACpF,IAAI,WAAW,MACb,OAAO;CAET,MAAM,aAAa,OAAO,MAAM,OAAO,GAAG,KAAK;CAC/C,MAAM,QAAQ,eAAe,UAAU;CACvC,MAAM,SAAS,gBACX,wHACA;CACJ,OAAO;EAEL,GAAG,OAAO,MAAM,GAAG,MAAM,KAAK,EAAE,KAAK,iBAAiB,GAAG,gBAAgB,UAAU,EAAE,eAAe,MAAM,MAAM,OAAO,EAAE,CAAC,MAAM;EAChI,6BAA6B,WAAW;EACxC,SAAS,iBAAiB,GAAG,MAAM,KAAK,GAAG,EAAE;EAC7C,oBAAoB,OAAO;EAC3B;CACF,CAAC,CAAC,KAAK,IAAI;AACb;;;;;;;;AASA,SAAS,cAAc,MAAc,MAAsB;CACzD,IAAI,QAAQ;CACZ,KAAK,IAAI,QAAQ,MAAM,QAAQ,KAAK,QAAQ,SAAS,GAAG;EACtD,MAAM,OAAO,KAAK;EAClB,IAAI,SAAS,KACX,SAAS;OACJ,IAAI,SAAS,KAAK;GACvB,SAAS;GACT,IAAI,UAAU,GACZ,OAAO;EAEX;CACF;CACA,OAAO;AACT;;;;;;;;AASA,SAAS,gBAAgB,YAA4B;CACnD,OAAO,WAAW,WAAW,4BAA4B,EAAE;AAC7D;;;;;;;AAQA,SAAS,eAAe,YAA8B;CACpD,MAAM,QAAkB,CAAC;CACzB,IAAI,QAAQ;CACZ,IAAI,QAAQ;CACZ,MAAM,QAAQ,QAAsB;EAClC,MAAM,QAAQ,gBAAgB,WAAW,MAAM,OAAO,GAAG,CAAC,CAAC,CAAC,KAAK;EACjE,MAAM,QAAQ,MAAM,QAAQ,GAAG;EAC/B,IAAI,QAAQ,GACV,MAAM,KAAK,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC;CAE3C;CACA,KAAK,IAAI,QAAQ,GAAG,QAAQ,WAAW,QAAQ,SAAS,GAAG;EACzD,MAAM,OAAO,WAAW;EACxB,IAAI,SAAS,OAAO,SAAS,KAC3B,SAAS;OACJ,IAAI,SAAS,OAAO,SAAS,KAClC,SAAS;OACJ,IAAI,SAAS,OAAO,UAAU,GAAG;GACtC,KAAK,KAAK;GACV,QAAQ,QAAQ;EAClB;CACF;CACA,KAAK,WAAW,MAAM;CACtB,OAAO;AACT;;;;;;;;;;;;;;;;AAiBA,SAAgB,mBACd,UACA,MACA,OACM;CACN,iBAAiB,UAAU,MAAM,KAAK;AACxC;;;;;;;;;;AAWA,SAAgB,kBAAkB,UAA0B,MAAc,OAA2B;CACnG,gBAAgB,UAAU,MAAM,KAAK;AACvC;;;;;;;;;;;AAYA,SAAgB,mBAAmB,UAA0B,MAAc,SAAiC;CAC1G,iBAAiB,UAAU,MAAM,OAAO;AAC1C;;;;;;;;;;AAWA,SAAgB,yBAAyB,UAA0B,MAAc,QAAoC;CACnH,uBAAuB,UAAU,MAAM,MAAM;AAC/C;;;;;;;;;;;;;AAcA,SAAgB,uBACd,QACA,OACA,UACA,OACW;CACX,MAAM,OAAO,YAAY;CACzB,MAAM,MAAM,QAAQ,GAAG,KAAK,UAAU;CACtC,MAAM,SAAS,MAAM,IAAI,GAAG;CAC5B,IAAI,WAAW,KAAA,GACb,OAAO;CAET,MAAM,UAAU,sBAAsB,QAAQ,MAAM,KAAK;CACzD,MAAM,IAAI,KAAK,OAAO;CACtB,OAAO;AACT;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,sBAAsB,QAAuB,UAAkB,OAA2B;CACxG,MAAM,OAAO,gBAAgB,aAAa,gBAAgB;CAC1D,MAAM,SAAS,WAAW,KAAK,QAAQ;EAAC;EAAK;EAAK;EAAK;CAAG,CAAC;CAC3D,OAAO,QACH,+BAA+B,QAAQ,QAAQ,GAAG,GAAG,GAAG,EAAE,SAAS,MAAM,CAAC,IAC1E,0BAA0B,QAAQ,QAAQ,GAAG,GAAG,CAAC,CAAC;AACxD;;;;;;;;;;;;;AAcA,SAAgB,6BAAmC;CACjD,mCAAmC;AACrC;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,iBAAiB,OAAqB,KAA4B;CAChF,MAAM,YAAY,qBAAqB,KAAK,CAAC,EAAE;CAC/C,IAAI,cAAc,KAAA,KAAa,UAAU,SAAS,GAChD,OAAO;CAET,IAAI,KAAK,UAAU,MAAM;CACzB,IAAI,KAAK,UAAU,MAAM;CACzB,IAAI,KAAK,UAAU,MAAM;CACzB,OAAO;AACT"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { o as rebuildMaterialPipelines } from "./material-CGk5mAah.js";
|
|
2
|
+
import { createScreenSpaceGlobalIlluminationPostProcessTask, getPbrUnlit, isPbrMaterial } from "@babylonjs/lite";
|
|
3
|
+
//#region src/lite/gpu/ssgi.ts
|
|
4
|
+
/** The pass's frame-graph task name. */
|
|
5
|
+
const TASK_NAME = "ignifx:ssgi";
|
|
6
|
+
/**
|
|
7
|
+
* The environment plugin's name.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
const SSGI_ENVIRONMENT_PLUGIN_NAME = "ignifx-ssgi-environment";
|
|
12
|
+
/**
|
|
13
|
+
* Creates an SSGI pass.
|
|
14
|
+
*
|
|
15
|
+
* @param engine - The engine.
|
|
16
|
+
* @param scene - The scene, whose materials get the plugin.
|
|
17
|
+
* @param depth - The scene-input depth target.
|
|
18
|
+
* @param camera - The camera the depth was drawn from.
|
|
19
|
+
* @param options - The initial tuning and the creation-time choices.
|
|
20
|
+
* @param options.tuning - The initial tuning.
|
|
21
|
+
* @param options.halfResolution - Whether the rays are traced at half resolution.
|
|
22
|
+
* @param options.usePlugin - Whether Lite's plugin bridges are installed, so the plugin can be used.
|
|
23
|
+
* @returns The pass.
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
function createSsgiPass(engine, scene, depth, camera, options) {
|
|
28
|
+
let task = null;
|
|
29
|
+
let plugin = null;
|
|
30
|
+
let pluginValue = NaN;
|
|
31
|
+
return {
|
|
32
|
+
create(source, target) {
|
|
33
|
+
const tuning = options.tuning;
|
|
34
|
+
task = createScreenSpaceGlobalIlluminationPostProcessTask({
|
|
35
|
+
name: TASK_NAME,
|
|
36
|
+
sourceTexture: source,
|
|
37
|
+
depthTexture: depth,
|
|
38
|
+
targetTexture: target,
|
|
39
|
+
camera,
|
|
40
|
+
resolutionScale: options.halfResolution ? .5 : 1,
|
|
41
|
+
intensity: tuning.intensity,
|
|
42
|
+
rayLength: tuning.radius,
|
|
43
|
+
stepCount: tuning.samples,
|
|
44
|
+
composition: "additive"
|
|
45
|
+
}, engine, scene);
|
|
46
|
+
return task;
|
|
47
|
+
},
|
|
48
|
+
update(tuning, isSceneRegistered) {
|
|
49
|
+
if (task === null) return;
|
|
50
|
+
task.intensity = tuning.intensity;
|
|
51
|
+
task.rayLength = tuning.radius;
|
|
52
|
+
task.stepCount = tuning.samples;
|
|
53
|
+
if (!options.usePlugin) return;
|
|
54
|
+
const value = Math.min(1, Math.max(0, tuning.environmentDiffuse));
|
|
55
|
+
if (plugin === null || value !== pluginValue) {
|
|
56
|
+
pluginValue = value;
|
|
57
|
+
plugin = createSsgiEnvironmentPlugin(value);
|
|
58
|
+
}
|
|
59
|
+
attachPlugin(scene, plugin, isSceneRegistered);
|
|
60
|
+
},
|
|
61
|
+
dispose(isSceneRegistered) {
|
|
62
|
+
if (plugin !== null) {
|
|
63
|
+
attachPlugin(scene, null, isSceneRegistered);
|
|
64
|
+
plugin = null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Builds the plugin that leaves `environmentDiffuse` of the environment's diffuse light.
|
|
71
|
+
*
|
|
72
|
+
* @param environmentDiffuse - What remains, 0 to 1. Baked into the WGSL, so a change compiles anew.
|
|
73
|
+
* @returns The plugin.
|
|
74
|
+
*
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
function createSsgiEnvironmentPlugin(environmentDiffuse) {
|
|
78
|
+
const fragment = {
|
|
79
|
+
CUSTOM_FRAGMENT_DEFINITIONS: "var<private> finalIrradiance: vec3<f32>;var<private> ignifxSsgiRemoved: vec3<f32>;",
|
|
80
|
+
CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION: `color-=(finalIrradiance-ignifxSsgiRemoved)*${(1 - environmentDiffuse).toFixed(4)};ignifxSsgiRemoved=finalIrradiance;`
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
name: SSGI_ENVIRONMENT_PLUGIN_NAME,
|
|
84
|
+
priority: -1,
|
|
85
|
+
getCustomCode: (stage) => stage === "fragment" ? fragment : null
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Puts a plugin on every lit PBR material in the scene, replacing an older one of the same name,
|
|
90
|
+
* or takes it off every material when `plugin` is `null`.
|
|
91
|
+
*
|
|
92
|
+
* @param scene - The scene.
|
|
93
|
+
* @param plugin - The current plugin, or `null` to remove.
|
|
94
|
+
* @param isSceneRegistered - Whether a changed material's pipelines must be rebuilt.
|
|
95
|
+
*/
|
|
96
|
+
function attachPlugin(scene, plugin, isSceneRegistered) {
|
|
97
|
+
const meshes = scene.meshes;
|
|
98
|
+
for (let index = 0; index < meshes.length; index += 1) {
|
|
99
|
+
const material = meshes[index]?.material;
|
|
100
|
+
if (material === void 0 || material === null || !isPbrMaterial(material)) continue;
|
|
101
|
+
const current = material.plugins ?? [];
|
|
102
|
+
const wanted = plugin !== null && getPbrUnlit(material) === void 0;
|
|
103
|
+
if (wanted && current.includes(plugin)) continue;
|
|
104
|
+
const kept = current.filter((other) => other.name !== SSGI_ENVIRONMENT_PLUGIN_NAME);
|
|
105
|
+
if (!wanted && kept.length === current.length) continue;
|
|
106
|
+
material.plugins = wanted ? [...kept, plugin] : kept;
|
|
107
|
+
if (isSceneRegistered) rebuildMaterialPipelines(scene, material);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
export { SSGI_ENVIRONMENT_PLUGIN_NAME, createSsgiEnvironmentPlugin, createSsgiPass };
|
|
112
|
+
|
|
113
|
+
//# sourceMappingURL=ssgi-Dm-maZrc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssgi-Dm-maZrc.js","names":[],"sources":["../src/lite/gpu/ssgi.ts"],"sourcesContent":["import { createScreenSpaceGlobalIlluminationPostProcessTask, getPbrUnlit, isPbrMaterial } from \"@babylonjs/lite\";\nimport { rebuildMaterialPipelines } from \"../material.js\";\nimport type { SceneColorPass } from \"./scene-color-passes.js\";\nimport type {\n Camera,\n EngineContext,\n MaterialPlugin,\n RenderTarget,\n SceneContext,\n ScreenSpaceGlobalIlluminationPostProcessTask,\n} from \"@babylonjs/lite\";\n\n/**\n * Screen-space global illumination (GI plan step G11): Lite's `@beta`\n * `createScreenSpaceGlobalIlluminationPostProcessTask` (`index.d.ts` 3681), fed the shared\n * scene-input depth and run as a scene-colour pass (`./scene-color-passes.ts`), plus a material\n * plugin that turns the environment's diffuse light down while it runs. Its own chunk, loaded only\n * while a `PostProcessStack` enables `ssgi` (`CONSTITUTION.md` §2.5).\n *\n * **Why the plugin.** Lite's additive composite adds one bounce of the lit scene colour on top of\n * the frame, and the environment's irradiance (`finalIrradiance`, `lib/material/pbr/fragments/\n * ibl-fragment.js` line 6) already stands in for that bounce, so with both the indirect light is\n * counted twice. The plugin subtracts `(1 - environmentDiffuse)` of `finalIrradiance` from the\n * colour; specular reflections are left alone.\n *\n * **How it compiles everywhere.** `CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION` is injected at both\n * the `AI` and the `NI` slot, which follow each other, and `finalIrradiance` exists only when the\n * material has an environment. The plugin declares a module-scope `finalIrradiance` of zero, which\n * the IBL code's own `let` shadows where it exists, and subtracts only what changed since its last\n * run, so the two injections together subtract once whichever side of the IBL code they land on,\n * and a material without an environment subtracts nothing. Priority -1 puts it ahead of the HDR\n * linear-output save (priority 0), which then keeps the adjusted colour.\n *\n * Plugins need Lite's bridges, which `rendering.hdr` and the `materialPlugins` feature install, so\n * without either the plugin is not attached and the environment is left as it is.\n */\n\n/**\n * The tuning a recorded pass follows live.\n *\n * @internal\n */\nexport interface SsgiTuning {\n /** How strongly the bounce is added, 0 to 4. */\n readonly intensity: number;\n /** How far each ray marches, in world units. */\n readonly radius: number;\n /** March steps per ray, 1 to 64. */\n readonly samples: number;\n /** How much of the environment's diffuse light remains, 0 to 1. */\n readonly environmentDiffuse: number;\n}\n\n/**\n * An SSGI pass: its task once created, its per-frame update, and the plugin it owns.\n *\n * @internal\n */\nexport interface SsgiPass extends SceneColorPass {\n /**\n * Writes the tuning onto the task and, when plugins are available, keeps every lit PBR material's\n * environment plugin in step.\n *\n * @param tuning - The stack's `ssgi` record.\n * @param isSceneRegistered - Whether a patched material's pipelines must be rebuilt.\n */\n update(tuning: SsgiTuning, isSceneRegistered: boolean): void;\n /**\n * Takes the plugin off every material again. The task itself is disposed by the installer.\n *\n * @param isSceneRegistered - Whether a patched material's pipelines must be rebuilt.\n */\n dispose(isSceneRegistered: boolean): void;\n}\n\n/** The pass's frame-graph task name. */\nconst TASK_NAME = \"ignifx:ssgi\";\n\n/**\n * The environment plugin's name.\n *\n * @internal\n */\nexport const SSGI_ENVIRONMENT_PLUGIN_NAME = \"ignifx-ssgi-environment\";\n\n/**\n * Creates an SSGI pass.\n *\n * @param engine - The engine.\n * @param scene - The scene, whose materials get the plugin.\n * @param depth - The scene-input depth target.\n * @param camera - The camera the depth was drawn from.\n * @param options - The initial tuning and the creation-time choices.\n * @param options.tuning - The initial tuning.\n * @param options.halfResolution - Whether the rays are traced at half resolution.\n * @param options.usePlugin - Whether Lite's plugin bridges are installed, so the plugin can be used.\n * @returns The pass.\n *\n * @internal\n */\nexport function createSsgiPass(\n engine: EngineContext,\n scene: SceneContext,\n depth: RenderTarget,\n camera: Camera,\n options: { readonly tuning: SsgiTuning; readonly halfResolution: boolean; readonly usePlugin: boolean },\n): SsgiPass {\n let task: ScreenSpaceGlobalIlluminationPostProcessTask | null = null;\n let plugin: MaterialPlugin | null = null;\n let pluginValue = Number.NaN;\n return {\n create(source: RenderTarget, target: RenderTarget): ScreenSpaceGlobalIlluminationPostProcessTask {\n const tuning = options.tuning;\n task = createScreenSpaceGlobalIlluminationPostProcessTask(\n {\n name: TASK_NAME,\n sourceTexture: source,\n depthTexture: depth,\n targetTexture: target,\n camera,\n resolutionScale: options.halfResolution ? 0.5 : 1,\n intensity: tuning.intensity,\n rayLength: tuning.radius,\n stepCount: tuning.samples,\n composition: \"additive\",\n },\n engine,\n scene,\n );\n return task;\n },\n update(tuning: SsgiTuning, isSceneRegistered: boolean): void {\n if (task === null) {\n return;\n }\n task.intensity = tuning.intensity;\n task.rayLength = tuning.radius;\n task.stepCount = tuning.samples;\n if (!options.usePlugin) {\n return;\n }\n const value = Math.min(1, Math.max(0, tuning.environmentDiffuse));\n if (plugin === null || value !== pluginValue) {\n pluginValue = value;\n plugin = createSsgiEnvironmentPlugin(value);\n }\n attachPlugin(scene, plugin, isSceneRegistered);\n },\n dispose(isSceneRegistered: boolean): void {\n if (plugin !== null) {\n attachPlugin(scene, null, isSceneRegistered);\n plugin = null;\n }\n },\n };\n}\n\n/**\n * Builds the plugin that leaves `environmentDiffuse` of the environment's diffuse light.\n *\n * @param environmentDiffuse - What remains, 0 to 1. Baked into the WGSL, so a change compiles anew.\n * @returns The plugin.\n *\n * @internal\n */\nexport function createSsgiEnvironmentPlugin(environmentDiffuse: number): MaterialPlugin {\n const removed = (1 - environmentDiffuse).toFixed(4);\n const fragment = {\n CUSTOM_FRAGMENT_DEFINITIONS: \"var<private> finalIrradiance: vec3<f32>;var<private> ignifxSsgiRemoved: vec3<f32>;\",\n CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION: `color-=(finalIrradiance-ignifxSsgiRemoved)*${removed};ignifxSsgiRemoved=finalIrradiance;`,\n };\n return {\n name: SSGI_ENVIRONMENT_PLUGIN_NAME,\n priority: -1,\n getCustomCode: (stage) => (stage === \"fragment\" ? fragment : null),\n };\n}\n\n/**\n * Puts a plugin on every lit PBR material in the scene, replacing an older one of the same name,\n * or takes it off every material when `plugin` is `null`.\n *\n * @param scene - The scene.\n * @param plugin - The current plugin, or `null` to remove.\n * @param isSceneRegistered - Whether a changed material's pipelines must be rebuilt.\n */\nfunction attachPlugin(scene: SceneContext, plugin: MaterialPlugin | null, isSceneRegistered: boolean): void {\n const meshes = scene.meshes;\n for (let index = 0; index < meshes.length; index += 1) {\n const material = meshes[index]?.material;\n // Declared non-null, but Lite's mesh factories create meshes with `material: null`.\n // oxlint-disable-next-line typescript/no-unnecessary-condition\n if (material === undefined || material === null || !isPbrMaterial(material)) {\n continue;\n }\n const current = material.plugins ?? [];\n const wanted = plugin !== null && getPbrUnlit(material) === undefined;\n if (wanted && current.includes(plugin)) {\n continue;\n }\n const kept = current.filter((other) => other.name !== SSGI_ENVIRONMENT_PLUGIN_NAME);\n if (!wanted && kept.length === current.length) {\n continue;\n }\n material.plugins = wanted ? [...kept, plugin] : kept;\n if (isSceneRegistered) {\n rebuildMaterialPipelines(scene, material);\n }\n }\n}\n"],"mappings":";;;;AA4EA,MAAM,YAAY;;;;;;AAOlB,MAAa,+BAA+B;;;;;;;;;;;;;;;;AAiB5C,SAAgB,eACd,QACA,OACA,OACA,QACA,SACU;CACV,IAAI,OAA4D;CAChE,IAAI,SAAgC;CACpC,IAAI,cAAc;CAClB,OAAO;EACL,OAAO,QAAsB,QAAoE;GAC/F,MAAM,SAAS,QAAQ;GACvB,OAAO,mDACL;IACE,MAAM;IACN,eAAe;IACf,cAAc;IACd,eAAe;IACf;IACA,iBAAiB,QAAQ,iBAAiB,KAAM;IAChD,WAAW,OAAO;IAClB,WAAW,OAAO;IAClB,WAAW,OAAO;IAClB,aAAa;GACf,GACA,QACA,KACF;GACA,OAAO;EACT;EACA,OAAO,QAAoB,mBAAkC;GAC3D,IAAI,SAAS,MACX;GAEF,KAAK,YAAY,OAAO;GACxB,KAAK,YAAY,OAAO;GACxB,KAAK,YAAY,OAAO;GACxB,IAAI,CAAC,QAAQ,WACX;GAEF,MAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,OAAO,kBAAkB,CAAC;GAChE,IAAI,WAAW,QAAQ,UAAU,aAAa;IAC5C,cAAc;IACd,SAAS,4BAA4B,KAAK;GAC5C;GACA,aAAa,OAAO,QAAQ,iBAAiB;EAC/C;EACA,QAAQ,mBAAkC;GACxC,IAAI,WAAW,MAAM;IACnB,aAAa,OAAO,MAAM,iBAAiB;IAC3C,SAAS;GACX;EACF;CACF;AACF;;;;;;;;;AAUA,SAAgB,4BAA4B,oBAA4C;CAEtF,MAAM,WAAW;EACf,6BAA6B;EAC7B,8CAA8C,+CAH/B,IAAI,mBAAA,CAAoB,QAAQ,CAGmD,EAAE;CACtG;CACA,OAAO;EACL,MAAM;EACN,UAAU;EACV,gBAAgB,UAAW,UAAU,aAAa,WAAW;CAC/D;AACF;;;;;;;;;AAUA,SAAS,aAAa,OAAqB,QAA+B,mBAAkC;CAC1G,MAAM,SAAS,MAAM;CACrB,KAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SAAS,GAAG;EACrD,MAAM,WAAW,OAAO,MAAM,EAAE;EAGhC,IAAI,aAAa,KAAA,KAAa,aAAa,QAAQ,CAAC,cAAc,QAAQ,GACxE;EAEF,MAAM,UAAU,SAAS,WAAW,CAAC;EACrC,MAAM,SAAS,WAAW,QAAQ,YAAY,QAAQ,MAAM,KAAA;EAC5D,IAAI,UAAU,QAAQ,SAAS,MAAM,GACnC;EAEF,MAAM,OAAO,QAAQ,QAAQ,UAAU,MAAM,SAAS,4BAA4B;EAClF,IAAI,CAAC,UAAU,KAAK,WAAW,QAAQ,QACrC;EAEF,SAAS,UAAU,SAAS,CAAC,GAAG,MAAM,MAAM,IAAI;EAChD,IAAI,mBACF,yBAAyB,OAAO,QAAQ;CAE5C;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as shaderMaterialsOf } from "./shader-material-
|
|
1
|
+
import { t as shaderMaterialsOf } from "./shader-material-B6p66wB8.js";
|
|
2
2
|
import { o as CoreErrorCode, t as IgnifxError } from "./ignifx-error-oYdVnT1S.js";
|
|
3
3
|
import { t as Color } from "./color-DrR6GFTd.js";
|
|
4
4
|
import { a as markMaterialDirty, o as rebuildMaterialPipelines } from "./material-CGk5mAah.js";
|
|
@@ -1397,4 +1397,4 @@ function describeNames(names) {
|
|
|
1397
1397
|
//#endregion
|
|
1398
1398
|
export { SurfaceShaderBinding, attachSurfaceShaders, detachSurfaceShaders, surfaceShaderBinding, surfaceShaderName, surfaceShaders };
|
|
1399
1399
|
|
|
1400
|
-
//# sourceMappingURL=surface-shader-
|
|
1400
|
+
//# sourceMappingURL=surface-shader-BaK0kvBB.js.map
|