@ignifx/core 0.14.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/decoders/draco3dgltf.LICENSE.md +201 -0
- package/decoders/draco_decoder.js +116 -0
- package/decoders/draco_decoder_gltf.wasm +0 -0
- package/decoders/vendored.json +22 -0
- package/dist/agx-tone-mapping-Cgt844j6.js +53 -0
- package/dist/agx-tone-mapping-Cgt844j6.js.map +1 -0
- package/dist/auto-exposure-uzPn0beO.js +246 -0
- package/dist/auto-exposure-uzPn0beO.js.map +1 -0
- package/dist/bloom-hdr-CLtQj-oY.js +315 -0
- package/dist/bloom-hdr-CLtQj-oY.js.map +1 -0
- package/dist/contact-shadows-T523EXaP.js +84 -0
- package/dist/contact-shadows-T523EXaP.js.map +1 -0
- package/dist/{decoders-CHJ7vduE.js → decoders-BUQrlS8U.js} +3 -2
- package/dist/decoders-BUQrlS8U.js.map +1 -0
- package/dist/{environment-Cq2BmA96.js → environment-DPi0_0SP.js} +18 -4
- package/dist/environment-DPi0_0SP.js.map +1 -0
- package/dist/gtao-_nr0b6-E.js +630 -0
- package/dist/gtao-_nr0b6-E.js.map +1 -0
- package/dist/hdr-output-BrUvpAsE.js +525 -0
- package/dist/hdr-output-BrUvpAsE.js.map +1 -0
- package/dist/index.d.ts +509 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1522 -512
- package/dist/index.js.map +1 -1
- package/dist/{instanced-mesh-instance-DYwH0vLi.js → instanced-mesh-instance-NnODkvqK.js} +2 -2
- package/dist/{instanced-mesh-instance-DYwH0vLi.js.map → instanced-mesh-instance-NnODkvqK.js.map} +1 -1
- package/dist/mat4-D6exvAuO.js +949 -0
- package/dist/mat4-D6exvAuO.js.map +1 -0
- package/dist/{render-path-Dx0learj.js → render-path-Be7WgN7r.js} +35 -4
- package/dist/render-path-Be7WgN7r.js.map +1 -0
- package/dist/{render-texture-IuR0iFVa.js → render-texture-C_TnaSz2.js} +28 -2
- package/dist/render-texture-C_TnaSz2.js.map +1 -0
- package/dist/scene-color-passes-DlNr-qyZ.js +65 -0
- package/dist/scene-color-passes-DlNr-qyZ.js.map +1 -0
- package/dist/scene-inputs-BxGOsnIZ.js +318 -0
- package/dist/scene-inputs-BxGOsnIZ.js.map +1 -0
- package/dist/{shader-material-CDQ0Y5kN.js → shader-material-B6p66wB8.js} +17 -6
- package/dist/shader-material-B6p66wB8.js.map +1 -0
- package/dist/{shader-material-BPb_oEZQ.js → shader-material-C0TAUr4t.js} +102 -4
- package/dist/shader-material-C0TAUr4t.js.map +1 -0
- package/dist/ssgi-Dm-maZrc.js +113 -0
- package/dist/ssgi-Dm-maZrc.js.map +1 -0
- package/dist/{surface-shader-CwQ03yHG.js → surface-shader-BaK0kvBB.js} +2 -2
- package/dist/{surface-shader-CwQ03yHG.js.map → surface-shader-BaK0kvBB.js.map} +1 -1
- package/dist/taa-BwBZLy11.js +480 -0
- package/dist/taa-BwBZLy11.js.map +1 -0
- package/dist/{vec3-T2PasQZv.js → vec3-D-0Y2mzE.js} +4 -948
- package/dist/vec3-D-0Y2mzE.js.map +1 -0
- package/package.json +4 -2
- package/dist/decoders-CHJ7vduE.js.map +0 -1
- package/dist/environment-Cq2BmA96.js.map +0 -1
- package/dist/hdr-output-DDpIo4Q5.js +0 -300
- package/dist/hdr-output-DDpIo4Q5.js.map +0 -1
- package/dist/render-path-Dx0learj.js.map +0 -1
- package/dist/render-texture-IuR0iFVa.js.map +0 -1
- package/dist/shader-material-BPb_oEZQ.js.map +0 -1
- package/dist/shader-material-CDQ0Y5kN.js.map +0 -1
- package/dist/vec3-T2PasQZv.js.map +0 -1
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { createScreenSpaceContactShadowsPostProcessTask } from "@babylonjs/lite";
|
|
2
|
+
//#region src/lite/gpu/contact-shadows.ts
|
|
3
|
+
/** The pass's frame-graph task name. */
|
|
4
|
+
const TASK_NAME = "ignifx:contact-shadows";
|
|
5
|
+
/**
|
|
6
|
+
* Creates a contact-shadows pass.
|
|
7
|
+
*
|
|
8
|
+
* @param engine - The engine.
|
|
9
|
+
* @param scene - The scene, whose lights are read every frame.
|
|
10
|
+
* @param depth - The scene-input depth target.
|
|
11
|
+
* @param camera - The camera the depth was drawn from.
|
|
12
|
+
* @param tuning - The initial tuning.
|
|
13
|
+
* @returns The pass.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
function createContactShadowsPass(engine, scene, depth, camera, tuning) {
|
|
18
|
+
const lightDirection = {
|
|
19
|
+
x: 0,
|
|
20
|
+
y: -1,
|
|
21
|
+
z: 0
|
|
22
|
+
};
|
|
23
|
+
let task = null;
|
|
24
|
+
return {
|
|
25
|
+
create(source, target) {
|
|
26
|
+
task = createScreenSpaceContactShadowsPostProcessTask({
|
|
27
|
+
name: TASK_NAME,
|
|
28
|
+
sourceTexture: source,
|
|
29
|
+
depthTexture: depth,
|
|
30
|
+
targetTexture: target,
|
|
31
|
+
camera,
|
|
32
|
+
lightDirection,
|
|
33
|
+
intensity: tuning.intensity,
|
|
34
|
+
maxDistance: tuning.length,
|
|
35
|
+
thickness: tuning.thickness,
|
|
36
|
+
stepCount: tuning.samples
|
|
37
|
+
}, engine, scene);
|
|
38
|
+
return task;
|
|
39
|
+
},
|
|
40
|
+
update(next) {
|
|
41
|
+
if (task === null) return;
|
|
42
|
+
task.intensity = next.intensity;
|
|
43
|
+
task.maxDistance = next.length;
|
|
44
|
+
task.thickness = next.thickness;
|
|
45
|
+
task.stepCount = next.samples;
|
|
46
|
+
const light = mainDirectionalLight(scene);
|
|
47
|
+
task.enabled = light !== null;
|
|
48
|
+
if (light !== null) {
|
|
49
|
+
lightDirection.x = light.direction.x;
|
|
50
|
+
lightDirection.y = light.direction.y;
|
|
51
|
+
lightDirection.z = light.direction.z;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The scene's main directional light: the first that casts shadows, else the first.
|
|
58
|
+
*
|
|
59
|
+
* @param scene - The scene.
|
|
60
|
+
* @returns The light, or `null` when the scene has none.
|
|
61
|
+
*/
|
|
62
|
+
function mainDirectionalLight(scene) {
|
|
63
|
+
let first = null;
|
|
64
|
+
for (const light of scene.lights) {
|
|
65
|
+
if (!isDirectional(light)) continue;
|
|
66
|
+
if (light.shadowGenerator !== void 0) return light;
|
|
67
|
+
first ??= light;
|
|
68
|
+
}
|
|
69
|
+
return first;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Whether a scene light is directional.
|
|
73
|
+
*
|
|
74
|
+
* @param light - The light.
|
|
75
|
+
* @param light.lightType - Its type tag.
|
|
76
|
+
* @returns `true` for a directional light.
|
|
77
|
+
*/
|
|
78
|
+
function isDirectional(light) {
|
|
79
|
+
return light.lightType === "directional";
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
export { createContactShadowsPass };
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=contact-shadows-T523EXaP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contact-shadows-T523EXaP.js","names":[],"sources":["../src/lite/gpu/contact-shadows.ts"],"sourcesContent":["import { createScreenSpaceContactShadowsPostProcessTask } from \"@babylonjs/lite\";\nimport type { SceneColorPass } from \"./scene-color-passes.js\";\nimport type {\n Camera,\n DirectionalLight,\n EngineContext,\n RenderTarget,\n SceneContext,\n ScreenSpaceContactShadowsPostProcessTask,\n} from \"@babylonjs/lite\";\n\n/**\n * Screen-space contact shadows (GI plan step G10): Lite's\n * `createScreenSpaceContactShadowsPostProcessTask` (`index.d.ts` 3672), fed the shared scene-input\n * depth and run as a scene-colour pass (`./scene-color-passes.ts`). Its own chunk, loaded only while\n * a `PostProcessStack` enables `contactShadows` (`CONSTITUTION.md` §2.5).\n *\n * Lite marches from each pixel towards one light through the depth buffer and multiplies the colour\n * by the occlusion it finds, so the light is the scene's main directional light: the first one that\n * casts shadows, else the first one. With none, the task runs disabled (its composite copies).\n */\n\n/**\n * The tuning a recorded pass follows live.\n *\n * @internal\n */\nexport interface ContactShadowsTuning {\n /** How dark a contact gets, 0 to 4. */\n readonly intensity: number;\n /** How far each ray marches, in world units. */\n readonly length: number;\n /** How thick a surface is assumed to be behind its depth, in world units. */\n readonly thickness: number;\n /** March steps per pixel, 1 to 64. */\n readonly samples: number;\n}\n\n/**\n * A contact-shadows pass: its task once created, and its per-frame update.\n *\n * @internal\n */\nexport interface ContactShadowsPass extends SceneColorPass {\n /**\n * Writes the tuning and the main light's direction onto the task.\n *\n * @param tuning - The stack's `contactShadows` record.\n */\n update(tuning: ContactShadowsTuning): void;\n}\n\n/** The pass's frame-graph task name. */\nconst TASK_NAME = \"ignifx:contact-shadows\";\n\n/**\n * Creates a contact-shadows pass.\n *\n * @param engine - The engine.\n * @param scene - The scene, whose lights are read every frame.\n * @param depth - The scene-input depth target.\n * @param camera - The camera the depth was drawn from.\n * @param tuning - The initial tuning.\n * @returns The pass.\n *\n * @internal\n */\nexport function createContactShadowsPass(\n engine: EngineContext,\n scene: SceneContext,\n depth: RenderTarget,\n camera: Camera,\n tuning: ContactShadowsTuning,\n): ContactShadowsPass {\n // Lite keeps this object and reads it every frame (`lib/post-process/screen-space-contact-shadows.js`).\n const lightDirection = { x: 0, y: -1, z: 0 };\n let task: ScreenSpaceContactShadowsPostProcessTask | null = null;\n return {\n create(source: RenderTarget, target: RenderTarget): ScreenSpaceContactShadowsPostProcessTask {\n task = createScreenSpaceContactShadowsPostProcessTask(\n {\n name: TASK_NAME,\n sourceTexture: source,\n depthTexture: depth,\n targetTexture: target,\n camera,\n lightDirection,\n intensity: tuning.intensity,\n maxDistance: tuning.length,\n thickness: tuning.thickness,\n stepCount: tuning.samples,\n },\n engine,\n scene,\n );\n return task;\n },\n update(next: ContactShadowsTuning): void {\n if (task === null) {\n return;\n }\n task.intensity = next.intensity;\n task.maxDistance = next.length;\n task.thickness = next.thickness;\n task.stepCount = next.samples;\n const light = mainDirectionalLight(scene);\n task.enabled = light !== null;\n if (light !== null) {\n lightDirection.x = light.direction.x;\n lightDirection.y = light.direction.y;\n lightDirection.z = light.direction.z;\n }\n },\n };\n}\n\n/**\n * The scene's main directional light: the first that casts shadows, else the first.\n *\n * @param scene - The scene.\n * @returns The light, or `null` when the scene has none.\n */\nfunction mainDirectionalLight(scene: SceneContext): DirectionalLight | null {\n let first: DirectionalLight | null = null;\n for (const light of scene.lights) {\n if (!isDirectional(light)) {\n continue;\n }\n if (light.shadowGenerator !== undefined) {\n return light;\n }\n first ??= light;\n }\n return first;\n}\n\n/**\n * Whether a scene light is directional.\n *\n * @param light - The light.\n * @param light.lightType - Its type tag.\n * @returns `true` for a directional light.\n */\nfunction isDirectional(light: { readonly lightType: string }): light is DirectionalLight {\n return light.lightType === \"directional\";\n}\n"],"mappings":";;;AAqDA,MAAM,YAAY;;;;;;;;;;;;;AAclB,SAAgB,yBACd,QACA,OACA,OACA,QACA,QACoB;CAEpB,MAAM,iBAAiB;EAAE,GAAG;EAAG,GAAG;EAAI,GAAG;CAAE;CAC3C,IAAI,OAAwD;CAC5D,OAAO;EACL,OAAO,QAAsB,QAAgE;GAC3F,OAAO,+CACL;IACE,MAAM;IACN,eAAe;IACf,cAAc;IACd,eAAe;IACf;IACA;IACA,WAAW,OAAO;IAClB,aAAa,OAAO;IACpB,WAAW,OAAO;IAClB,WAAW,OAAO;GACpB,GACA,QACA,KACF;GACA,OAAO;EACT;EACA,OAAO,MAAkC;GACvC,IAAI,SAAS,MACX;GAEF,KAAK,YAAY,KAAK;GACtB,KAAK,cAAc,KAAK;GACxB,KAAK,YAAY,KAAK;GACtB,KAAK,YAAY,KAAK;GACtB,MAAM,QAAQ,qBAAqB,KAAK;GACxC,KAAK,UAAU,UAAU;GACzB,IAAI,UAAU,MAAM;IAClB,eAAe,IAAI,MAAM,UAAU;IACnC,eAAe,IAAI,MAAM,UAAU;IACnC,eAAe,IAAI,MAAM,UAAU;GACrC;EACF;CACF;AACF;;;;;;;AAQA,SAAS,qBAAqB,OAA8C;CAC1E,IAAI,QAAiC;CACrC,KAAK,MAAM,SAAS,MAAM,QAAQ;EAChC,IAAI,CAAC,cAAc,KAAK,GACtB;EAEF,IAAI,MAAM,oBAAoB,KAAA,GAC5B,OAAO;EAET,UAAU;CACZ;CACA,OAAO;AACT;;;;;;;;AASA,SAAS,cAAc,OAAkE;CACvF,OAAO,MAAM,cAAc;AAC7B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getOrCreateSampler, loadBasisTexture2D, loadKtx2Texture2D, setKtx2DecoderUrl, setMeshoptBaseUrl } from "@babylonjs/lite";
|
|
1
|
+
import { getOrCreateSampler, loadBasisTexture2D, loadKtx2Texture2D, setDracoBaseUrl, setKtx2DecoderUrl, setMeshoptBaseUrl } from "@babylonjs/lite";
|
|
2
2
|
//#region src/lite/gpu/decoders.ts
|
|
3
3
|
/**
|
|
4
4
|
* Points Lite at the given decoder locations.
|
|
@@ -14,6 +14,7 @@ function applyLiteDecoderUrls(urls) {
|
|
|
14
14
|
setKtx2DecoderUrl(urls.ktx2Decoder, transcoders);
|
|
15
15
|
}
|
|
16
16
|
if (urls.meshoptBaseUrl !== null) setMeshoptBaseUrl(urls.meshoptBaseUrl);
|
|
17
|
+
if (urls.dracoBaseUrl !== null) setDracoBaseUrl(urls.dracoBaseUrl);
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
20
|
* Loads a `.ktx2` texture through Lite's KTX2 decoder and gives it the requested sampler.
|
|
@@ -79,4 +80,4 @@ function loadBasisTextureWithOptions(engine, url, options) {
|
|
|
79
80
|
//#endregion
|
|
80
81
|
export { applyLiteDecoderUrls, loadBasisTextureWithOptions, loadKtx2TextureWithOptions };
|
|
81
82
|
|
|
82
|
-
//# sourceMappingURL=decoders-
|
|
83
|
+
//# sourceMappingURL=decoders-BUQrlS8U.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decoders-BUQrlS8U.js","names":[],"sources":["../src/lite/gpu/decoders.ts"],"sourcesContent":["import {\n getOrCreateSampler,\n loadBasisTexture2D,\n loadKtx2Texture2D,\n setDracoBaseUrl,\n setKtx2DecoderUrl,\n setMeshoptBaseUrl,\n} from \"@babylonjs/lite\";\nimport type { EngineContext, Texture2D, Texture2DOptions } from \"@babylonjs/lite\";\n\n/**\n * The compressed-texture and decoder half of the Babylon Lite adapter\n * (`docs/architecture/07-rendering.md` §7). Imported only dynamically, from `./texture.ts` and\n * `../../render/decoder-urls.ts`, so a game that loads no KTX2 texture and no glTF carries none of\n * Lite's KTX2, Basis, meshopt or Draco glue.\n *\n * Everything here is `@internal`.\n *\n * ## The decoders (verified against `@babylonjs/lite@1.34.0`)\n *\n * `loadKtx2Texture2D` (`index.d.ts` 7892) and the glTF `KHR_texture_basisu` path inject\n * `babylon.ktx2Decoder.js` as a `<script>` and read the `KTX2DECODER` global it defines; that\n * script then fetches its transcoders (`msc_basis_transcoder.js` and `.wasm` for ETC1S,\n * `uastc_*.wasm` for UASTC, `zstddec.wasm` for Zstandard supercompression). glTF\n * `EXT_meshopt_compression` injects `meshopt_decoder.js`. Every one of them comes from\n * `https://cdn.babylonjs.com/` unless `setKtx2DecoderUrl` (12484) and `setMeshoptBaseUrl` (12538)\n * say otherwise (`lib/texture/ktx2-loader.js`, `lib/loader-gltf/meshopt-decode.js`). Both setters\n * write process-wide state, and the KTX2 decoder is loaded once: a URL set after the first KTX2\n * load is ignored until a failed load clears Lite's cached promise.\n *\n * glTF `KHR_draco_mesh_compression` injects `draco_decoder.js`, which defines the\n * `DracoDecoderModule` global and fetches `draco_decoder_gltf.wasm` through `locateFile`. Both come\n * from the page's root, `/`, unless `setDracoBaseUrl` (12375) says otherwise\n * (`lib/loader-gltf/draco-decode.js`); the module is cached the same way.\n *\n * `loadBasisTexture2D` (7771) has no such setter. It always fetches `basis_transcoder.js` and its\n * WASM from `https://cdn.babylonjs.com/basisTranscoder/1/` (`lib/texture/basis-loader.js`), so a\n * `.basis` file cannot load under a `script-src 'self'` policy until Lite adds one.\n *\n * ## Transcode targets\n *\n * Lite picks them; the public API has no override. Its caps come from the device features\n * `texture-compression-{astc,bc,etc2}`, which `createEngine` requests whenever the adapter has\n * them (`lib/engine/engine.js`). The decoder's decision tree (`@babylonjs/ktx2decoder`\n * `transcodeDecisionTree.js`) then gives:\n *\n * - ETC1S: ETC2 (RGB, or RGBA with alpha) when `etc2` is present, else BC7 when `bc` is, else RGBA8.\n * - UASTC: ASTC 4×4 when `astc` is present, else BC7 when `bc` is, else ETC2 when `etc2` is, else\n * RGBA8.\n *\n * So a Windows or Linux desktop GPU gets BC7, Apple silicon gets ETC2 (ETC1S) or ASTC (UASTC),\n * and a device with no compression feature gets uncompressed RGBA8. `.basis` uses Lite's own\n * order: BC7, ASTC 4×4, ETC2, BC3, BC1, RGBA8.\n */\n\n/**\n * Where Lite should load its decoders from. A `null` field leaves Lite's default for that decoder.\n *\n * @internal\n */\nexport interface LiteDecoderUrls {\n /** The URL of `babylon.ktx2Decoder.js`, or `null` for Lite's CDN default. */\n readonly ktx2Decoder: string | null;\n /**\n * Overrides for the decoder's transcoder modules: class name in the `KTX2DECODER` namespace →\n * static property → URL, the second argument of `setKtx2DecoderUrl`. Ignored when\n * {@link LiteDecoderUrls.ktx2Decoder} is `null`.\n */\n readonly ktx2Transcoders: Readonly<Record<string, Readonly<Record<string, string>>>>;\n /** The directory `meshopt_decoder.js` is served from, or `null` for Lite's CDN default. */\n readonly meshoptBaseUrl: string | null;\n /**\n * The directory `draco_decoder.js` and `draco_decoder_gltf.wasm` are served from, or `null` for\n * Lite's default, the page's root.\n */\n readonly dracoBaseUrl: string | null;\n}\n\n/**\n * Points Lite at the given decoder locations.\n *\n * @param urls - The locations; `null` fields are left as they are.\n *\n * @internal\n */\nexport function applyLiteDecoderUrls(urls: LiteDecoderUrls): void {\n if (urls.ktx2Decoder !== null) {\n // `setKtx2DecoderUrl` keeps its own reference; a copy keeps the caller's object frozen-safe.\n const transcoders: Record<string, Record<string, string>> = {};\n for (const [name, properties] of Object.entries(urls.ktx2Transcoders)) {\n transcoders[name] = { ...properties };\n }\n setKtx2DecoderUrl(urls.ktx2Decoder, transcoders);\n }\n if (urls.meshoptBaseUrl !== null) {\n setMeshoptBaseUrl(urls.meshoptBaseUrl);\n }\n if (urls.dracoBaseUrl !== null) {\n setDracoBaseUrl(urls.dracoBaseUrl);\n }\n}\n\n/**\n * Loads a `.ktx2` texture through Lite's KTX2 decoder and gives it the requested sampler.\n *\n * @remarks\n * `loadKtx2Texture2D` takes only the URL and the sRGB flag. It uploads the file's own mip chain as\n * stored, with a fixed repeat/linear sampler; the sampler is rebuilt here from `options`.\n *\n * ## Orientation: rows as stored\n *\n * Compressed blocks cannot be flipped at upload, so `invertY` has no effect: the file's first row\n * lands at the top of the GPU texture, which is what a PNG gets with `invertY: false`. Lite marks\n * the handle `invertY` and documents that materials flip V for it (`index.d.ts` 14966), but in\n * 1.34 no material reads the flag, and a props-built PBR material ignores `setTextureTransform`\n * too (its UV-transform variant is enabled only by the glTF builder). Measured in\n * `test/assets/ktx2.browser.test.ts`: a top-row-first `.ktx2` draws upside down next to the same\n * PNG loaded with the default `invertY: true`, and a `.ktx2` encoded from the vertically flipped\n * image draws the same. So a `.ktx2` meant to replace a PNG under the default sidecar is encoded\n * flipped (Basis `setYFlip(true)`); `mipMaps` and `premultiplyAlpha` do not apply either.\n *\n * @param engine - The engine that owns the GPU texture.\n * @param url - Where to fetch the file from.\n * @param options - Colour space and sampler.\n * @returns The texture, transcoded to the device's best compressed format. Its reference count\n * starts at one, like `loadTexture2D`'s.\n *\n * @internal\n */\nexport async function loadKtx2TextureWithOptions(\n engine: EngineContext,\n url: string,\n options: Texture2DOptions,\n): Promise<Texture2D> {\n const texture = await loadKtx2Texture2D(engine, url, options.srgb ?? false);\n const hasMips = texture.texture.mipLevelCount > 1;\n const minFilter = options.minFilter ?? \"linear\";\n const magFilter = options.magFilter ?? \"linear\";\n const mipmapFilter: GPUMipmapFilterMode = hasMips ? \"linear\" : \"nearest\";\n // WebGPU accepts anisotropy only when every filter is linear; this is Lite's own rule for\n // `loadTexture2D`.\n const allLinear = minFilter === \"linear\" && magFilter === \"linear\" && mipmapFilter === \"linear\";\n texture.sampler = getOrCreateSampler(engine, {\n addressModeU: options.addressModeU ?? \"repeat\",\n addressModeV: options.addressModeV ?? \"repeat\",\n minFilter,\n magFilter,\n mipmapFilter,\n maxAnisotropy: allLinear ? 4 : 1,\n });\n return texture;\n}\n\n/**\n * Loads a `.basis` texture through Lite's Basis Universal loader.\n *\n * @remarks\n * Sampler and sRGB options apply; `mipMaps` and `invertY` are ignored by Lite. The transcoder always\n * comes from the Babylon CDN (see the module comment).\n *\n * @param engine - The engine that owns the GPU texture.\n * @param url - Where to fetch the file from.\n * @param options - Colour space and sampler.\n * @returns The texture.\n *\n * @internal\n */\nexport function loadBasisTextureWithOptions(\n engine: EngineContext,\n url: string,\n options: Texture2DOptions,\n): Promise<Texture2D> {\n return loadBasisTexture2D(engine, url, options);\n}\n"],"mappings":";;;;;;;;;AAqFA,SAAgB,qBAAqB,MAA6B;CAChE,IAAI,KAAK,gBAAgB,MAAM;EAE7B,MAAM,cAAsD,CAAC;EAC7D,KAAK,MAAM,CAAC,MAAM,eAAe,OAAO,QAAQ,KAAK,eAAe,GAClE,YAAY,QAAQ,EAAE,GAAG,WAAW;EAEtC,kBAAkB,KAAK,aAAa,WAAW;CACjD;CACA,IAAI,KAAK,mBAAmB,MAC1B,kBAAkB,KAAK,cAAc;CAEvC,IAAI,KAAK,iBAAiB,MACxB,gBAAgB,KAAK,YAAY;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,eAAsB,2BACpB,QACA,KACA,SACoB;CACpB,MAAM,UAAU,MAAM,kBAAkB,QAAQ,KAAK,QAAQ,QAAQ,KAAK;CAC1E,MAAM,UAAU,QAAQ,QAAQ,gBAAgB;CAChD,MAAM,YAAY,QAAQ,aAAa;CACvC,MAAM,YAAY,QAAQ,aAAa;CACvC,MAAM,eAAoC,UAAU,WAAW;CAG/D,MAAM,YAAY,cAAc,YAAY,cAAc,YAAY,iBAAiB;CACvF,QAAQ,UAAU,mBAAmB,QAAQ;EAC3C,cAAc,QAAQ,gBAAgB;EACtC,cAAc,QAAQ,gBAAgB;EACtC;EACA;EACA;EACA,eAAe,YAAY,IAAI;CACjC,CAAC;CACD,OAAO;AACT;;;;;;;;;;;;;;;AAgBA,SAAgB,4BACd,QACA,KACA,SACoB;CACpB,OAAO,mBAAmB,QAAQ,KAAK,OAAO;AAChD"}
|
|
@@ -19,7 +19,8 @@ const FOG_MODES = {
|
|
|
19
19
|
linear: 3
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
22
|
-
* The tone-mapping curves `docs/architecture/07-rendering.md` §2.5 exposes.
|
|
22
|
+
* The tone-mapping curves `docs/architecture/07-rendering.md` §2.5 exposes. `"agx"` is ignifx's
|
|
23
|
+
* own Lite curve (`./agx-tone-mapping.ts`); the others are Lite's built-ins.
|
|
23
24
|
*
|
|
24
25
|
* @public
|
|
25
26
|
*/
|
|
@@ -27,9 +28,15 @@ const TONE_MAPPING_NAMES = [
|
|
|
27
28
|
"none",
|
|
28
29
|
"standard",
|
|
29
30
|
"aces",
|
|
30
|
-
"neutral"
|
|
31
|
+
"neutral",
|
|
32
|
+
"agx"
|
|
31
33
|
];
|
|
32
34
|
/**
|
|
35
|
+
* The `id` of the AgX curve, repeated from `./agx-tone-mapping.ts` so recognising it does not load
|
|
36
|
+
* that chunk.
|
|
37
|
+
*/
|
|
38
|
+
const AGX_TONE_MAPPING_ID = "ignifx-agx";
|
|
39
|
+
/**
|
|
33
40
|
* Loads an `.env` environment and installs it on a scene.
|
|
34
41
|
*
|
|
35
42
|
* @param scene - The scene to light.
|
|
@@ -221,6 +228,12 @@ function setSceneImageProcessingOptions(scene, exposure, contrast, toneMapping)
|
|
|
221
228
|
contrast,
|
|
222
229
|
toneMappingEnabled: false
|
|
223
230
|
});
|
|
231
|
+
if (toneMapping === "agx") return import("./agx-tone-mapping-Cgt844j6.js").then(({ AgxToneMapping }) => setSceneImageProcessing(scene, {
|
|
232
|
+
exposure,
|
|
233
|
+
contrast,
|
|
234
|
+
toneMappingEnabled: true,
|
|
235
|
+
toneMapping: AgxToneMapping
|
|
236
|
+
}));
|
|
224
237
|
return setSceneImageProcessing(scene, {
|
|
225
238
|
exposure,
|
|
226
239
|
contrast,
|
|
@@ -260,13 +273,14 @@ function curveName(curve) {
|
|
|
260
273
|
case StandardToneMapping.id: return "standard";
|
|
261
274
|
case AcesToneMapping.id: return "aces";
|
|
262
275
|
case NeutralToneMapping.id: return "neutral";
|
|
276
|
+
case AGX_TONE_MAPPING_ID: return "agx";
|
|
263
277
|
default: return "none";
|
|
264
278
|
}
|
|
265
279
|
}
|
|
266
280
|
/**
|
|
267
281
|
* Maps an ignifx tone-mapping name onto the Lite curve object.
|
|
268
282
|
*
|
|
269
|
-
* @param name - The curve name; `"none"`
|
|
283
|
+
* @param name - The curve name; `"none"` and the lazily loaded `"agx"` are handled by the caller.
|
|
270
284
|
* @returns The Lite curve.
|
|
271
285
|
*/
|
|
272
286
|
function toneMappingCurve(name) {
|
|
@@ -280,4 +294,4 @@ function toneMappingCurve(name) {
|
|
|
280
294
|
//#endregion
|
|
281
295
|
export { readSceneImageProcessing as a, setSceneEnvironmentRotation as c, readSceneEnvironment as i, setSceneFog as l, installSceneEnvironment as n, setSceneClearColor as o, loadSceneEnvironment as r, setSceneEnvironmentBlur as s, TONE_MAPPING_NAMES as t, setSceneImageProcessingOptions as u };
|
|
282
296
|
|
|
283
|
-
//# sourceMappingURL=environment-
|
|
297
|
+
//# sourceMappingURL=environment-DPi0_0SP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment-DPi0_0SP.js","names":[],"sources":["../src/lite/gpu/environment.ts"],"sourcesContent":["import {\n AcesToneMapping,\n loadEnvironment,\n loadSkybox,\n NeutralToneMapping,\n setEnvironmentBlur,\n setEnvironmentRotation,\n setFog,\n setSceneImageProcessing,\n StandardToneMapping,\n} from \"@babylonjs/lite\";\nimport { assertNever } from \"../../errors/ignifx-error.js\";\nimport { Color } from \"../../math/color.js\";\nimport { degToRad } from \"../../math/math-utils.js\";\nimport type { EnvironmentTextures, SceneContext, ToneMapping } from \"@babylonjs/lite\";\n\n/**\n * Environment half of the Babylon Lite adapter (`docs/architecture/07-rendering.md` §2.5): image\n * based lighting, the skybox, fog, image processing, and the clear colour.\n *\n * Everything here is `@internal`. Loading uploads cube maps, so the module is GPU-only.\n *\n * ## The BRDF LUT is mandatory (verified against `@babylonjs/lite@1.27.0`)\n *\n * `loadEnvironment(scene, url, options)` (`index.d.ts` 6779) takes a **required** `brdfUrl`: Lite\n * decodes the split-sum BRDF lookup table from a pre-baked RGBD PNG rather than computing it, \"for\n * pixel-perfect parity\" with Babylon.js (`lib/_chunks/env-helpers-*.js`, `loadBrdfImage`, which\n * `fetch`es the URL and decodes it with `createImageBitmap`). ignifx ships that PNG as\n * `tests/fixtures/assets/brdf-lut.png`, decoded from Babylon.js's own\n * `_environmentBRDFBase64Texture` (`packages/dev/core/src/Misc/brdfTextureTools.ts`, Apache-2.0).\n * It is 256×256 RGBA8 and 23 KB.\n *\n * ## Fog\n *\n * `SceneContext.fog` is `FogConfig | null` (`index.d.ts` 5350) with a numeric `mode`; Lite exports\n * no named constants for it, so {@link FOG_MODES} maps ignifx's names onto the numbers.\n *\n * **Fog has to be installed with `setFog`, not by assigning the field.** `scene.fog` is what the PBR\n * group builder reads to decide whether a material's program gets the fog block at all\n * (`lib/material/pbr/pbr-renderable.js` 140-159, `PBR_HAS_FOG`), but the block it compiles reads\n * `scene.vFogInfos.x` out of the scene uniform buffer — and the only writer of those slots is\n * `writeFogUbo`, which nothing registers except `setFog`\n * (`lib/scene/scene-ubo-extras.js`: `setFog` is `scene.fog = config` **plus**\n * `_registerSceneUboContributor(scene, writeFogUbo)`, and `_writePassSceneUBO` runs\n * `scene._sceneUboContributors` and nothing else, `lib/frame-graph/render-task.js` 372-379).\n * Lite says as much in `index.d.ts` 10471: \"importing `setFog` is what pulls the fog UBO writer into\n * the bundle\". Assigning `scene.fog` alone therefore compiles the fog block into every PBR pipeline\n * and leaves `vFogInfos` zeroed, so `vFogInfos.x > 0.0` is never true and the scene renders with no\n * fog at all — the cost with none of the effect.\n *\n * A **fresh** config object goes in on every change, because a render task caches its scene UBO on\n * the identity of `scene.fog` (`s[1] === fog`, `lib/frame-graph/render-task.js` 355-371): mutating\n * the installed object in place leaves the cache key equal and the new density or colour never\n * reaches the GPU. Turning fog off writes mode `0`, which is what the already-compiled fog block\n * reads as \"no fog\"; dropping the field back to `null` would only stop the writer and leave the last\n * fog standing. A scene that never had fog keeps its `null` and pays nothing.\n *\n * ## Image processing\n *\n * `setSceneImageProcessing` is **async** (`index.d.ts` 10917) because tone mapping is baked into\n * the PBR shaders at `registerScene` time; changing it recompiles the affected pipelines\n * (`rebuildScenePbrPipelines`). Setting exposure or contrast alone still goes through the same\n * call. Note that `loadEnvironment` **overwrites** all three (`toneMappingEnabled = true`,\n * `exposure = 0.8`, `contrast = 1.2`) as a side effect of installing an environment, which is why\n * the `Environment` component re-applies its own image processing after every install.\n *\n * ## Swapping the installed environment: `scene._envTextures`\n *\n * Lite 1.27.0 declares **no** public way to replace, clear, or read back a registered scene's\n * environment. `index.d.ts` has no `scene.environmentTexture`, no `unloadEnvironment`, and no\n * setter of any kind; `loadEnvironment` is the only installer and it fetches, decodes, and uploads\n * a fresh cube map every call. What it actually installs is one field —\n * `scene._envTextures = textures` (`lib/_chunks/env-helpers-CRI1i-A3.js` 24, and the same line in\n * `lib/loader-hdr/load-hdr.js` 23, `lib/loader-env/load-dds-env.js` 177 and\n * `lib/loader-gltf/gltf-ext-lights-image-based.js` 65) — and every consumer reads that field:\n *\n * - the PBR group builder, which bakes the cube view and sampler into each material's bind group\n * (`lib/material/pbr/pbr-material.js` 12 → `lib/material/pbr/pbr-renderable.js`);\n * - the scene-uniform packer, for `lodGenerationScale` (`lib/frame-graph/scene-uniforms-pack.js` 21);\n * - the env UBO contributor, for the diffuse spherical harmonics (`lib/scene/scene-ubo-extras.js` 24);\n * - the blur contributor, for `lodGenerationOffset` (`lib/scene/set-environment-blur.js` 8);\n * - the render task's scene-UBO cache key, which is keyed on the **object identity** of the field\n * (`lib/frame-graph/render-task.js` 358), so a new object re-uploads the harmonics by itself.\n *\n * Lite's own device-lost recovery replaces the field exactly this way\n * (`lib/loader-env/environment-recovery.js` 16 and 38), so {@link installSceneEnvironment} writes it\n * too. Bind groups are the one consumer that does *not* re-read it: they hold the `GPUTextureView`,\n * so a swap only reaches the specular reflection once the material groups have been rebuilt, which\n * `rebuildSceneRenderables` does (`lib/scene/scene-rebuild.js`, `rebuildEachGroup`). The\n * `Environment` component therefore reports an install as a topology change and lets the render-sync\n * system fire its one coalesced rebuild. This is the only place in ignifx that touches a Lite field\n * `index.d.ts` does not declare, which is what the adapter boundary exists for\n * (`CONSTITUTION.md` §3.4, ADR-0002); it is pinned by\n * `packages/core/test/lite/render/environment.browser.test.ts`, which fails loudly if the field is\n * renamed.\n */\n\n/**\n * The GPU-resident image-based-lighting textures `loadEnvironment` resolves to, re-exported under an\n * ignifx name (`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 LiteEnvironmentTextures = EnvironmentTextures;\n\n/**\n * ignifx fog mode names mapped to the numbers `FogConfig.mode` uses.\n *\n * @internal\n */\nexport const FOG_MODES = {\n /** No fog. */\n none: 0,\n /** Exponential fog. */\n exp: 1,\n /** Squared-exponential fog. */\n exp2: 2,\n /** Linear fog between `start` and `end`. */\n linear: 3,\n} as const;\n\n/**\n * The union of the fog mode names.\n *\n * @internal\n */\nexport type FogMode = keyof typeof FOG_MODES;\n\n/**\n * The tone-mapping curves `docs/architecture/07-rendering.md` §2.5 exposes. `\"agx\"` is ignifx's\n * own Lite curve (`./agx-tone-mapping.ts`); the others are Lite's built-ins.\n *\n * @public\n */\nexport const TONE_MAPPING_NAMES = [\"none\", \"standard\", \"aces\", \"neutral\", \"agx\"] as const;\n\n/**\n * The `id` of the AgX curve, repeated from `./agx-tone-mapping.ts` so recognising it does not load\n * that chunk.\n */\nconst AGX_TONE_MAPPING_ID = \"ignifx-agx\";\n\n/**\n * The union of the tone-mapping curve names.\n *\n * @internal\n */\nexport type ToneMappingName = (typeof TONE_MAPPING_NAMES)[number];\n\n/**\n * The image processing Lite's PBR shaders apply: exposure, contrast and the tone-mapping curve.\n *\n * @internal\n */\nexport interface ImageProcessingState {\n /** The exposure multiplier. */\n exposure: number;\n /** The contrast multiplier. */\n contrast: number;\n /** The tone-mapping curve, or `\"none\"`. */\n curve: ToneMappingName;\n}\n\n/**\n * How an ignifx `Environment` component configures image based lighting.\n *\n * @internal\n */\nexport interface EnvironmentLoadOptions {\n /** The `.env` file holding the prefiltered specular cube map and its spherical harmonics. */\n readonly url: string;\n /** The RGBD PNG BRDF lookup table. Required by Lite. */\n readonly brdfUrl: string;\n /** A `.dds` or `.env` skybox. Omit for a flat background. */\n readonly skyboxUrl?: string;\n /** The skybox cube's size, in metres. Lite defaults to 20. */\n readonly skyboxSize?: number;\n /** Skip the skybox entirely. */\n readonly skipSkybox?: boolean;\n /** Skip the reflective ground plane Lite would otherwise add. */\n readonly skipGround?: boolean;\n /** A texture for that ground plane. */\n readonly groundTextureUrl?: string;\n}\n\n/**\n * Loads an `.env` environment and installs it on a scene.\n *\n * @param scene - The scene to light.\n * @param options - The environment, BRDF, and skybox URLs.\n * @returns The GPU-resident environment textures, for materials that need them explicitly.\n *\n * @example\n * ```ts\n * await loadSceneEnvironment(scene, {\n * url: \"environments/studio.env\",\n * brdfUrl: \"environments/brdf-lut.png\",\n * });\n * ```\n *\n * @internal\n */\nexport function loadSceneEnvironment(\n scene: SceneContext,\n options: EnvironmentLoadOptions,\n): Promise<EnvironmentTextures> {\n const liteOptions: {\n brdfUrl: string;\n skyboxUrl?: string;\n skyboxSize?: number;\n skipSkybox?: boolean;\n skipGround?: boolean;\n groundTextureUrl?: string;\n } = { brdfUrl: options.brdfUrl };\n if (options.skyboxUrl !== undefined) {\n liteOptions.skyboxUrl = options.skyboxUrl;\n }\n if (options.skyboxSize !== undefined) {\n liteOptions.skyboxSize = options.skyboxSize;\n }\n if (options.skipSkybox !== undefined) {\n liteOptions.skipSkybox = options.skipSkybox;\n }\n if (options.skipGround !== undefined) {\n liteOptions.skipGround = options.skipGround;\n }\n if (options.groundTextureUrl !== undefined) {\n liteOptions.groundTextureUrl = options.groundTextureUrl;\n }\n return loadEnvironment(scene, options.url, liteOptions);\n}\n\n/**\n * The scene fields Babylon Lite 1.27.0 writes for image-based lighting but does not declare in\n * `index.d.ts`. Adapter-internal Lite mirror (coding standards §5.1); see the module header for the\n * `lib/` lines that prove each one.\n */\ninterface SceneEnvironmentSlot {\n /** What `loadEnvironment` installed, or `undefined` on a scene that has never had one. */\n _envTextures?: EnvironmentTextures | undefined;\n}\n\n/**\n * Views a scene through its undeclared environment slot.\n *\n * @param scene - The scene.\n * @returns The same object, typed so the slot is reachable.\n */\nfunction environmentSlotOf(scene: SceneContext): SceneEnvironmentSlot {\n // Boundary assertion (coding standards §5.2): `SceneContext` is a plain object literal Lite\n // creates in `lib/scene/scene-core.js`, and `_envTextures` is one of its own fields — it is\n // absent from `index.d.ts` because it is not part of Lite's declared surface, not because it is\n // a different object. See the module header for every `lib/` line that reads or writes it.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n return scene as SceneContext & SceneEnvironmentSlot;\n}\n\n/**\n * Reports which environment textures a scene is currently lit by.\n *\n * @param scene - The scene to inspect.\n * @returns The installed textures, or `null` when no environment has ever been installed.\n *\n * @internal\n */\nexport function readSceneEnvironment(scene: SceneContext): EnvironmentTextures | null {\n // The underscore is Lite's, not ignifx's: coding standards §5.1 reserves `_field` for exactly\n // this, an adapter-internal mirror of a Lite field, and the module header proves the name.\n // oxlint-disable-next-line no-underscore-dangle\n return environmentSlotOf(scene)._envTextures ?? null;\n}\n\n/**\n * Points a scene at an already-loaded set of environment textures, without loading anything.\n *\n * @remarks\n * This is how an `Environment` component swaps environments at runtime: the textures belong to the\n * `EnvironmentAsset` that loaded them and stay alive as long as its handle is retained, so\n * switching between two loaded assets uploads nothing and frees nothing.\n *\n * The specular reflection follows only after the scene's material groups are rebuilt\n * (`rebuildRenderables` in `../shadow.ts`): a PBR bind group holds the cube map's `GPUTextureView`,\n * not the slot. The diffuse harmonics and the LOD scale follow immediately, because the render\n * task's scene-UBO cache is keyed on this object's identity.\n *\n * @param scene - The scene to light.\n * @param textures - The textures to light it with.\n * @returns `true` when the scene was lit by something else and now is not — the caller owes a\n * renderable rebuild; `false` when these textures were already installed and nothing was written.\n *\n * @example\n * ```ts\n * if (installSceneEnvironment(scene, asset.lite.textures)) {\n * await rebuildRenderables(scene);\n * }\n * ```\n *\n * @internal\n */\nexport function installSceneEnvironment(scene: SceneContext, textures: EnvironmentTextures): boolean {\n const slot = environmentSlotOf(scene);\n // As in `readSceneEnvironment`: an adapter-internal Lite mirror (coding standards §5.1).\n // oxlint-disable-next-line no-underscore-dangle\n if (slot._envTextures === textures) {\n return false;\n }\n // oxlint-disable-next-line no-underscore-dangle\n slot._envTextures = textures;\n return true;\n}\n\n/**\n * Loads a six-face cube-map skybox from a base URL.\n *\n * @param scene - The scene to give a background.\n * @param baseUrl - The URL prefix each face name is appended to.\n * @param extension - The face file extension, such as `\".jpg\"`.\n * @param size - The skybox cube's size, in metres.\n * @returns A promise that resolves when the faces are uploaded.\n *\n * @internal\n */\nexport function loadSceneSkybox(scene: SceneContext, baseUrl: string, extension: string, size?: number): Promise<void> {\n return loadSkybox(scene, baseUrl, extension, size);\n}\n\n/**\n * Rotates the environment around the world Y axis.\n *\n * @param scene - The scene to rotate the environment of.\n * @param degrees - The rotation, in degrees.\n *\n * @internal\n */\nexport function setSceneEnvironmentRotation(scene: SceneContext, degrees: number): void {\n setEnvironmentRotation(scene, degToRad(degrees));\n}\n\n/**\n * Blurs the visible skybox. Babylon Lite patches only the skybox shader; no material reads the value.\n *\n * @param scene - The scene to change.\n * @param blur - The blur amount, 0 to 1.\n *\n * @internal\n */\nexport function setSceneEnvironmentBlur(scene: SceneContext, blur: number): void {\n setEnvironmentBlur(scene, blur);\n}\n\n/**\n * Sets the colour the scene is cleared to each frame, so that it presents as the sRGB value given.\n *\n * @remarks\n * Lite stores the clear value into the colour target untouched. Tone mapping, image processing and\n * bloom's threshold never apply to it on the GPU (the renderer applies image processing before this\n * call, `src/render/image-processing-color.ts`), and Lite's own transmission and solid-skybox paths read it\n * as the colour that should come out (`lib/frame-graph/transmission.js` `executeRenderTaskLinear`,\n * `lib/material/pbr/background-solid-skybox.js`). The default surface format is not an sRGB one,\n * so the sRGB value is written unchanged. Only an `*-srgb` surface view (`rendering.srgb: true`)\n * encodes on write; there the value is decoded first, so that the GPU's encoding gives it back.\n * Every target ignifx renders the scene into uses the surface's format (`./render-path.ts`), so\n * the same rule holds on the offscreen path.\n *\n * @param scene - The scene to change.\n * @param r - The sRGB red component, 0 to 1.\n * @param g - The sRGB green component, 0 to 1.\n * @param b - The sRGB blue component, 0 to 1.\n * @param a - The alpha component; only meaningful with a premultiplied canvas alpha mode.\n *\n * @internal\n */\nexport function setSceneClearColor(scene: SceneContext, r: number, g: number, b: number, a: number): void {\n const clear = scene.clearColor;\n const decode = isSrgbEncodingFormat(scene.surface.format);\n clear.r = decode ? Color.srgbToLinear(r) : r;\n clear.g = decode ? Color.srgbToLinear(g) : g;\n clear.b = decode ? Color.srgbToLinear(b) : b;\n clear.a = a;\n}\n\n/**\n * Whether a colour target of this format encodes linear values to sRGB as they are stored.\n *\n * @param format - The target's format. Lite's null engine has none.\n * @returns `true` for an `*-srgb` format.\n *\n * @internal\n */\nexport function isSrgbEncodingFormat(format: string | undefined): boolean {\n return format?.endsWith(\"-srgb\") === true;\n}\n\n/**\n * Configures the scene's fog, or turns it off.\n *\n * @param scene - The scene to change.\n * @param mode - The fog falloff, or `\"none\"` to disable it.\n * @param r - The sRGB red component of the fog colour; Lite's fog block decodes it itself.\n * @param g - The sRGB green component.\n * @param b - The sRGB blue component.\n * @param density - The density, for the exponential modes.\n * @param start - Where linear fog begins, in metres.\n * @param end - Where linear fog reaches full strength, in metres.\n *\n * @internal\n */\nexport function setSceneFog(\n scene: SceneContext,\n mode: FogMode,\n r: number,\n g: number,\n b: number,\n density: number,\n start: number,\n end: number,\n): void {\n if (mode === \"none\" && scene.fog === null) {\n // A scene that never had fog pays nothing: no contributor, no fog block in any PBR pipeline.\n return;\n }\n setFog(scene, { mode: FOG_MODES[mode], density, start, end, color: [r, g, b] });\n}\n\n/**\n * Sets exposure, contrast, and the tone-mapping curve.\n *\n * @remarks\n * Asynchronous by nature: tone mapping is compiled into the PBR shaders, so changing it after\n * `registerScene` recompiles the scene's PBR pipelines. Exposure and contrast alone are uniform\n * values, but Lite routes them through the same call.\n *\n * @param scene - The scene to change.\n * @param exposure - The exposure multiplier.\n * @param contrast - The contrast multiplier.\n * @param toneMapping - The curve, or `\"none\"` to leave the colour untouched.\n * @returns A promise that resolves when any affected pipeline has been rebuilt.\n *\n * @internal\n */\nexport function setSceneImageProcessingOptions(\n scene: SceneContext,\n exposure: number,\n contrast: number,\n toneMapping: ToneMappingName,\n): Promise<void> {\n if (toneMapping === \"none\") {\n return setSceneImageProcessing(scene, { exposure, contrast, toneMappingEnabled: false });\n }\n if (toneMapping === \"agx\") {\n // Its own chunk: a project that never names AgX loads none of its WGSL (CONSTITUTION.md §2.5).\n return import(\"./agx-tone-mapping.js\").then(({ AgxToneMapping }) =>\n setSceneImageProcessing(scene, { exposure, contrast, toneMappingEnabled: true, toneMapping: AgxToneMapping }),\n );\n }\n return setSceneImageProcessing(scene, {\n exposure,\n contrast,\n toneMappingEnabled: true,\n toneMapping: toneMappingCurve(toneMapping),\n });\n}\n\n/**\n * Reads the image processing the scene's PBR shaders currently apply.\n *\n * @remarks\n * Read from Lite rather than from the `Environment` component, because Lite's `loadEnvironment`\n * also writes it (exposure 0.8, contrast 1.2, the standard curve) and the clear colour has to match\n * what the shaders actually do. A custom Lite curve set through `.lite` reads as `\"none\"`.\n *\n * @param scene - The scene.\n * @param out - Receives the exposure, contrast and curve.\n * @returns `out`.\n *\n * @internal\n */\nexport function readSceneImageProcessing(scene: SceneContext, out: ImageProcessingState): ImageProcessingState {\n const processing = scene.imageProcessing;\n out.exposure = processing.exposure;\n out.contrast = processing.contrast;\n out.curve = processing.toneMappingEnabled ? curveName(processing.toneMapping ?? StandardToneMapping) : \"none\";\n return out;\n}\n\n/**\n * Maps a Lite curve object back onto its ignifx name.\n *\n * @param curve - The Lite curve.\n * @returns The name, or `\"none\"` for a curve ignifx does not know.\n */\nfunction curveName(curve: ToneMapping): ToneMappingName {\n switch (curve.id) {\n case StandardToneMapping.id:\n return \"standard\";\n case AcesToneMapping.id:\n return \"aces\";\n case NeutralToneMapping.id:\n return \"neutral\";\n case AGX_TONE_MAPPING_ID:\n return \"agx\";\n default:\n return \"none\";\n }\n}\n\n/**\n * Maps an ignifx tone-mapping name onto the Lite curve object.\n *\n * @param name - The curve name; `\"none\"` and the lazily loaded `\"agx\"` are handled by the caller.\n * @returns The Lite curve.\n */\nfunction toneMappingCurve(name: Exclude<ToneMappingName, \"none\" | \"agx\">): ToneMapping {\n switch (name) {\n case \"standard\":\n return StandardToneMapping;\n case \"aces\":\n return AcesToneMapping;\n case \"neutral\":\n return NeutralToneMapping;\n default:\n return assertNever(name, \"tone mapping\");\n }\n}\n"],"mappings":"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"}
|