@ignifx/core 0.5.0 → 0.6.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/dist/{environment-_EeJXzjk.js → environment-CvVC1lPa.js} +39 -3
- package/dist/environment-CvVC1lPa.js.map +1 -0
- package/dist/index.d.ts +40 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +364 -14
- package/dist/index.js.map +1 -1
- package/dist/{post-effect-compiler-DTlkT1si.js → post-effect-compiler-Cq6cshjL.js} +2 -2
- package/dist/{post-effect-compiler-DTlkT1si.js.map → post-effect-compiler-Cq6cshjL.js.map} +1 -1
- package/dist/{shader-material-BVCQ4lW9.js → shader-material-BzVY0ySR.js} +2 -2
- package/dist/{shader-material-BVCQ4lW9.js.map → shader-material-BzVY0ySR.js.map} +1 -1
- package/dist/{shader-material-CqkEsKQ2.js → shader-material-fOI9Upt3.js} +2 -2
- package/dist/{shader-material-CqkEsKQ2.js.map → shader-material-fOI9Upt3.js.map} +1 -1
- package/dist/{surface-shader-B3gtg_8Q.js → surface-shader-fJ2MOez0.js} +2 -2
- package/dist/{surface-shader-B3gtg_8Q.js.map → surface-shader-fJ2MOez0.js.map} +1 -1
- package/package.json +1 -1
- package/dist/environment-_EeJXzjk.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as CORE_ERROR_MESSAGES, c as THIRD_PARTY_ERROR_PREFIX, i as isIgnifxError, l as isValidErrorCode, n as assertNever, o as CoreErrorCode, r as formatErrorMessage, s as ErrorRange, t as IgnifxError } from "./ignifx-error-R1ma_Lzv.js";
|
|
2
2
|
import { _ as sign, a as approximately, c as degToRad, d as lerp, f as lerpAngleDegrees, g as repeat, h as radToDeg, i as RAD_TO_DEG, l as deltaAngleDegrees, m as pingPong, n as DEG_TO_RAD, o as clamp, p as moveTowards, r as EPSILON, s as clamp01, t as Color, u as inverseLerp, v as smoothStep, y as wrapAngleDegrees } from "./color-CpvebMIh.js";
|
|
3
3
|
import { A as linkParent, B as tagNode, C as setMeshSubtreeVisible, D as updateMeshUvs$1, E as updateMeshPositions$1, F as readNodeTag, I as readWorldMatrix, L as reparentKeepingWorld, M as localRotation, N as localScale, O as createNode, P as parentNode, R as setNodeName, S as setMeshRenderOrder, T as updateMeshNormals$1, V as worldMatrixVersion, a as createCapsuleMesh, b as setMeshPickable, c as createMeshFromGeometry, d as createTorusMesh, g as removeMeshFromScene, h as recomputeMeshBounds, i as createBoxMesh, j as localPosition, k as disposeNode, l as createPlaneMesh, m as overrideSubtreeMaterials, n as cloneMeshUnderNode, o as createCylinderMesh, p as disposeMeshTemplate, r as collectSubtreeMeshes, s as createGroundMesh, t as addMeshToScene, u as createSphereMesh, v as setMeshId, w as updateMeshColors$1, x as setMeshReceiveShadows, y as setMeshMaterial, z as setNodeSelfVisible } from "./mesh-CnK_PX46.js";
|
|
4
|
-
import { a as
|
|
4
|
+
import { a as readSceneImageProcessing, c as setSceneEnvironmentRotation, l as setSceneFog, n as installSceneEnvironment, o as setSceneClearColor, r as loadSceneEnvironment, s as setSceneEnvironmentBlur, t as TONE_MAPPING_NAMES, u as setSceneImageProcessingOptions } from "./environment-CvVC1lPa.js";
|
|
5
5
|
import { a as defineMaterialPlugin, c as MATERIAL_ALPHA_MODES, d as createStandardMaterialFromProps, f as markMaterialDirty, g as setPbrMetallicRoughness, h as setPbrBaseColor, i as MATERIAL_PLUGIN_SAMPLER_BUDGET, l as createDefaultMaterial, m as setMaterialAlpha, n as MATERIAL_PLUGIN_DEFAULT_PRIORITY, o as isLiteMaterialPluginPoint, r as MATERIAL_PLUGIN_RESERVED_NAMES, t as LITE_MATERIAL_PLUGIN_POINTS, u as createPbrMaterialFromProps } from "./material-plugin-CTaWZXEk.js";
|
|
6
6
|
import { a as postEffectValuesCodec, i as declaredTextureBinding, n as POST_EFFECT_FUNCTION, o as asJsonArray, r as customEffect, s as asJsonObject, t as POST_EFFECT_BUILTIN_UNIFORMS } from "./post-effect-C42XJFmo.js";
|
|
7
7
|
import { a as SHADER_BLEND_MODES, c as SHADER_KINDS, d as SURFACE_HOOK_NAMES, f as SURFACE_UNIFORM_BLOCK, i as SHADER_ATTRIBUTE_NAMES, l as SHADER_TEXTURE_FALLBACKS, o as SHADER_CULL_MODES, r as LITE_SYSTEM_UNIFORM_NAMES, s as SHADER_INSTANCING_MODES, t as IGNIFX_UNIFORM_NAMES, u as SHADER_UNIFORM_TYPES } from "./shader-declaration-5q__jycG.js";
|
|
@@ -7829,7 +7829,7 @@ function environmentSchema() {
|
|
|
7829
7829
|
}),
|
|
7830
7830
|
toneMapping: enumOf(TONE_MAPPING_NAMES, "none", { tooltip: "The tone-mapping curve." })
|
|
7831
7831
|
}, { tooltip: "Exposure, contrast, and tone mapping. Recompiles PBR pipelines when it changes." }),
|
|
7832
|
-
clearColor: optional(color("#000000"), { tooltip: "The colour the scene is cleared to,
|
|
7832
|
+
clearColor: optional(color("#000000"), { tooltip: "The sRGB colour the scene is cleared to, through imageProcessing; null leaves the rendering.clearColor setting." })
|
|
7833
7833
|
});
|
|
7834
7834
|
}
|
|
7835
7835
|
//#endregion
|
|
@@ -7872,7 +7872,7 @@ let surfaceLayer = null;
|
|
|
7872
7872
|
* @internal
|
|
7873
7873
|
*/
|
|
7874
7874
|
async function loadShaderSupport() {
|
|
7875
|
-
const loaded = shaderLayer ?? await import("./shader-material-
|
|
7875
|
+
const loaded = shaderLayer ?? await import("./shader-material-fOI9Upt3.js").then((n) => n.n);
|
|
7876
7876
|
shaderLayer = loaded;
|
|
7877
7877
|
await loaded.loadShaderMaterialAdapter();
|
|
7878
7878
|
return loaded;
|
|
@@ -7895,7 +7895,7 @@ function shaderSupport() {
|
|
|
7895
7895
|
* @internal
|
|
7896
7896
|
*/
|
|
7897
7897
|
async function loadSurfaceShaderSupport() {
|
|
7898
|
-
const loaded = surfaceLayer ?? await import("./surface-shader-
|
|
7898
|
+
const loaded = surfaceLayer ?? await import("./surface-shader-fJ2MOez0.js");
|
|
7899
7899
|
surfaceLayer = loaded;
|
|
7900
7900
|
return loaded;
|
|
7901
7901
|
}
|
|
@@ -10271,6 +10271,175 @@ function readTaskTimings(engine) {
|
|
|
10271
10271
|
};
|
|
10272
10272
|
}
|
|
10273
10273
|
//#endregion
|
|
10274
|
+
//#region src/render/image-processing-color.ts
|
|
10275
|
+
/** Lite's gamma: a plain 2.2 power, not the piecewise sRGB curve. */
|
|
10276
|
+
const GAMMA = 2.2;
|
|
10277
|
+
/**
|
|
10278
|
+
* Whether image processing leaves an encoded colour unchanged.
|
|
10279
|
+
*
|
|
10280
|
+
* @param state - The image processing.
|
|
10281
|
+
* @returns `true` for exposure 1, contrast 1 and no curve, where decode and encode cancel out.
|
|
10282
|
+
*
|
|
10283
|
+
* @internal
|
|
10284
|
+
*/
|
|
10285
|
+
function isIdentityImageProcessing(state) {
|
|
10286
|
+
return state.exposure === 1 && state.contrast === 1 && state.curve === "none";
|
|
10287
|
+
}
|
|
10288
|
+
/**
|
|
10289
|
+
* Whether two image-processing states are the same.
|
|
10290
|
+
*
|
|
10291
|
+
* @param left - One state.
|
|
10292
|
+
* @param right - The other.
|
|
10293
|
+
* @returns `true` when every field matches.
|
|
10294
|
+
*
|
|
10295
|
+
* @internal
|
|
10296
|
+
*/
|
|
10297
|
+
function sameImageProcessing(left, right) {
|
|
10298
|
+
return left.exposure === right.exposure && left.contrast === right.contrast && left.curve === right.curve;
|
|
10299
|
+
}
|
|
10300
|
+
/**
|
|
10301
|
+
* Applies Lite's PBR image processing to an sRGB colour, as a fully fogged fragment of that colour
|
|
10302
|
+
* would receive it.
|
|
10303
|
+
*
|
|
10304
|
+
* @param r - The sRGB red component, 0 to 1.
|
|
10305
|
+
* @param g - The sRGB green component, 0 to 1.
|
|
10306
|
+
* @param b - The sRGB blue component, 0 to 1.
|
|
10307
|
+
* @param a - The alpha, passed through.
|
|
10308
|
+
* @param state - The image processing to apply.
|
|
10309
|
+
* @param out - Receives the processed sRGB colour.
|
|
10310
|
+
* @returns `out`.
|
|
10311
|
+
*
|
|
10312
|
+
* @internal
|
|
10313
|
+
*/
|
|
10314
|
+
function imageProcessedColor(r, g, b, a, state, out) {
|
|
10315
|
+
out.a = a;
|
|
10316
|
+
if (isIdentityImageProcessing(state)) {
|
|
10317
|
+
out.r = r;
|
|
10318
|
+
out.g = g;
|
|
10319
|
+
out.b = b;
|
|
10320
|
+
return out;
|
|
10321
|
+
}
|
|
10322
|
+
out.r = decode(r) * state.exposure;
|
|
10323
|
+
out.g = decode(g) * state.exposure;
|
|
10324
|
+
out.b = decode(b) * state.exposure;
|
|
10325
|
+
applyCurve(state.curve, out);
|
|
10326
|
+
out.r = finish(out.r, state.contrast);
|
|
10327
|
+
out.g = finish(out.g, state.contrast);
|
|
10328
|
+
out.b = finish(out.b, state.contrast);
|
|
10329
|
+
return out;
|
|
10330
|
+
}
|
|
10331
|
+
/**
|
|
10332
|
+
* Lite's fog-colour decode.
|
|
10333
|
+
*
|
|
10334
|
+
* @param value - The encoded channel.
|
|
10335
|
+
* @returns The linear channel.
|
|
10336
|
+
*/
|
|
10337
|
+
function decode(value) {
|
|
10338
|
+
return Math.max(value, 0) ** GAMMA;
|
|
10339
|
+
}
|
|
10340
|
+
/**
|
|
10341
|
+
* Encodes, clamps and applies contrast, the steps every PBR fragment ends with.
|
|
10342
|
+
*
|
|
10343
|
+
* @param value - The tone-mapped linear channel.
|
|
10344
|
+
* @param contrast - The contrast multiplier.
|
|
10345
|
+
* @returns The presented channel, 0 to 1.
|
|
10346
|
+
*/
|
|
10347
|
+
function finish(value, contrast) {
|
|
10348
|
+
const encoded = Math.min(Math.max(Math.max(value, 0) ** (1 / GAMMA), 0), 1);
|
|
10349
|
+
const high = encoded * encoded * (3 - 2 * encoded);
|
|
10350
|
+
const contrasted = contrast < 1 ? .5 + (encoded - .5) * contrast : encoded + (high - encoded) * (contrast - 1);
|
|
10351
|
+
return Math.max(contrasted, 0);
|
|
10352
|
+
}
|
|
10353
|
+
/**
|
|
10354
|
+
* Applies a tone-mapping curve in place, to an already exposed linear colour.
|
|
10355
|
+
*
|
|
10356
|
+
* @param curve - The curve.
|
|
10357
|
+
* @param color - The colour; overwritten.
|
|
10358
|
+
*/
|
|
10359
|
+
function applyCurve(curve, color) {
|
|
10360
|
+
switch (curve) {
|
|
10361
|
+
case "none": return;
|
|
10362
|
+
case "standard":
|
|
10363
|
+
color.r = standard(color.r);
|
|
10364
|
+
color.g = standard(color.g);
|
|
10365
|
+
color.b = standard(color.b);
|
|
10366
|
+
return;
|
|
10367
|
+
case "aces":
|
|
10368
|
+
aces(color);
|
|
10369
|
+
return;
|
|
10370
|
+
case "neutral":
|
|
10371
|
+
neutral(color);
|
|
10372
|
+
return;
|
|
10373
|
+
default: assertNever(curve, "tone mapping");
|
|
10374
|
+
}
|
|
10375
|
+
}
|
|
10376
|
+
/**
|
|
10377
|
+
* Lite's `StandardToneMapping` (`lib/material/pbr/tone-mapping.js`).
|
|
10378
|
+
*
|
|
10379
|
+
* @param value - The exposed channel.
|
|
10380
|
+
* @returns The tone-mapped channel.
|
|
10381
|
+
*/
|
|
10382
|
+
function standard(value) {
|
|
10383
|
+
return 1 - 2 ** (-1.590579 * value);
|
|
10384
|
+
}
|
|
10385
|
+
/**
|
|
10386
|
+
* Lite's `AcesToneMapping`, the fitted RRT + ODT (`lib/material/pbr/pbr-aces-wgsl.js`).
|
|
10387
|
+
*
|
|
10388
|
+
* @param color - The exposed colour; overwritten.
|
|
10389
|
+
*/
|
|
10390
|
+
function aces(color) {
|
|
10391
|
+
const r = .59719 * color.r + .35458 * color.g + .04823 * color.b;
|
|
10392
|
+
const g = .076 * color.r + .90834 * color.g + .01566 * color.b;
|
|
10393
|
+
const b = .0284 * color.r + .13383 * color.g + .83777 * color.b;
|
|
10394
|
+
const fr = rrtAndOdtFit(r);
|
|
10395
|
+
const fg = rrtAndOdtFit(g);
|
|
10396
|
+
const fb = rrtAndOdtFit(b);
|
|
10397
|
+
color.r = saturate(1.60475 * fr - .53108 * fg - .07367 * fb);
|
|
10398
|
+
color.g = saturate(-.10208 * fr + 1.10813 * fg - .00605 * fb);
|
|
10399
|
+
color.b = saturate(-.00327 * fr - .07276 * fg + 1.07602 * fb);
|
|
10400
|
+
}
|
|
10401
|
+
/**
|
|
10402
|
+
* The rational fit inside ACES.
|
|
10403
|
+
*
|
|
10404
|
+
* @param value - One channel in the ACES working space.
|
|
10405
|
+
* @returns The fitted channel.
|
|
10406
|
+
*/
|
|
10407
|
+
function rrtAndOdtFit(value) {
|
|
10408
|
+
return (value * (value + .0245786) - 90537e-9) / (value * (.983729 * value + .432951) + .238081);
|
|
10409
|
+
}
|
|
10410
|
+
/**
|
|
10411
|
+
* Lite's `NeutralToneMapping`, Khronos PBR Neutral (`lib/material/pbr/pbr-neutral-wgsl.js`).
|
|
10412
|
+
*
|
|
10413
|
+
* @param color - The exposed colour; overwritten.
|
|
10414
|
+
*/
|
|
10415
|
+
function neutral(color) {
|
|
10416
|
+
const startCompression = .76;
|
|
10417
|
+
const desaturation = .15;
|
|
10418
|
+
const lowest = Math.min(color.r, color.g, color.b);
|
|
10419
|
+
const offset = lowest < .08 ? lowest - 6.25 * lowest * lowest : .04;
|
|
10420
|
+
color.r -= offset;
|
|
10421
|
+
color.g -= offset;
|
|
10422
|
+
color.b -= offset;
|
|
10423
|
+
const peak = Math.max(color.r, color.g, color.b);
|
|
10424
|
+
if (peak < startCompression) return;
|
|
10425
|
+
const d = .24;
|
|
10426
|
+
const newPeak = 1 - d * d / (peak + d - startCompression);
|
|
10427
|
+
const scale = newPeak / peak;
|
|
10428
|
+
const blend = 1 - 1 / (desaturation * (peak - newPeak) + 1);
|
|
10429
|
+
color.r = color.r * scale + (newPeak - color.r * scale) * blend;
|
|
10430
|
+
color.g = color.g * scale + (newPeak - color.g * scale) * blend;
|
|
10431
|
+
color.b = color.b * scale + (newPeak - color.b * scale) * blend;
|
|
10432
|
+
}
|
|
10433
|
+
/**
|
|
10434
|
+
* Clamps to `[0, 1]`.
|
|
10435
|
+
*
|
|
10436
|
+
* @param value - The value.
|
|
10437
|
+
* @returns The clamped value.
|
|
10438
|
+
*/
|
|
10439
|
+
function saturate(value) {
|
|
10440
|
+
return Math.min(Math.max(value, 0), 1);
|
|
10441
|
+
}
|
|
10442
|
+
//#endregion
|
|
10274
10443
|
//#region src/render/rendering-settings.ts
|
|
10275
10444
|
/**
|
|
10276
10445
|
* The `rendering` project settings section (`docs/architecture/04-extensions.md` §5,
|
|
@@ -10541,6 +10710,8 @@ var RendererImpl = class {
|
|
|
10541
10710
|
needsRenderableRebuild = false;
|
|
10542
10711
|
/** `true` once a `castShadows` or caster-set change needs the caster lists rebuilt this frame. */
|
|
10543
10712
|
needsCasterRebuild = false;
|
|
10713
|
+
/** `true` once a light gained or lost a shadow generator, so the next rebuild needs fresh layouts. */
|
|
10714
|
+
needsShadowLayoutReset = false;
|
|
10544
10715
|
/** `true` once a camera was added, removed, enabled, disabled, or re-prioritised. */
|
|
10545
10716
|
needsCameraSelect = true;
|
|
10546
10717
|
/** `true` once the world has been told it has no enabled camera, so `IGX-0706` is logged once. */
|
|
@@ -10571,6 +10742,32 @@ var RendererImpl = class {
|
|
|
10571
10742
|
#profileTasks = false;
|
|
10572
10743
|
#isSceneRegistered = false;
|
|
10573
10744
|
#isLoopRunning = false;
|
|
10745
|
+
/** The clear colour as authored, in sRGB, before image processing. */
|
|
10746
|
+
#authoredClear = {
|
|
10747
|
+
r: 0,
|
|
10748
|
+
g: 0,
|
|
10749
|
+
b: 0,
|
|
10750
|
+
a: 1
|
|
10751
|
+
};
|
|
10752
|
+
/** The image processing the clear colour was last written with. */
|
|
10753
|
+
#clearProcessing = {
|
|
10754
|
+
exposure: 1,
|
|
10755
|
+
contrast: 1,
|
|
10756
|
+
curve: "none"
|
|
10757
|
+
};
|
|
10758
|
+
/** Scratch for {@link RendererImpl.refreshClearColor}'s per-frame read. */
|
|
10759
|
+
#processingScratch = {
|
|
10760
|
+
exposure: 1,
|
|
10761
|
+
contrast: 1,
|
|
10762
|
+
curve: "none"
|
|
10763
|
+
};
|
|
10764
|
+
/** Scratch for the processed clear colour. */
|
|
10765
|
+
#processedClear = {
|
|
10766
|
+
r: 0,
|
|
10767
|
+
g: 0,
|
|
10768
|
+
b: 0,
|
|
10769
|
+
a: 1
|
|
10770
|
+
};
|
|
10574
10771
|
/**
|
|
10575
10772
|
* Creates the rendering service.
|
|
10576
10773
|
*
|
|
@@ -10968,18 +11165,52 @@ var RendererImpl = class {
|
|
|
10968
11165
|
* ignifx default is opaque black (`src/render/rendering-settings.ts`), so Lite's grey is only
|
|
10969
11166
|
* ever seen by code that bypasses `createApp`.
|
|
10970
11167
|
*
|
|
10971
|
-
* Colours are stored in sRGB in every settings section and every component field
|
|
10972
|
-
*
|
|
10973
|
-
*
|
|
10974
|
-
*
|
|
10975
|
-
*
|
|
11168
|
+
* Colours are stored in sRGB in every settings section and every component field. The clear goes
|
|
11169
|
+
* through the same exposure, curve and contrast as every PBR fragment, applied here on the CPU,
|
|
11170
|
+
* so a fully fogged floor and a clear colour of the fog's colour present as the same bytes. With
|
|
11171
|
+
* no image processing (exposure 1, contrast 1, curve `"none"`) an sRGB `0.5` presents as byte
|
|
11172
|
+
* `128`; under ACES it presents as byte `104`. The value is decoded only for an `*-srgb` surface
|
|
11173
|
+
* view (`rendering.srgb: true`), which encodes it again on write (`setSceneClearColor`).
|
|
10976
11174
|
*
|
|
10977
11175
|
* @param value - The sRGB colour, `0` to `1` per channel.
|
|
10978
11176
|
*
|
|
10979
11177
|
* @internal
|
|
10980
11178
|
*/
|
|
10981
11179
|
applyClearColor(value) {
|
|
10982
|
-
|
|
11180
|
+
const authored = this.#authoredClear;
|
|
11181
|
+
authored.r = value.r;
|
|
11182
|
+
authored.g = value.g;
|
|
11183
|
+
authored.b = value.b;
|
|
11184
|
+
authored.a = value.a;
|
|
11185
|
+
this.#writeClearColor(readSceneImageProcessing(this.scene, this.#processingScratch));
|
|
11186
|
+
}
|
|
11187
|
+
/**
|
|
11188
|
+
* Re-applies the clear colour when the scene's image processing changed since it was written.
|
|
11189
|
+
*
|
|
11190
|
+
* @remarks
|
|
11191
|
+
* The `PreRender` system calls it every frame, after the `Environment` has written its image
|
|
11192
|
+
* processing. Lite's `loadEnvironment` changes image processing too, which is why the scene is
|
|
11193
|
+
* read rather than the component.
|
|
11194
|
+
*
|
|
11195
|
+
* @internal
|
|
11196
|
+
*/
|
|
11197
|
+
refreshClearColor() {
|
|
11198
|
+
const current = readSceneImageProcessing(this.scene, this.#processingScratch);
|
|
11199
|
+
if (!sameImageProcessing(current, this.#clearProcessing)) this.#writeClearColor(current);
|
|
11200
|
+
}
|
|
11201
|
+
/**
|
|
11202
|
+
* Writes the authored clear colour, processed with `processing`, onto the scene.
|
|
11203
|
+
*
|
|
11204
|
+
* @param processing - The scene's current image processing.
|
|
11205
|
+
*/
|
|
11206
|
+
#writeClearColor(processing) {
|
|
11207
|
+
const applied = this.#clearProcessing;
|
|
11208
|
+
applied.exposure = processing.exposure;
|
|
11209
|
+
applied.contrast = processing.contrast;
|
|
11210
|
+
applied.curve = processing.curve;
|
|
11211
|
+
const authored = this.#authoredClear;
|
|
11212
|
+
const out = imageProcessedColor(authored.r, authored.g, authored.b, authored.a, processing, this.#processedClear);
|
|
11213
|
+
setSceneClearColor(this.scene, out.r, out.g, out.b, out.a);
|
|
10983
11214
|
}
|
|
10984
11215
|
/**
|
|
10985
11216
|
* Reconciles the world with the Lite scene once, before the scene is registered.
|
|
@@ -12024,6 +12255,45 @@ function rebuildRenderables(scene) {
|
|
|
12024
12255
|
return rebuildSceneRenderables(scene);
|
|
12025
12256
|
}
|
|
12026
12257
|
/**
|
|
12258
|
+
* How many times the scene's materials have been rebuilt.
|
|
12259
|
+
*
|
|
12260
|
+
* @remarks
|
|
12261
|
+
* An ESM generator keeps the caster views it built for a caster array until it is handed a
|
|
12262
|
+
* different array, whatever happens to the materials (`ensureEsmShadowTaskState`,
|
|
12263
|
+
* `lib/shadow/esm-directional-shadow-generator.js` 121-126; PCF and CSM compare each material's
|
|
12264
|
+
* `_csmGen` instead). So a surface shader switched on or off went on drawing the old shape into an
|
|
12265
|
+
* ESM map. The render sync system re-supplies the caster lists whenever this moves.
|
|
12266
|
+
*
|
|
12267
|
+
* @param scene - The scene.
|
|
12268
|
+
* @returns The counter; `0` before anything was built.
|
|
12269
|
+
*
|
|
12270
|
+
* @internal
|
|
12271
|
+
*/
|
|
12272
|
+
function readMaterialEpoch(scene) {
|
|
12273
|
+
return scene._materialEpoch ?? 0;
|
|
12274
|
+
}
|
|
12275
|
+
/**
|
|
12276
|
+
* Makes the next renderable rebuild create fresh bind-group layouts for every material.
|
|
12277
|
+
*
|
|
12278
|
+
* @remarks
|
|
12279
|
+
* Call it before {@link rebuildRenderables} whenever a light gained or lost a shadow generator.
|
|
12280
|
+
* Lite caches a material's bindings, shadow bind-group layout included, under a key that does not
|
|
12281
|
+
* name the shadow maps (`getOrCreatePbrBindings`, `lib/material/pbr/pbr-pipeline.js` 36). So after
|
|
12282
|
+
* the number of shadow-casting lights changes, a rebuild reuses a layout sized for the old number
|
|
12283
|
+
* and builds a bind group for the new one, and WebGPU rejects every frame ("Number of entries (3)
|
|
12284
|
+
* did not match the expected number of entries (6)"). Clearing the cache costs one pipeline
|
|
12285
|
+
* rebuild per material, only on a frame whose shadow casters changed.
|
|
12286
|
+
*
|
|
12287
|
+
* @param engine - The engine whose caches to clear.
|
|
12288
|
+
*
|
|
12289
|
+
* @internal
|
|
12290
|
+
*/
|
|
12291
|
+
function forgetMaterialBindingLayouts(engine) {
|
|
12292
|
+
const resets = engine;
|
|
12293
|
+
resets._pbrCleanup?.();
|
|
12294
|
+
resets._standardCleanup?.();
|
|
12295
|
+
}
|
|
12296
|
+
/**
|
|
12027
12297
|
* Releases a shadow generator's GPU resources and unlinks it from its light.
|
|
12028
12298
|
*
|
|
12029
12299
|
* @remarks
|
|
@@ -12151,11 +12421,40 @@ function recordReplacedShadowTaskStates(generator) {
|
|
|
12151
12421
|
hooks._ensureShadowTaskState = (engine, scene, casterMeshes) => {
|
|
12152
12422
|
const previous = hooks._shadowTaskState;
|
|
12153
12423
|
const state = ensure(engine, scene, casterMeshes);
|
|
12424
|
+
if (state !== previous && casterMeshes.length === 0) stopMirroringEmptyStates(scene, state);
|
|
12154
12425
|
if (previous !== void 0 && state !== previous && state._casterMeshes === previous._casterMeshes) state._task.record();
|
|
12155
12426
|
return state;
|
|
12156
12427
|
};
|
|
12157
12428
|
}
|
|
12158
12429
|
/**
|
|
12430
|
+
* Keeps a shadow task state built for no casters from drawing the scene's renderables.
|
|
12431
|
+
*
|
|
12432
|
+
* @remarks
|
|
12433
|
+
* Each render task records against an empty renderable list, and its mirroring flag is cleared
|
|
12434
|
+
* afterwards so a later change to the scene's renderables does not copy them in either. The pass
|
|
12435
|
+
* then only clears the map. See the module header.
|
|
12436
|
+
*
|
|
12437
|
+
* @param scene - The scene the state belongs to.
|
|
12438
|
+
* @param state - A state whose caster list is empty.
|
|
12439
|
+
*/
|
|
12440
|
+
function stopMirroringEmptyStates(scene, state) {
|
|
12441
|
+
const renderables = scene;
|
|
12442
|
+
const tasks = state._tasks ?? [state._task];
|
|
12443
|
+
for (const task of tasks) {
|
|
12444
|
+
const record = task.record.bind(task);
|
|
12445
|
+
task.record = () => {
|
|
12446
|
+
const all = renderables._renderables;
|
|
12447
|
+
renderables._renderables = [];
|
|
12448
|
+
try {
|
|
12449
|
+
record();
|
|
12450
|
+
} finally {
|
|
12451
|
+
renderables._renderables = all;
|
|
12452
|
+
}
|
|
12453
|
+
task._af = false;
|
|
12454
|
+
};
|
|
12455
|
+
}
|
|
12456
|
+
}
|
|
12457
|
+
/**
|
|
12159
12458
|
* Builds the directional generator for a technique.
|
|
12160
12459
|
*
|
|
12161
12460
|
* @param engine - The engine that owns the shadow map.
|
|
@@ -12505,6 +12804,7 @@ var Light = class Light extends Component {
|
|
|
12505
12804
|
return true;
|
|
12506
12805
|
}
|
|
12507
12806
|
this.#generator = attachShadows(renderer.engine, light, this.shadows);
|
|
12807
|
+
renderer.needsShadowLayoutReset = true;
|
|
12508
12808
|
return true;
|
|
12509
12809
|
}
|
|
12510
12810
|
/**
|
|
@@ -12545,7 +12845,10 @@ var Light = class Light extends Component {
|
|
|
12545
12845
|
const generator = this.#generator;
|
|
12546
12846
|
const light = this.#light;
|
|
12547
12847
|
this.#generator = null;
|
|
12548
|
-
if (generator !== null)
|
|
12848
|
+
if (generator !== null) {
|
|
12849
|
+
detachShadows(renderer.scene, light, generator);
|
|
12850
|
+
renderer.needsShadowLayoutReset = true;
|
|
12851
|
+
}
|
|
12549
12852
|
}
|
|
12550
12853
|
/**
|
|
12551
12854
|
* Removes the light and its generator from the scene.
|
|
@@ -13949,7 +14252,7 @@ let effectLayer = null;
|
|
|
13949
14252
|
* @internal
|
|
13950
14253
|
*/
|
|
13951
14254
|
async function loadPostEffectSupport() {
|
|
13952
|
-
const [compiler, effects] = await Promise.all([compilerLayer ?? import("./post-effect-compiler-
|
|
14255
|
+
const [compiler, effects] = await Promise.all([compilerLayer ?? import("./post-effect-compiler-Cq6cshjL.js"), effectLayer ?? import("./effect-task-CMbuO6Kb.js")]);
|
|
13953
14256
|
compilerLayer = compiler;
|
|
13954
14257
|
effectLayer = effects;
|
|
13955
14258
|
}
|
|
@@ -16563,6 +16866,8 @@ var RenderSyncSystem = class {
|
|
|
16563
16866
|
/** A rebuild asked for while one was already running; it is run once the in-flight one lands. */
|
|
16564
16867
|
#isRebuildPending = false;
|
|
16565
16868
|
#areCastersDirty = false;
|
|
16869
|
+
/** The scene's material epoch when the ESM caster lists were last handed over. */
|
|
16870
|
+
#materialEpoch = 0;
|
|
16566
16871
|
/**
|
|
16567
16872
|
* Creates the system.
|
|
16568
16873
|
*
|
|
@@ -16630,8 +16935,10 @@ var RenderSyncSystem = class {
|
|
|
16630
16935
|
topologyChanged = changed || topologyChanged;
|
|
16631
16936
|
castersChanged = changed || castersChanged;
|
|
16632
16937
|
}
|
|
16938
|
+
castersChanged = this.#hasEsmMaterialChanged(lights) || castersChanged;
|
|
16633
16939
|
this.#selectCamera(world, cameras);
|
|
16634
16940
|
topologyChanged = this.#applyEnvironment(world) || topologyChanged;
|
|
16941
|
+
renderer.refreshClearColor();
|
|
16635
16942
|
this.#applyStacks(world);
|
|
16636
16943
|
this.#areCastersDirty = this.#areCastersDirty || castersChanged;
|
|
16637
16944
|
if (this.#isRebuildDue && !topologyChanged) {
|
|
@@ -16771,6 +17078,25 @@ var RenderSyncSystem = class {
|
|
|
16771
17078
|
}
|
|
16772
17079
|
}
|
|
16773
17080
|
/**
|
|
17081
|
+
* Whether a material was rebuilt since the caster lists were last handed over, while an ESM light
|
|
17082
|
+
* is casting.
|
|
17083
|
+
*
|
|
17084
|
+
* @remarks
|
|
17085
|
+
* An ESM generator only rebuilds its caster views for a new caster array (`readMaterialEpoch`), so
|
|
17086
|
+
* a fresh array is what makes it draw a rebuilt material's new shape. PCF and CSM notice material
|
|
17087
|
+
* changes themselves, which is why nothing is re-supplied without an ESM light.
|
|
17088
|
+
*
|
|
17089
|
+
* @param lights - The world's lights.
|
|
17090
|
+
* @returns `true` when the caster lists should be rebuilt.
|
|
17091
|
+
*/
|
|
17092
|
+
#hasEsmMaterialChanged(lights) {
|
|
17093
|
+
const epoch = readMaterialEpoch(this.#renderer.scene);
|
|
17094
|
+
if (epoch === this.#materialEpoch) return false;
|
|
17095
|
+
this.#materialEpoch = epoch;
|
|
17096
|
+
for (let index = 0; index < lights.length; index += 1) if (isEsmCaster(lights[index])) return true;
|
|
17097
|
+
return false;
|
|
17098
|
+
}
|
|
17099
|
+
/**
|
|
16774
17100
|
* Collects one renderer's casters into the full list and, unless it draws with a shader
|
|
16775
17101
|
* material, into the ESM list too. A shader-material caster under an ESM light is reported once
|
|
16776
17102
|
* with `IGX-0724` (Babylon Lite 1.27.0 has no ESM view for the shader family).
|
|
@@ -16864,6 +17190,10 @@ var RenderSyncSystem = class {
|
|
|
16864
17190
|
do {
|
|
16865
17191
|
if (renderer.isHeadless || !renderer.isSceneRegistered) return;
|
|
16866
17192
|
try {
|
|
17193
|
+
if (renderer.needsShadowLayoutReset) {
|
|
17194
|
+
renderer.needsShadowLayoutReset = false;
|
|
17195
|
+
forgetMaterialBindingLayouts(renderer.engine);
|
|
17196
|
+
}
|
|
16867
17197
|
await rebuildRenderables(renderer.scene);
|
|
16868
17198
|
} catch (error) {
|
|
16869
17199
|
renderer.app.onError.emit({
|
|
@@ -28923,12 +29253,32 @@ function applyComponentInit(component, schema, init, typeName) {
|
|
|
28923
29253
|
issues: issues.length
|
|
28924
29254
|
} });
|
|
28925
29255
|
const target = component;
|
|
28926
|
-
for (const name of Object.
|
|
29256
|
+
for (const [name, field] of Object.entries(schema)) {
|
|
28927
29257
|
const value = values[name];
|
|
28928
|
-
if (value !== void 0) target[name] = value;
|
|
29258
|
+
if (value !== void 0) target[name] = withRecordDefaults(field, value);
|
|
28929
29259
|
}
|
|
28930
29260
|
}
|
|
28931
29261
|
/**
|
|
29262
|
+
* Fills the fields a partial `record` value leaves out with their schema defaults, at any depth, as
|
|
29263
|
+
* reading a scene file does.
|
|
29264
|
+
*
|
|
29265
|
+
* @param field - The field the value is for.
|
|
29266
|
+
* @param value - The caller's validated value.
|
|
29267
|
+
* @returns A fresh record for a `record` field (or an `optional` one holding a record), otherwise
|
|
29268
|
+
* `value` itself.
|
|
29269
|
+
*/
|
|
29270
|
+
function withRecordDefaults(field, value) {
|
|
29271
|
+
const spec = field.spec;
|
|
29272
|
+
if (spec.kind === "optional") return value === null ? value : withRecordDefaults(spec.inner, value);
|
|
29273
|
+
if (spec.kind !== "record" || !isPlainObject(value)) return value;
|
|
29274
|
+
const merged = {};
|
|
29275
|
+
for (const [name, inner] of Object.entries(spec.fields)) {
|
|
29276
|
+
const given = value[name];
|
|
29277
|
+
merged[name] = given === void 0 ? inner.createDefault() : withRecordDefaults(inner, given);
|
|
29278
|
+
}
|
|
29279
|
+
return merged;
|
|
29280
|
+
}
|
|
29281
|
+
/**
|
|
28932
29282
|
* Builds the "used after destroy" error.
|
|
28933
29283
|
*
|
|
28934
29284
|
* @param uid - The destroyed entity's identifier.
|