@ignifx/core 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/{color-CpvebMIh.js → color-DrR6GFTd.js} +3 -276
  2. package/dist/color-DrR6GFTd.js.map +1 -0
  3. package/dist/{environment-CTM7BAyb.js → environment-mr5wp69e.js} +3 -2
  4. package/dist/{environment-CTM7BAyb.js.map → environment-mr5wp69e.js.map} +1 -1
  5. package/dist/index.d.ts +140 -88
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1353 -2797
  8. package/dist/index.js.map +1 -1
  9. package/dist/{instanced-mesh-instance-Cgx1H87p.js → instanced-mesh-instance-DYwH0vLi.js} +74 -10
  10. package/dist/instanced-mesh-instance-DYwH0vLi.js.map +1 -0
  11. package/dist/{material-plugin-Cfw_h_Mg.js → material-plugin-BRnhfw7K.js} +2 -2
  12. package/dist/material-plugin-BRnhfw7K.js.map +1 -0
  13. package/dist/math-utils-BcDnL-gi.js +277 -0
  14. package/dist/math-utils-BcDnL-gi.js.map +1 -0
  15. package/dist/shader-declaration-5q__jycG.js.map +1 -1
  16. package/dist/{shader-material-CJxMJEUO.js → shader-material-BIG3UDyu.js} +3 -3
  17. package/dist/{shader-material-CJxMJEUO.js.map → shader-material-BIG3UDyu.js.map} +1 -1
  18. package/dist/{shader-material-F-CL4D70.js → shader-material-U6BKZ8D1.js} +2 -2
  19. package/dist/{shader-material-F-CL4D70.js.map → shader-material-U6BKZ8D1.js.map} +1 -1
  20. package/dist/{shader-pragma-D4HKC9vP.js → shader-pragma-tw6AKaQD.js} +24 -3
  21. package/dist/shader-pragma-tw6AKaQD.js.map +1 -0
  22. package/dist/{surface-shader-Chs7wOAE.js → surface-shader-Br17yysO.js} +7 -5
  23. package/dist/{surface-shader-Chs7wOAE.js.map → surface-shader-Br17yysO.js.map} +1 -1
  24. package/dist/vec3-T2PasQZv.js +2458 -0
  25. package/dist/vec3-T2PasQZv.js.map +1 -0
  26. package/package.json +2 -2
  27. package/dist/color-CpvebMIh.js.map +0 -1
  28. package/dist/instanced-mesh-instance-Cgx1H87p.js.map +0 -1
  29. package/dist/material-plugin-Cfw_h_Mg.js.map +0 -1
  30. package/dist/mesh-CnK_PX46.js +0 -811
  31. package/dist/mesh-CnK_PX46.js.map +0 -1
  32. package/dist/shader-pragma-D4HKC9vP.js.map +0 -1
@@ -1,277 +1,4 @@
1
- //#region src/math/math-utils.ts
2
- /**
3
- * Scalar helpers shared by the vector, quaternion and matrix types and by game code.
4
- *
5
- * Angles are **degrees** in every public API unless the name ends in `Rad`/`Radians`
6
- * (coding standards §5.1, ADR-0011). Every function here is a pure scalar function: none of them
7
- * allocate, so they are safe in per-frame code (coding standards §7).
8
- */
9
- /**
10
- * The default tolerance for approximate float comparisons. Chosen for single-precision positions in
11
- * metres: `Float32Array` round-tripping loses roughly 1e-7 of relative precision, so 1e-6 is the
12
- * smallest value that does not report false differences on data that has been through the GPU.
13
- *
14
- * @public
15
- */
16
- const EPSILON = 1e-6;
17
- /**
18
- * Multiplier that converts degrees to radians.
19
- *
20
- * @public
21
- */
22
- const DEG_TO_RAD = Math.PI / 180;
23
- /**
24
- * Multiplier that converts radians to degrees.
25
- *
26
- * @public
27
- */
28
- const RAD_TO_DEG = 180 / Math.PI;
29
- /**
30
- * Converts an angle from degrees to radians.
31
- *
32
- * @param degrees - The angle in degrees.
33
- * @returns The same angle in radians.
34
- *
35
- * @public
36
- */
37
- function degToRad(degrees) {
38
- return degrees * DEG_TO_RAD;
39
- }
40
- /**
41
- * Converts an angle from radians to degrees.
42
- *
43
- * @param radians - The angle in radians.
44
- * @returns The same angle in degrees.
45
- *
46
- * @public
47
- */
48
- function radToDeg(radians) {
49
- return radians * RAD_TO_DEG;
50
- }
51
- /**
52
- * Constrains a value to an inclusive range.
53
- *
54
- * @param value - The value to constrain.
55
- * @param min - The lower bound.
56
- * @param max - The upper bound.
57
- * @returns `min` when `value` is smaller, `max` when it is larger, otherwise `value` unchanged.
58
- * `NaN` propagates.
59
- *
60
- * @example
61
- * ```ts
62
- * clamp(12, 0, 10); // 10
63
- * ```
64
- *
65
- * @public
66
- */
67
- function clamp(value, min, max) {
68
- if (value < min) return min;
69
- if (value > max) return max;
70
- return value;
71
- }
72
- /**
73
- * Constrains a value to the 0–1 range.
74
- *
75
- * @param value - The value to constrain.
76
- * @returns The value clamped into `[0, 1]`.
77
- *
78
- * @public
79
- */
80
- function clamp01(value) {
81
- return clamp(value, 0, 1);
82
- }
83
- /**
84
- * Linearly interpolates between two values. The interpolant is **not** clamped, so values outside
85
- * `[0, 1]` extrapolate; wrap `t` in {@link clamp01} when that is not wanted.
86
- *
87
- * @param a - The value returned at `t === 0`.
88
- * @param b - The value returned at `t === 1`.
89
- * @param t - The interpolant.
90
- * @returns The interpolated value.
91
- *
92
- * @example
93
- * ```ts
94
- * lerp(0, 10, 0.25); // 2.5
95
- * ```
96
- *
97
- * @public
98
- */
99
- function lerp(a, b, t) {
100
- return a + (b - a) * t;
101
- }
102
- /**
103
- * The inverse of {@link lerp}: finds the interpolant that maps `a`–`b` onto `value`.
104
- *
105
- * @param a - The value that maps to 0.
106
- * @param b - The value that maps to 1.
107
- * @param value - The value to locate.
108
- * @returns The interpolant, clamped into `[0, 1]`. Returns 0 when `a` and `b` are equal.
109
- *
110
- * @public
111
- */
112
- function inverseLerp(a, b, value) {
113
- if (a === b) return 0;
114
- return clamp01((value - a) / (b - a));
115
- }
116
- /**
117
- * Smoothly interpolates between two edges with a Hermite curve (the GLSL `smoothstep`), easing in
118
- * and out instead of the straight ramp of {@link lerp}.
119
- *
120
- * @param edge0 - The value below which the result is 0.
121
- * @param edge1 - The value above which the result is 1.
122
- * @param x - The value to map.
123
- * @returns A value in `[0, 1]`. Degenerate edges (`edge0 === edge1`) step from 0 to 1 at the edge.
124
- *
125
- * @example
126
- * ```ts
127
- * smoothStep(0, 1, 0.5); // 0.5, but with zero slope at 0 and 1
128
- * ```
129
- *
130
- * @public
131
- */
132
- function smoothStep(edge0, edge1, x) {
133
- if (edge0 === edge1) return x < edge0 ? 0 : 1;
134
- const t = clamp01((x - edge0) / (edge1 - edge0));
135
- return t * t * (3 - 2 * t);
136
- }
137
- /**
138
- * Moves a value towards a target without overshooting it.
139
- *
140
- * @param current - The value to move.
141
- * @param target - The value to move towards.
142
- * @param maxDelta - The largest step allowed this call; negative values move away from the target.
143
- * @returns The stepped value, exactly `target` once the remaining distance fits in `maxDelta`.
144
- *
145
- * @example
146
- * ```ts
147
- * // frame-rate independent approach at 2 units per second
148
- * health = moveTowards(health, 100, 2 * time.deltaTime);
149
- * ```
150
- *
151
- * @public
152
- */
153
- function moveTowards(current, target, maxDelta) {
154
- const delta = target - current;
155
- if (Math.abs(delta) <= maxDelta) return target;
156
- return current + (delta < 0 ? -maxDelta : maxDelta);
157
- }
158
- /**
159
- * Wraps a value into `[0, length)`, the way a looping animation time behaves. Unlike `%` the result
160
- * is never negative.
161
- *
162
- * @param t - The value to wrap.
163
- * @param length - The positive period to wrap into.
164
- * @returns The wrapped value, clamped into `[0, length]` so float error cannot escape the range.
165
- *
166
- * @example
167
- * ```ts
168
- * repeat(-1, 4); // 3
169
- * ```
170
- *
171
- * @public
172
- */
173
- function repeat(t, length) {
174
- return clamp(t - Math.floor(t / length) * length, 0, length);
175
- }
176
- /**
177
- * Bounces a value back and forth between 0 and `length`, the way a ping-pong animation behaves.
178
- *
179
- * @param t - The value to fold.
180
- * @param length - The positive half-period to fold into.
181
- * @returns A value in `[0, length]` that rises then falls as `t` increases.
182
- *
183
- * @example
184
- * ```ts
185
- * pingPong(5, 4); // 3
186
- * ```
187
- *
188
- * @public
189
- */
190
- function pingPong(t, length) {
191
- return length - Math.abs(repeat(t, length * 2) - length);
192
- }
193
- /**
194
- * Compares two numbers with an absolute tolerance. Use this instead of `===` on anything that has
195
- * been through a matrix, a quaternion or a `Float32Array`.
196
- *
197
- * @param a - The first value.
198
- * @param b - The second value.
199
- * @param epsilon - The largest difference still considered equal. Defaults to {@link EPSILON}.
200
- * @returns `true` when the values differ by no more than `epsilon`. `NaN` is never approximately
201
- * equal to anything, including itself.
202
- *
203
- * @public
204
- */
205
- function approximately(a, b, epsilon = EPSILON) {
206
- return Math.abs(a - b) <= epsilon;
207
- }
208
- /**
209
- * The sign of a value, with zero treated as positive (matching Unity's `Mathf.Sign`, and unlike
210
- * `Math.sign`, which returns 0 and `-0`).
211
- *
212
- * @param value - The value to inspect.
213
- * @returns `-1` for negative values, `1` for positive values and for both `0` and `-0`, and `NaN`
214
- * for `NaN`.
215
- *
216
- * @public
217
- */
218
- function sign(value) {
219
- if (Number.isNaN(value)) return NaN;
220
- return value < 0 ? -1 : 1;
221
- }
222
- /**
223
- * Wraps an angle in degrees into `[-180, 180)`, the range rotations are most readable in.
224
- *
225
- * @param degrees - The angle to wrap.
226
- * @returns The equivalent angle in `[-180, 180)`; exactly `180` wraps to `-180`.
227
- *
228
- * @example
229
- * ```ts
230
- * wrapAngleDegrees(370); // 10
231
- * wrapAngleDegrees(-190); // 170
232
- * ```
233
- *
234
- * @public
235
- */
236
- function wrapAngleDegrees(degrees) {
237
- return repeat(degrees + 180, 360) - 180;
238
- }
239
- /**
240
- * The shortest signed rotation from one angle to another, in degrees.
241
- *
242
- * @param fromDegrees - The starting angle.
243
- * @param toDegrees - The target angle.
244
- * @returns The signed difference in `[-180, 180)`.
245
- *
246
- * @example
247
- * ```ts
248
- * deltaAngleDegrees(350, 10); // 20, not -340
249
- * ```
250
- *
251
- * @public
252
- */
253
- function deltaAngleDegrees(fromDegrees, toDegrees) {
254
- return wrapAngleDegrees(toDegrees - fromDegrees);
255
- }
256
- /**
257
- * Interpolates between two angles in degrees the short way around the circle.
258
- *
259
- * @param fromDegrees - The angle returned at `t === 0`.
260
- * @param toDegrees - The angle approached at `t === 1`.
261
- * @param t - The interpolant; not clamped, matching {@link lerp}.
262
- * @returns The interpolated angle. It is not wrapped, so feeding the result back in is stable.
263
- *
264
- * @example
265
- * ```ts
266
- * lerpAngleDegrees(350, 10, 0.5); // 360
267
- * ```
268
- *
269
- * @public
270
- */
271
- function lerpAngleDegrees(fromDegrees, toDegrees, t) {
272
- return fromDegrees + deltaAngleDegrees(fromDegrees, toDegrees) * t;
273
- }
274
- //#endregion
1
+ import { n as EPSILON, o as clamp01, u as lerp } from "./math-utils-BcDnL-gi.js";
275
2
  //#region src/math/color.ts
276
3
  /**
277
4
  * Matches `#rrggbb`, `#rrggbbaa`, and the same two without the leading `#`.
@@ -619,6 +346,6 @@ var Color = class Color {
619
346
  }
620
347
  };
621
348
  //#endregion
622
- export { sign as _, approximately as a, degToRad as c, lerp as d, lerpAngleDegrees as f, repeat as g, radToDeg as h, RAD_TO_DEG as i, deltaAngleDegrees as l, pingPong as m, DEG_TO_RAD as n, clamp as o, moveTowards as p, EPSILON as r, clamp01 as s, Color as t, inverseLerp as u, smoothStep as v, wrapAngleDegrees as y };
349
+ export { Color as t };
623
350
 
624
- //# sourceMappingURL=color-CpvebMIh.js.map
351
+ //# sourceMappingURL=color-DrR6GFTd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color-DrR6GFTd.js","names":[],"sources":["../src/math/color.ts"],"sourcesContent":["import { clamp01, EPSILON, lerp } from \"./math-utils.js\";\nimport type { ColorLike } from \"./types.js\";\n\n/**\n * Matches `#rrggbb`, `#rrggbbaa`, and the same two without the leading `#`.\n */\nconst HEX_PATTERN = /^#?(?:[\\da-f]{6}|[\\da-f]{8})$/iu;\n\n/**\n * Formats a 0-255 channel as two lowercase hex digits.\n *\n * @param value - The channel value, already rounded into 0-255.\n * @returns Two hex digits.\n */\nfunction hexByte(value: number): string {\n return value.toString(16).padStart(2, \"0\");\n}\n\n/**\n * An RGBA colour whose components are **linear** and normally in 0-1 (values above 1 are allowed\n * and mean HDR intensity). Lighting maths only works in linear space, which is why this is the\n * space ignifx stores; scene files and hex strings are sRGB, and\n * {@link Color.fromHex}/{@link Color.fromSrgb} are the doors between the two\n * (`docs/architecture/06-serialization-and-scene-format.md` section 3).\n *\n * Every method says which space it works in. The rule of thumb: if it takes or returns a hex string\n * or has `Srgb` in its name, it is sRGB; everything else is linear.\n *\n * @example\n * ```ts\n * const tint = Color.fromHex(\"#ff8800\") ?? new Color(1, 1, 1, 1); // parsed as sRGB, stored linear\n * tint.scaleRgb(2); // twice as bright, same alpha\n * tint.toHex(); // back to sRGB: \"#ffbe00\"\n * ```\n *\n * @public\n */\nexport class Color {\n /** The linear red component. */\n r: number;\n /** The linear green component. */\n g: number;\n /** The linear blue component. */\n b: number;\n /** The alpha component in 0-1. Alpha is always linear, never gamma encoded. */\n a: number;\n\n /**\n * Creates a colour from linear components.\n *\n * @param r - The linear red component. Defaults to 0.\n * @param g - The linear green component. Defaults to 0.\n * @param b - The linear blue component. Defaults to 0.\n * @param a - The alpha component. Defaults to 1 (opaque).\n */\n constructor(r: number = 0, g: number = 0, b: number = 0, a: number = 1) {\n this.r = r;\n this.g = g;\n this.b = b;\n this.a = a;\n }\n\n /**\n * Assigns every component at once, in linear space.\n *\n * @param r - The new linear red component.\n * @param g - The new linear green component.\n * @param b - The new linear blue component.\n * @param a - The new alpha component.\n * @returns This colour.\n */\n set(r: number, g: number, b: number, a: number): this {\n this.r = r;\n this.g = g;\n this.b = b;\n this.a = a;\n return this;\n }\n\n /**\n * Copies every component from another colour.\n *\n * @param c - The colour to read.\n * @returns This colour.\n */\n copyFrom(c: ColorLike): this {\n this.r = c.r;\n this.g = c.g;\n this.b = c.b;\n this.a = c.a;\n return this;\n }\n\n /**\n * Copies this colour into a new one.\n *\n * @returns A new colour. **Allocates.**\n */\n clone(): Color {\n return new Color(this.r, this.g, this.b, this.a);\n }\n\n /**\n * Multiplies this colour by another, component by component including alpha — the usual way a\n * tint is applied.\n *\n * @param c - The colour to multiply by.\n * @returns This colour.\n */\n multiply(c: ColorLike): this {\n this.r *= c.r;\n this.g *= c.g;\n this.b *= c.b;\n this.a *= c.a;\n return this;\n }\n\n /**\n * Scales the linear RGB components, leaving alpha alone. This is what \"brighter\" means: alpha is\n * coverage, not colour.\n *\n * @param factor - The intensity factor.\n * @returns This colour.\n */\n scaleRgb(factor: number): this {\n this.r *= factor;\n this.g *= factor;\n this.b *= factor;\n return this;\n }\n\n /**\n * Moves this colour towards a target, in linear space (which is where blending belongs; lerping\n * sRGB values darkens midpoints).\n *\n * @param target - The colour reached at `t === 1`.\n * @param t - The interpolant; not clamped.\n * @returns This colour.\n */\n lerp(target: ColorLike, t: number): this {\n return Color.lerpToRef(this, target, t, this);\n }\n\n /**\n * Compares this colour with another, component by component, with a tolerance.\n *\n * @param c - The colour to compare against.\n * @param epsilon - The largest per-component difference still considered equal.\n * @returns `true` when every component matches within `epsilon`.\n */\n equalsWithEpsilon(c: ColorLike, epsilon: number = EPSILON): boolean {\n return Color.equalsWithEpsilon(this, c, epsilon);\n }\n\n /**\n * Writes the **linear** components into a `Float32Array`, the form a shader wants. The output\n * comes first to mirror Babylon Lite's `toArray` helpers.\n *\n * @param out - The array to write into.\n * @param offset - The index of the red component. Defaults to 0.\n * @returns `out`.\n */\n toArray(out: Float32Array, offset: number = 0): Float32Array {\n out[offset] = this.r;\n out[offset + 1] = this.g;\n out[offset + 2] = this.b;\n out[offset + 3] = this.a;\n return out;\n }\n\n /**\n * Writes this colour's **sRGB-encoded** components into `out`, for display, pickers and files.\n * Components are clamped into 0-1 by the encoding curve.\n *\n * @param out - The colour to write; may be this colour. Its fields hold sRGB values afterwards,\n * not linear ones.\n * @returns `out`.\n */\n toSrgbToRef<TOut extends Color>(out: TOut): TOut {\n return out.set(Color.linearToSrgb(this.r), Color.linearToSrgb(this.g), Color.linearToSrgb(this.b), this.a);\n }\n\n /**\n * Encodes this colour as an sRGB hex string.\n *\n * @returns `#rrggbb` for an opaque colour, `#rrggbbaa` when alpha is below 1. **Allocates a\n * string.**\n *\n * @example\n * ```ts\n * new Color(1, 1, 1, 1).toHex(); // \"#ffffff\"\n * ```\n */\n toHex(): string {\n const r = hexByte(Math.round(Color.linearToSrgb(this.r) * 255));\n const g = hexByte(Math.round(Color.linearToSrgb(this.g) * 255));\n const b = hexByte(Math.round(Color.linearToSrgb(this.b) * 255));\n const alpha = clamp01(this.a);\n if (alpha >= 1) {\n return `#${r}${g}${b}`;\n }\n return `#${r}${g}${b}${hexByte(Math.round(alpha * 255))}`;\n }\n\n /**\n * Opaque white.\n *\n * @returns A new linear `(1, 1, 1, 1)`. **Allocates.**\n */\n static white(): Color {\n return new Color(1, 1, 1, 1);\n }\n\n /**\n * Opaque black.\n *\n * @returns A new linear `(0, 0, 0, 1)`. **Allocates.**\n */\n static black(): Color {\n return new Color(0, 0, 0, 1);\n }\n\n /**\n * Fully transparent black.\n *\n * @returns A new linear `(0, 0, 0, 0)`. **Allocates.**\n */\n static transparent(): Color {\n return new Color(0, 0, 0, 0);\n }\n\n /**\n * Copies any colour-shaped value into a `Color`.\n *\n * @param c - The linear colour to copy.\n * @returns A new colour. **Allocates.**\n */\n static from(c: ColorLike): Color {\n return new Color(c.r, c.g, c.b, c.a);\n }\n\n /**\n * Converts one **sRGB** channel to linear, using the IEC 61966-2-1 curve Babylon Lite uses\n * (`lib/math/color.js`).\n *\n * @param channel - The sRGB channel value; clamped into 0-1.\n * @returns The linear value.\n */\n static srgbToLinear(channel: number): number {\n const c = clamp01(channel);\n return c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);\n }\n\n /**\n * Converts one **linear** channel to sRGB, the inverse of {@link Color.srgbToLinear}.\n *\n * @param channel - The linear channel value; clamped into 0-1, so HDR intensity is lost.\n * @returns The sRGB value.\n */\n static linearToSrgb(channel: number): number {\n const c = clamp01(channel);\n return c <= 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 1 / 2.4) - 0.055;\n }\n\n /**\n * Builds a colour from **sRGB** components, converting RGB to linear and taking alpha as-is.\n *\n * @param r - The sRGB red component, 0-1.\n * @param g - The sRGB green component, 0-1.\n * @param b - The sRGB blue component, 0-1.\n * @param a - The alpha component, 0-1. Defaults to 1.\n * @returns A new colour holding linear components. **Allocates.**\n */\n static fromSrgb(r: number, g: number, b: number, a: number = 1): Color {\n return Color.fromSrgbToRef(r, g, b, a, new Color());\n }\n\n /**\n * Writes a colour built from **sRGB** components into `out`.\n *\n * @param r - The sRGB red component, 0-1.\n * @param g - The sRGB green component, 0-1.\n * @param b - The sRGB blue component, 0-1.\n * @param a - The alpha component, 0-1.\n * @param out - The colour to write; holds linear components afterwards.\n * @returns `out`.\n */\n static fromSrgbToRef<TOut extends Color>(r: number, g: number, b: number, a: number, out: TOut): TOut {\n return out.set(Color.srgbToLinear(r), Color.srgbToLinear(g), Color.srgbToLinear(b), a);\n }\n\n /**\n * Parses an **sRGB** hex string into a linear colour.\n *\n * @param hex - `#rrggbb` or `#rrggbbaa`, with or without the leading `#`, in either case.\n * @returns A new colour, or `null` when the string is not a hex colour. Colours arrive from files\n * and user input, so a bad one is expected absence rather than API misuse (coding standards\n * section 5.5): the caller decides whether to substitute a default or raise a load error.\n * **Allocates.**\n *\n * @example\n * ```ts\n * const tint = Color.fromHex(\"#ff8800aa\") ?? Color.white();\n * ```\n */\n static fromHex(hex: string): Color | null {\n const out = new Color();\n return Color.fromHexToRef(hex, out) ? out : null;\n }\n\n /**\n * Parses an **sRGB** hex string into `out` as linear components.\n *\n * @param hex - `#rrggbb` or `#rrggbbaa`, with or without the leading `#`, in either case.\n * @param out - The colour to write; left untouched when parsing fails.\n * @returns `true` when `hex` was a valid hex colour.\n */\n static fromHexToRef(hex: string, out: Color): boolean {\n if (!HEX_PATTERN.test(hex)) {\n return false;\n }\n const body = hex.startsWith(\"#\") ? hex.slice(1) : hex;\n const r = Number.parseInt(body.slice(0, 2), 16) / 255;\n const g = Number.parseInt(body.slice(2, 4), 16) / 255;\n const b = Number.parseInt(body.slice(4, 6), 16) / 255;\n const a = body.length === 8 ? Number.parseInt(body.slice(6, 8), 16) / 255 : 1;\n Color.fromSrgbToRef(r, g, b, a, out);\n return true;\n }\n\n /**\n * Writes the component-wise product `a * b` into `out`, in linear space.\n *\n * @param a - The first colour.\n * @param b - The second colour.\n * @param out - The colour to write; may alias `a` or `b`.\n * @returns `out`.\n */\n static multiplyToRef<TOut extends Color>(a: ColorLike, b: ColorLike, out: TOut): TOut {\n return out.set(a.r * b.r, a.g * b.g, a.b * b.b, a.a * b.a);\n }\n\n /**\n * Writes `c` with its RGB scaled and its alpha untouched into `out`.\n *\n * @param c - The colour to scale.\n * @param factor - The intensity factor.\n * @param out - The colour to write; may alias `c`.\n * @returns `out`.\n */\n static scaleRgbToRef<TOut extends Color>(c: ColorLike, factor: number, out: TOut): TOut {\n return out.set(c.r * factor, c.g * factor, c.b * factor, c.a);\n }\n\n /**\n * Writes the linear-space interpolation of `a` and `b` into `out`.\n *\n * @param a - The colour written at `t === 0`.\n * @param b - The colour written at `t === 1`.\n * @param t - The interpolant; not clamped.\n * @param out - The colour to write; may alias `a` or `b`.\n * @returns `out`.\n */\n static lerpToRef<TOut extends Color>(a: ColorLike, b: ColorLike, t: number, out: TOut): TOut {\n return out.set(lerp(a.r, b.r, t), lerp(a.g, b.g, t), lerp(a.b, b.b, t), lerp(a.a, b.a, t));\n }\n\n /**\n * Compares two colours component by component, with a tolerance.\n *\n * @param a - The first colour.\n * @param b - The second colour.\n * @param epsilon - The largest per-component difference still considered equal.\n * @returns `true` when every component matches within `epsilon`.\n */\n static equalsWithEpsilon(a: ColorLike, b: ColorLike, epsilon: number = EPSILON): boolean {\n return (\n Math.abs(a.r - b.r) <= epsilon &&\n Math.abs(a.g - b.g) <= epsilon &&\n Math.abs(a.b - b.b) <= epsilon &&\n Math.abs(a.a - b.a) <= epsilon\n );\n }\n}\n"],"mappings":";;;;;AAMA,MAAM,cAAc;;;;;;;AAQpB,SAAS,QAAQ,OAAuB;CACtC,OAAO,MAAM,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG;AAC3C;;;;;;;;;;;;;;;;;;;;AAqBA,IAAa,QAAb,MAAa,MAAM;;CAEjB;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c,GAAc,GAAW,KAAiB;EAC3F,OAAO,IAAI,IAAI,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;CAC3F;;;;;;;;;CAUA,OAAO,kBAAkB,GAAc,GAAc,UAAkB,SAAkB;EACvF,OACE,KAAK,IAAI,EAAE,IAAI,EAAE,CAAC,KAAK,WACvB,KAAK,IAAI,EAAE,IAAI,EAAE,CAAC,KAAK,WACvB,KAAK,IAAI,EAAE,IAAI,EAAE,CAAC,KAAK,WACvB,KAAK,IAAI,EAAE,IAAI,EAAE,CAAC,KAAK;CAE3B;AACF"}
@@ -1,5 +1,6 @@
1
1
  import { n as assertNever } from "./ignifx-error-CRh89KUJ.js";
2
- import { c as degToRad, t as Color } from "./color-CpvebMIh.js";
2
+ import { s as degToRad } from "./math-utils-BcDnL-gi.js";
3
+ import { t as Color } from "./color-DrR6GFTd.js";
3
4
  import { AcesToneMapping, NeutralToneMapping, StandardToneMapping, loadEnvironment, setEnvironmentBlur, setEnvironmentRotation, setFog, setSceneImageProcessing } from "@babylonjs/lite";
4
5
  //#region src/lite/gpu/environment.ts
5
6
  /**
@@ -279,4 +280,4 @@ function toneMappingCurve(name) {
279
280
  //#endregion
280
281
  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 };
281
282
 
282
- //# sourceMappingURL=environment-CTM7BAyb.js.map
283
+ //# sourceMappingURL=environment-mr5wp69e.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"environment-CTM7BAyb.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.\n *\n * @public\n */\nexport const TONE_MAPPING_NAMES = [\"none\", \"standard\", \"aces\", \"neutral\"] as const;\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 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 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\"` is handled by the caller.\n * @returns The Lite curve.\n */\nfunction toneMappingCurve(name: Exclude<ToneMappingName, \"none\">): 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":";;;;;;;;;AAiHA,MAAa,YAAY;;CAEvB,MAAM;;CAEN,KAAK;;CAEL,MAAM;;CAEN,QAAQ;AACV;;;;;;AAcA,MAAa,qBAAqB;CAAC;CAAQ;CAAY;CAAQ;AAAS;;;;;;;;;;;;;;;;;;AA8DxE,SAAgB,qBACd,OACA,SAC8B;CAC9B,MAAM,cAOF,EAAE,SAAS,QAAQ,QAAQ;CAC/B,IAAI,QAAQ,cAAc,KAAA,GACxB,YAAY,YAAY,QAAQ;CAElC,IAAI,QAAQ,eAAe,KAAA,GACzB,YAAY,aAAa,QAAQ;CAEnC,IAAI,QAAQ,eAAe,KAAA,GACzB,YAAY,aAAa,QAAQ;CAEnC,IAAI,QAAQ,eAAe,KAAA,GACzB,YAAY,aAAa,QAAQ;CAEnC,IAAI,QAAQ,qBAAqB,KAAA,GAC/B,YAAY,mBAAmB,QAAQ;CAEzC,OAAO,gBAAgB,OAAO,QAAQ,KAAK,WAAW;AACxD;;;;;;;AAkBA,SAAS,kBAAkB,OAA2C;CAMpE,OAAO;A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,wBAAwB,OAAO;EACpC;EACA;EACA,oBAAoB;EACpB,aAAa,iBAAiB,WAAW;CAC3C,CAAC;AACH;;;;;;;;;;;;;;;AAgBA,SAAgB,yBAAyB,OAAqB,KAAiD;CAC7G,MAAM,aAAa,MAAM;CACzB,IAAI,WAAW,WAAW;CAC1B,IAAI,WAAW,WAAW;CAC1B,IAAI,QAAQ,WAAW,qBAAqB,UAAU,WAAW,eAAe,mBAAmB,IAAI;CACvG,OAAO;AACT;;;;;;;AAQA,SAAS,UAAU,OAAqC;CACtD,QAAQ,MAAM,IAAd;EACE,KAAK,oBAAoB,IACvB,OAAO;EACT,KAAK,gBAAgB,IACnB,OAAO;EACT,KAAK,mBAAmB,IACtB,OAAO;EACT,SACE,OAAO;CACX;AACF;;;;;;;AAQA,SAAS,iBAAiB,MAAqD;CAC7E,QAAQ,MAAR;EACE,KAAK,YACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,KAAK,WACH,OAAO;EACT,SACE,OAAO,YAAY,MAAM,cAAc;CAC3C;AACF"}
1
+ {"version":3,"file":"environment-mr5wp69e.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.\n *\n * @public\n */\nexport const TONE_MAPPING_NAMES = [\"none\", \"standard\", \"aces\", \"neutral\"] as const;\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 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 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\"` is handled by the caller.\n * @returns The Lite curve.\n */\nfunction toneMappingCurve(name: Exclude<ToneMappingName, \"none\">): ToneMapping {\n switch (name) {\n case \"standard\":\n return StandardToneMapping;\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