@onerjs/core 8.48.4 → 8.48.6

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 (119) hide show
  1. package/Animations/animatable.core.d.ts +13 -0
  2. package/Animations/animatable.core.js +46 -7
  3. package/Animations/animatable.core.js.map +1 -1
  4. package/Cameras/Inputs/geospatialCameraPointersInput.js +10 -8
  5. package/Cameras/Inputs/geospatialCameraPointersInput.js.map +1 -1
  6. package/Cameras/geospatialCameraMovement.js +2 -2
  7. package/Cameras/geospatialCameraMovement.js.map +1 -1
  8. package/FrameGraph/Node/Blocks/Rendering/iblShadowsRendererBlock.d.ts +105 -0
  9. package/FrameGraph/Node/Blocks/Rendering/iblShadowsRendererBlock.js +318 -0
  10. package/FrameGraph/Node/Blocks/Rendering/iblShadowsRendererBlock.js.map +1 -0
  11. package/FrameGraph/Node/Blocks/index.d.ts +1 -0
  12. package/FrameGraph/Node/Blocks/index.js +1 -0
  13. package/FrameGraph/Node/Blocks/index.js.map +1 -1
  14. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsAccumulationTask.d.ts +34 -0
  15. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsAccumulationTask.js +144 -0
  16. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsAccumulationTask.js.map +1 -0
  17. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsSpatialBlurTask.d.ts +26 -0
  18. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsSpatialBlurTask.js +82 -0
  19. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsSpatialBlurTask.js.map +1 -0
  20. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsTracingTask.d.ts +61 -0
  21. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsTracingTask.js +207 -0
  22. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsTracingTask.js.map +1 -0
  23. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsVoxelizationTask.d.ts +104 -0
  24. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsVoxelizationTask.js +218 -0
  25. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsVoxelizationTask.js.map +1 -0
  26. package/FrameGraph/Tasks/Rendering/iblShadowsRendererTask.d.ts +217 -0
  27. package/FrameGraph/Tasks/Rendering/iblShadowsRendererTask.js +640 -0
  28. package/FrameGraph/Tasks/Rendering/iblShadowsRendererTask.js.map +1 -0
  29. package/FrameGraph/frameGraph.js +1 -0
  30. package/FrameGraph/frameGraph.js.map +1 -1
  31. package/FrameGraph/index.d.ts +1 -0
  32. package/FrameGraph/index.js +1 -0
  33. package/FrameGraph/index.js.map +1 -1
  34. package/Materials/PBR/openpbrMaterial.d.ts +13 -2
  35. package/Materials/PBR/openpbrMaterial.js +47 -16
  36. package/Materials/PBR/openpbrMaterial.js.map +1 -1
  37. package/Materials/PBR/pbrBRDFConfiguration.js +1 -1
  38. package/Materials/PBR/pbrBRDFConfiguration.js.map +1 -1
  39. package/Materials/Textures/Filtering/hdrFiltering.js +6 -0
  40. package/Materials/Textures/Filtering/hdrFiltering.js.map +1 -1
  41. package/Materials/Textures/envCubeTexture.js +13 -13
  42. package/Materials/Textures/envCubeTexture.js.map +1 -1
  43. package/Materials/materialHelper.functions.js +1 -1
  44. package/Materials/materialHelper.functions.js.map +1 -1
  45. package/Misc/textureTools.d.ts +3 -1
  46. package/Misc/textureTools.js +74 -13
  47. package/Misc/textureTools.js.map +1 -1
  48. package/Particles/baseParticleSystem.d.ts +33 -1
  49. package/Particles/baseParticleSystem.js +65 -0
  50. package/Particles/baseParticleSystem.js.map +1 -1
  51. package/Particles/computeShaderParticleSystem.js +6 -0
  52. package/Particles/computeShaderParticleSystem.js.map +1 -1
  53. package/Particles/gpuParticleSystem.d.ts +24 -6
  54. package/Particles/gpuParticleSystem.js +85 -36
  55. package/Particles/gpuParticleSystem.js.map +1 -1
  56. package/Particles/particleSystem.d.ts +0 -7
  57. package/Particles/particleSystem.js +3 -15
  58. package/Particles/particleSystem.js.map +1 -1
  59. package/Particles/thinParticleSystem.d.ts +1 -3
  60. package/Particles/thinParticleSystem.js +1 -27
  61. package/Particles/thinParticleSystem.js.map +1 -1
  62. package/Particles/webgl2ParticleSystem.js +7 -0
  63. package/Particles/webgl2ParticleSystem.js.map +1 -1
  64. package/Rendering/IBLShadows/iblShadowsAccumulationPass.js +1 -1
  65. package/Rendering/IBLShadows/iblShadowsAccumulationPass.js.map +1 -1
  66. package/Rendering/IBLShadows/iblShadowsPluginMaterial.d.ts +3 -1
  67. package/Rendering/IBLShadows/iblShadowsPluginMaterial.js +11 -1
  68. package/Rendering/IBLShadows/iblShadowsPluginMaterial.js.map +1 -1
  69. package/Rendering/IBLShadows/iblShadowsRenderPipeline.d.ts +0 -19
  70. package/Rendering/IBLShadows/iblShadowsRenderPipeline.js +21 -65
  71. package/Rendering/IBLShadows/iblShadowsRenderPipeline.js.map +1 -1
  72. package/Rendering/IBLShadows/iblShadowsVoxelRenderer.d.ts +15 -52
  73. package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js +129 -220
  74. package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js.map +1 -1
  75. package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js +3 -0
  76. package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js.map +1 -1
  77. package/Rendering/geometryBufferRenderer.d.ts +14 -5
  78. package/Rendering/geometryBufferRenderer.js +6 -2
  79. package/Rendering/geometryBufferRenderer.js.map +1 -1
  80. package/Rendering/geometryBufferRendererSceneComponent.d.ts +4 -6
  81. package/Rendering/geometryBufferRendererSceneComponent.js.map +1 -1
  82. package/Rendering/iblCdfGenerator.d.ts +10 -0
  83. package/Rendering/iblCdfGenerator.js +52 -17
  84. package/Rendering/iblCdfGenerator.js.map +1 -1
  85. package/Rendering/index.d.ts +0 -6
  86. package/Rendering/index.js +0 -6
  87. package/Rendering/index.js.map +1 -1
  88. package/Shaders/ShadersInclude/openpbrDirectLighting.js +6 -1
  89. package/Shaders/ShadersInclude/openpbrDirectLighting.js.map +1 -1
  90. package/Shaders/ShadersInclude/openpbrEnvironmentLighting.js +1 -1
  91. package/Shaders/ShadersInclude/openpbrEnvironmentLighting.js.map +1 -1
  92. package/Shaders/gpuUpdateParticles.vertex.js +12 -6
  93. package/Shaders/gpuUpdateParticles.vertex.js.map +1 -1
  94. package/Shaders/iblShadowVoxelTracing.fragment.js +5 -1
  95. package/Shaders/iblShadowVoxelTracing.fragment.js.map +1 -1
  96. package/Shaders/iblVoxelGrid.fragment.d.ts +1 -0
  97. package/Shaders/iblVoxelGrid.fragment.js +33 -5
  98. package/Shaders/iblVoxelGrid.fragment.js.map +1 -1
  99. package/Shaders/lod3D.fragment.d.ts +5 -0
  100. package/Shaders/lod3D.fragment.js +13 -0
  101. package/Shaders/lod3D.fragment.js.map +1 -0
  102. package/Shaders/openpbr.fragment.js +5 -0
  103. package/Shaders/openpbr.fragment.js.map +1 -1
  104. package/ShadersWGSL/ShadersInclude/openpbrDirectLighting.js +6 -1
  105. package/ShadersWGSL/ShadersInclude/openpbrDirectLighting.js.map +1 -1
  106. package/ShadersWGSL/ShadersInclude/openpbrEnvironmentLighting.js +1 -1
  107. package/ShadersWGSL/ShadersInclude/openpbrEnvironmentLighting.js.map +1 -1
  108. package/ShadersWGSL/gpuUpdateParticles.compute.js +14 -7
  109. package/ShadersWGSL/gpuUpdateParticles.compute.js.map +1 -1
  110. package/ShadersWGSL/iblShadowVoxelTracing.fragment.js +5 -1
  111. package/ShadersWGSL/iblShadowVoxelTracing.fragment.js.map +1 -1
  112. package/ShadersWGSL/iblVoxelGrid.fragment.js +1 -1
  113. package/ShadersWGSL/iblVoxelGrid.fragment.js.map +1 -1
  114. package/ShadersWGSL/lod3D.fragment.d.ts +5 -0
  115. package/ShadersWGSL/lod3D.fragment.js +13 -0
  116. package/ShadersWGSL/lod3D.fragment.js.map +1 -0
  117. package/ShadersWGSL/openpbr.fragment.js +5 -0
  118. package/ShadersWGSL/openpbr.fragment.js.map +1 -1
  119. package/package.json +1 -1
@@ -0,0 +1,640 @@
1
+
2
+ import { PBRBaseMaterial } from "../../../Materials/PBR/pbrBaseMaterial.js";
3
+ import { OpenPBRMaterial } from "../../../Materials/PBR/openpbrMaterial.js";
4
+ import { StandardMaterial } from "../../../Materials/standardMaterial.js";
5
+ import { IBLShadowsPluginMaterial } from "../../../Rendering/IBLShadows/iblShadowsPluginMaterial.js";
6
+ import { FrameGraphIblShadowsAccumulationTask } from "./iblShadows/iblShadowsAccumulationTask.js";
7
+ import { FrameGraphIblShadowsSpatialBlurTask } from "./iblShadows/iblShadowsSpatialBlurTask.js";
8
+ import { FrameGraphIblShadowsTracingTask } from "./iblShadows/iblShadowsTracingTask.js";
9
+ import { FrameGraphIblShadowsVoxelizationTask } from "./iblShadows/iblShadowsVoxelizationTask.js";
10
+ import { Texture } from "../../../Materials/Textures/texture.js";
11
+ import { CubeTexture } from "../../../Materials/Textures/cubeTexture.js";
12
+ import { Tools } from "../../../Misc/tools.js";
13
+ import { Observable } from "../../../Misc/observable.js";
14
+ import { FrameGraphTask } from "../../frameGraphTask.js";
15
+ import { _RetryWithInterval } from "../../../Misc/timingTools.js";
16
+ import "../../../Rendering/iblCdfGeneratorSceneComponent.js";
17
+ /**
18
+ * Composite task that owns the individual IBL shadows frame graph tasks.
19
+ * The frame graph remains flat internally, but this task groups the pipeline
20
+ * and owns the child task implementation details.
21
+ */
22
+ export class FrameGraphIblShadowsRendererTask extends FrameGraphTask {
23
+ /**
24
+ * Gets the class name.
25
+ * @returns The class name.
26
+ */
27
+ getClassName() {
28
+ return "FrameGraphIblShadowsRendererTask";
29
+ }
30
+ get name() {
31
+ return this._name;
32
+ }
33
+ set name(value) {
34
+ this._name = value;
35
+ if (this._voxelizationTask) {
36
+ this._voxelizationTask.name = `${value} Voxelization`;
37
+ }
38
+ if (this._tracingTask) {
39
+ this._tracingTask.name = `${value} Tracing`;
40
+ }
41
+ if (this._spatialBlurTask) {
42
+ this._spatialBlurTask.name = `${value} Blur`;
43
+ }
44
+ if (this._accumulationTask) {
45
+ this._accumulationTask.name = `${value} Accumulation`;
46
+ }
47
+ }
48
+ /**
49
+ * Whether the task is disabled.
50
+ */
51
+ get disabled() {
52
+ return this._disabled;
53
+ }
54
+ set disabled(value) {
55
+ this._disabled = value;
56
+ if (!this._disabled && this._dependenciesResolved) {
57
+ this._accumulationTask.reset = true;
58
+ }
59
+ this._applyMaterialPluginParameters();
60
+ }
61
+ // ------ Common properties ------
62
+ /** Camera used by the tracing stage. */
63
+ get camera() {
64
+ return this._tracingTask.camera;
65
+ }
66
+ /** Camera used by the tracing stage. */
67
+ set camera(value) {
68
+ this._setCamera(value);
69
+ }
70
+ /** Object list used by voxelization. */
71
+ get objectList() {
72
+ return this._voxelizationTask.objectList;
73
+ }
74
+ /** Object list used by voxelization. */
75
+ set objectList(value) {
76
+ if (this._voxelizationTask.objectList === value) {
77
+ return;
78
+ }
79
+ this._voxelizationTask.objectList = value;
80
+ this._voxelizationTask.updateSceneBounds();
81
+ this._voxelizationTask.requestVoxelizationUpdate();
82
+ this._accumulationTask.reset = true;
83
+ }
84
+ // ------ Tracing properties ------
85
+ /** Number of tracing sample directions. */
86
+ get sampleDirections() {
87
+ return this._tracingTask.sampleDirections;
88
+ }
89
+ /** Number of tracing sample directions. */
90
+ set sampleDirections(value) {
91
+ this._tracingTask.sampleDirections = value;
92
+ this.resetAccumulation();
93
+ }
94
+ /** Whether traced shadows preserve environment color. */
95
+ get coloredShadows() {
96
+ return this._tracingTask.coloredShadows;
97
+ }
98
+ /** Whether traced shadows preserve environment color. */
99
+ set coloredShadows(value) {
100
+ if (this._tracingTask.coloredShadows === value) {
101
+ return;
102
+ }
103
+ this._tracingTask.coloredShadows = value;
104
+ this._applyMaterialPluginParameters();
105
+ this.resetAccumulation();
106
+ }
107
+ /** Opacity of voxel-traced shadows. */
108
+ get voxelShadowOpacity() {
109
+ return this._tracingTask.voxelShadowOpacity;
110
+ }
111
+ /** Opacity of voxel-traced shadows. */
112
+ set voxelShadowOpacity(value) {
113
+ this._tracingTask.voxelShadowOpacity = value;
114
+ this.resetAccumulation();
115
+ }
116
+ /** Opacity of screen-space shadows. */
117
+ get ssShadowOpacity() {
118
+ return this._tracingTask.ssShadowOpacity;
119
+ }
120
+ /** Opacity of screen-space shadows. */
121
+ set ssShadowOpacity(value) {
122
+ this._tracingTask.ssShadowOpacity = value;
123
+ this.resetAccumulation();
124
+ }
125
+ /** Number of screen-space shadow samples. */
126
+ get ssShadowSampleCount() {
127
+ return this._tracingTask.ssShadowSampleCount;
128
+ }
129
+ /** Number of screen-space shadow samples. */
130
+ set ssShadowSampleCount(value) {
131
+ this._tracingTask.ssShadowSampleCount = value;
132
+ this.resetAccumulation();
133
+ }
134
+ /** Stride used by screen-space shadow sampling. */
135
+ get ssShadowStride() {
136
+ return this._tracingTask.ssShadowStride;
137
+ }
138
+ /** Stride used by screen-space shadow sampling. */
139
+ set ssShadowStride(value) {
140
+ this._tracingTask.ssShadowStride = value;
141
+ this.resetAccumulation();
142
+ }
143
+ /** Distance scale used by screen-space shadow tracing. */
144
+ get ssShadowDistanceScale() {
145
+ return this._tracingTask.ssShadowDistanceScale;
146
+ }
147
+ /** Distance scale used by screen-space shadow tracing. */
148
+ set ssShadowDistanceScale(value) {
149
+ this._tracingTask.ssShadowDistanceScale = value;
150
+ this.resetAccumulation();
151
+ }
152
+ /** Thickness scale used by screen-space shadow tracing. */
153
+ get ssShadowThicknessScale() {
154
+ return this._tracingTask.ssShadowThicknessScale;
155
+ }
156
+ /** Thickness scale used by screen-space shadow tracing. */
157
+ set ssShadowThicknessScale(value) {
158
+ this._tracingTask.ssShadowThicknessScale = value;
159
+ this.resetAccumulation();
160
+ }
161
+ /** Voxel tracing normal bias. */
162
+ get voxelNormalBias() {
163
+ return this._tracingTask.voxelNormalBias;
164
+ }
165
+ /** Voxel tracing normal bias. */
166
+ set voxelNormalBias(value) {
167
+ this._tracingTask.voxelNormalBias = value;
168
+ this.resetAccumulation();
169
+ }
170
+ /** Voxel tracing direction bias. */
171
+ get voxelDirectionBias() {
172
+ return this._tracingTask.voxelDirectionBias;
173
+ }
174
+ /** Voxel tracing direction bias. */
175
+ set voxelDirectionBias(value) {
176
+ this._tracingTask.voxelDirectionBias = value;
177
+ this.resetAccumulation();
178
+ }
179
+ /** Environment rotation in radians. */
180
+ get envRotation() {
181
+ return this._tracingTask.envRotation;
182
+ }
183
+ /** Environment rotation in radians. */
184
+ set envRotation(value) {
185
+ this._tracingTask.envRotation = value;
186
+ this.resetAccumulation();
187
+ }
188
+ // ------ Accumulation properties ------
189
+ /** Temporal shadow remanence while moving. */
190
+ get shadowRemanence() {
191
+ return this._accumulationTask.remanence;
192
+ }
193
+ /** Temporal shadow remanence while moving. */
194
+ set shadowRemanence(value) {
195
+ this._accumulationTask.remanence = value;
196
+ }
197
+ /** Final material shadow opacity. */
198
+ get shadowOpacity() {
199
+ return this._shadowOpacity;
200
+ }
201
+ /** Final material shadow opacity. */
202
+ set shadowOpacity(value) {
203
+ this._shadowOpacity = Math.max(0, Math.min(value, 1));
204
+ this._applyMaterialPluginParameters();
205
+ }
206
+ // ------ Voxelization properties ------
207
+ /** Voxelization resolution exponent. */
208
+ get resolutionExp() {
209
+ return this._voxelizationTask.resolutionExp;
210
+ }
211
+ /** Voxelization resolution exponent. */
212
+ set resolutionExp(value) {
213
+ this._voxelizationTask.resolutionExp = value;
214
+ this.resetAccumulation();
215
+ }
216
+ /** Voxelization refresh rate. */
217
+ get refreshRate() {
218
+ return this._voxelizationTask.refreshRate;
219
+ }
220
+ /** Voxelization refresh rate. */
221
+ set refreshRate(value) {
222
+ this._voxelizationTask.refreshRate = value;
223
+ }
224
+ /** Whether tri-planar voxelization is used. */
225
+ get triPlanarVoxelization() {
226
+ return this._voxelizationTask.triPlanarVoxelization;
227
+ }
228
+ /** Whether tri-planar voxelization is used. */
229
+ set triPlanarVoxelization(value) {
230
+ this._voxelizationTask.triPlanarVoxelization = value;
231
+ }
232
+ /** Current world-space voxel grid size. */
233
+ get voxelGridSize() {
234
+ return this._voxelizationTask.voxelGridSize;
235
+ }
236
+ /** True when the accumulated output texture is ready. */
237
+ get outputTextureReady() {
238
+ return !!this._getAccumulationOutputTexture()?.isReady;
239
+ }
240
+ /** Notifies when the accumulated output texture becomes ready. */
241
+ get onOutputTextureReadyObservable() {
242
+ return this._outputTextureReadyObservable;
243
+ }
244
+ // ------ Public methods ------
245
+ /** Triggers a voxelization refresh on the next eligible frame. */
246
+ updateVoxelization() {
247
+ this._voxelizationTask.requestVoxelizationUpdate();
248
+ }
249
+ /** Recomputes the voxelization scene bounds from the current object list. */
250
+ updateSceneBounds() {
251
+ this._voxelizationTask.updateSceneBounds();
252
+ }
253
+ /** Resets temporal accumulation. */
254
+ resetAccumulation() {
255
+ this._accumulationTask.reset = true;
256
+ }
257
+ /**
258
+ * Adds one or more materials that should receive IBL shadows.
259
+ * @param material The material or materials to register. If omitted, all scene materials are added.
260
+ */
261
+ addShadowReceivingMaterial(material) {
262
+ if (!material) {
263
+ for (const sceneMaterial of this._frameGraph.scene.materials) {
264
+ this._addShadowReceivingMaterialInternal(sceneMaterial);
265
+ }
266
+ }
267
+ else if (Array.isArray(material)) {
268
+ for (const sceneMaterial of material) {
269
+ this._addShadowReceivingMaterialInternal(sceneMaterial);
270
+ }
271
+ }
272
+ else {
273
+ this._addShadowReceivingMaterialInternal(material);
274
+ }
275
+ this._applyMaterialPluginParameters();
276
+ }
277
+ /**
278
+ * Removes one or more materials from IBL shadow reception.
279
+ * @param material The material or materials to unregister.
280
+ */
281
+ removeShadowReceivingMaterial(material) {
282
+ const materials = Array.isArray(material) ? material : [material];
283
+ for (const mat of materials) {
284
+ const index = this._materialsWithRenderPlugin.indexOf(mat);
285
+ if (index !== -1) {
286
+ this._materialsWithRenderPlugin.splice(index, 1);
287
+ }
288
+ const plugin = mat.pluginManager?.getPlugin(IBLShadowsPluginMaterial.Name);
289
+ if (plugin) {
290
+ plugin.isEnabled = false;
291
+ }
292
+ }
293
+ }
294
+ /** Clears all registered shadow-receiving materials. */
295
+ clearShadowReceivingMaterials() {
296
+ for (const mat of this._materialsWithRenderPlugin) {
297
+ const plugin = mat.pluginManager?.getPlugin(IBLShadowsPluginMaterial.Name);
298
+ if (plugin) {
299
+ plugin.isEnabled = false;
300
+ }
301
+ }
302
+ this._materialsWithRenderPlugin.length = 0;
303
+ }
304
+ /**
305
+ * Adds one or more meshes to the voxelization object list.
306
+ * @param mesh The mesh or meshes to add.
307
+ */
308
+ addShadowCastingMesh(mesh) {
309
+ const meshes = Array.isArray(mesh) ? mesh : [mesh];
310
+ const objectMeshes = this._voxelizationTask.objectList.meshes;
311
+ for (const currentMesh of meshes) {
312
+ if (currentMesh && objectMeshes.indexOf(currentMesh) === -1) {
313
+ objectMeshes.push(currentMesh);
314
+ }
315
+ }
316
+ }
317
+ /**
318
+ * Removes one or more meshes from the voxelization object list.
319
+ * @param mesh The mesh or meshes to remove.
320
+ */
321
+ removeShadowCastingMesh(mesh) {
322
+ const meshes = Array.isArray(mesh) ? mesh : [mesh];
323
+ const objectMeshes = this._voxelizationTask.objectList.meshes;
324
+ for (const currentMesh of meshes) {
325
+ const index = objectMeshes.indexOf(currentMesh);
326
+ if (index !== -1) {
327
+ objectMeshes.splice(index, 1);
328
+ }
329
+ }
330
+ }
331
+ /** Clears all shadow-casting meshes from the voxelization object list. */
332
+ clearShadowCastingMeshes() {
333
+ const objectMeshes = this._voxelizationTask.objectList.meshes;
334
+ objectMeshes.length = 0;
335
+ }
336
+ // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax
337
+ initAsync() {
338
+ this._frameGraph.scene.enableIblCdfGenerator();
339
+ return new Promise((resolve, reject) => {
340
+ this._initAsyncCancel = _RetryWithInterval(() => this._tryEnableShadowsTasks(), () => {
341
+ this._initAsyncCancel = null;
342
+ resolve();
343
+ }, (err, isTimeout) => {
344
+ this._initAsyncCancel = null;
345
+ if (isTimeout) {
346
+ reject(new Error(`FrameGraphIblShadowsRendererTask "${this.name}": timed out waiting for shadow dependencies to be ready.`));
347
+ }
348
+ else {
349
+ reject(new Error(err));
350
+ }
351
+ }, 16, 10000);
352
+ });
353
+ }
354
+ isReady() {
355
+ return this._voxelizationTask.isReady() && this._tracingTask.isReady() && this._spatialBlurTask.isReady() && this._accumulationTask.isReady();
356
+ }
357
+ /**
358
+ * Records the parent task.
359
+ * Child tasks record the actual passes.
360
+ */
361
+ record() {
362
+ if (this.depthTexture === undefined || this.normalTexture === undefined || this.positionTexture === undefined || this.velocityTexture === undefined) {
363
+ throw new Error(`FrameGraphIblShadowsRendererTask "${this.name}": depthTexture, normalTexture, positionTexture and velocityTexture are required`);
364
+ }
365
+ this._lastImportedIcdfTexture = null;
366
+ this._lastImportedEnvironmentTexture = null;
367
+ this._lastImportedBlueNoiseTexture = null;
368
+ this._tryEnableShadowsTasks();
369
+ // Set sub-task texture inputs (these are set here because handles may not be available at construction time)
370
+ this._tracingTask.depthTexture = this.depthTexture;
371
+ this._tracingTask.normalTexture = this.normalTexture;
372
+ this._spatialBlurTask.depthTexture = this.depthTexture;
373
+ this._spatialBlurTask.normalTexture = this.normalTexture;
374
+ this._accumulationTask.positionTexture = this.positionTexture;
375
+ this._accumulationTask.velocityTexture = this.velocityTexture;
376
+ this._voxelizationTask.record();
377
+ this._tracingTask.record();
378
+ this._spatialBlurTask.record();
379
+ this._accumulationTask.record();
380
+ const passDisabled = this._frameGraph.addRenderPass(this.name + "_disabled", true);
381
+ passDisabled.setRenderTarget(this.outputTexture);
382
+ passDisabled.setExecuteFunc((_context) => { });
383
+ }
384
+ /**
385
+ * Disposes the task and owned resources.
386
+ */
387
+ dispose() {
388
+ this._initAsyncCancel?.();
389
+ this._initAsyncCancel = null;
390
+ this._disposeObservers();
391
+ this._voxelizationTask.dispose();
392
+ this._tracingTask.dispose();
393
+ this._spatialBlurTask.dispose();
394
+ this._accumulationTask.dispose();
395
+ super.dispose();
396
+ }
397
+ /**
398
+ * Creates a new IBL shadows composite task.
399
+ * @param name The task name.
400
+ * @param frameGraph The owning frame graph.
401
+ */
402
+ constructor(name, frameGraph) {
403
+ super(name, frameGraph);
404
+ this._dependenciesResolved = false;
405
+ this._shadowOpacity = 1.0;
406
+ this._materialsWithRenderPlugin = [];
407
+ this._outputTextureReadyObservable = new Observable();
408
+ this._lastNotifiedOutputTexture = null;
409
+ this._observedEnvironmentTexture = null;
410
+ this._observedEnvironmentTextureUnsubscribe = null;
411
+ this._lastImportedIcdfTexture = null;
412
+ this._lastImportedEnvironmentTexture = null;
413
+ this._lastImportedBlueNoiseTexture = null;
414
+ this._cameraViewChangedObserver = null;
415
+ this._cdfTextureChangedObserver = null;
416
+ this._cdfGeneratedObserver = null;
417
+ this._environmentTextureChangedObserver = null;
418
+ this._beforeRenderDependencyObserver = null;
419
+ this._beforeRenderOutputReadyObserver = null;
420
+ this._blueNoiseLoadObserver = null;
421
+ this._texturesAllocatedObserver = null;
422
+ this._voxelizationCompleteObserver = null;
423
+ // ------ Framework overrides ------
424
+ this._initAsyncCancel = null;
425
+ this._onEnvironmentTextureLoaded = () => {
426
+ this._tryEnableShadowsTasks();
427
+ };
428
+ this._voxelizationTask = new FrameGraphIblShadowsVoxelizationTask(`${name} Voxelization`, frameGraph);
429
+ this._tracingTask = new FrameGraphIblShadowsTracingTask(`${name} Tracing`, frameGraph);
430
+ this._tracingTask.voxelGridTexture = this._voxelizationTask.outputVoxelGridTexture;
431
+ this._tracingTask.worldScaleMatrix = this._voxelizationTask.worldScaleMatrix;
432
+ this._tracingTask.voxelizationTask = this._voxelizationTask;
433
+ this._spatialBlurTask = new FrameGraphIblShadowsSpatialBlurTask(`${name} Blur`, frameGraph);
434
+ this._spatialBlurTask.sourceTexture = this._tracingTask.outputTexture;
435
+ this._spatialBlurTask.voxelizationTask = this._voxelizationTask;
436
+ this._accumulationTask = new FrameGraphIblShadowsAccumulationTask(`${name} Accumulation`, frameGraph);
437
+ this._accumulationTask.sourceTexture = this._spatialBlurTask.outputTexture;
438
+ this._accumulationTask.voxelizationTask = this._voxelizationTask;
439
+ this.outputTexture = this._accumulationTask.outputTexture;
440
+ this._blueNoiseTexture = new Texture(Tools.GetAssetUrl("https://assets.babylonjs.com/core/blue_noise/blue_noise_rgb.png"), frameGraph.scene, false, true, 1);
441
+ this._initialize();
442
+ }
443
+ _disposeDependencyObservers() {
444
+ this._observedEnvironmentTextureUnsubscribe?.();
445
+ this._observedEnvironmentTextureUnsubscribe = null;
446
+ this._observedEnvironmentTexture = null;
447
+ }
448
+ _disposeObservers() {
449
+ this._disposeDependencyObservers();
450
+ this._tracingTask.camera?.onViewMatrixChangedObservable.remove(this._cameraViewChangedObserver);
451
+ this._frameGraph.scene.iblCdfGenerator?.onTextureChangedObservable.remove(this._cdfTextureChangedObserver);
452
+ this._frameGraph.scene.iblCdfGenerator?.onGeneratedObservable.remove(this._cdfGeneratedObserver);
453
+ this._frameGraph.scene.onEnvironmentTextureChangedObservable.remove(this._environmentTextureChangedObserver);
454
+ this._frameGraph.scene.onBeforeRenderObservable.remove(this._beforeRenderDependencyObserver);
455
+ this._frameGraph.scene.onBeforeRenderObservable.remove(this._beforeRenderOutputReadyObserver);
456
+ this._blueNoiseTexture.onLoadObservable.remove(this._blueNoiseLoadObserver);
457
+ this.onTexturesAllocatedObservable.remove(this._texturesAllocatedObserver);
458
+ this._voxelizationTask.onVoxelizationCompleteObservable.remove(this._voxelizationCompleteObserver);
459
+ this._cameraViewChangedObserver = null;
460
+ this._cdfTextureChangedObserver = null;
461
+ this._cdfGeneratedObserver = null;
462
+ this._environmentTextureChangedObserver = null;
463
+ this._beforeRenderDependencyObserver = null;
464
+ this._beforeRenderOutputReadyObserver = null;
465
+ this._blueNoiseLoadObserver = null;
466
+ this._texturesAllocatedObserver = null;
467
+ this._voxelizationCompleteObserver = null;
468
+ this._blueNoiseTexture.dispose();
469
+ }
470
+ _setCamera(camera) {
471
+ const currentCamera = this._tracingTask.camera;
472
+ if (currentCamera === camera && this._cameraViewChangedObserver !== null) {
473
+ return;
474
+ }
475
+ if (currentCamera && this._cameraViewChangedObserver) {
476
+ currentCamera.onViewMatrixChangedObservable.remove(this._cameraViewChangedObserver);
477
+ this._cameraViewChangedObserver = null;
478
+ }
479
+ this._tracingTask.camera = camera;
480
+ this._cameraViewChangedObserver = camera.onViewMatrixChangedObservable.add(() => {
481
+ this._accumulationTask.isMoving = true;
482
+ });
483
+ this._accumulationTask.reset = true;
484
+ }
485
+ _observeEnvironmentTexture() {
486
+ const env = this._frameGraph.scene.environmentTexture;
487
+ const currentEnvironmentTexture = env instanceof Texture || env instanceof CubeTexture ? env : null;
488
+ if (currentEnvironmentTexture === this._observedEnvironmentTexture) {
489
+ return;
490
+ }
491
+ this._observedEnvironmentTextureUnsubscribe?.();
492
+ this._observedEnvironmentTextureUnsubscribe = null;
493
+ this._observedEnvironmentTexture = currentEnvironmentTexture;
494
+ if (currentEnvironmentTexture instanceof Texture) {
495
+ const observer = currentEnvironmentTexture.onLoadObservable.add(this._onEnvironmentTextureLoaded);
496
+ if (observer) {
497
+ this._observedEnvironmentTextureUnsubscribe = () => currentEnvironmentTexture.onLoadObservable.remove(observer);
498
+ }
499
+ }
500
+ else if (currentEnvironmentTexture instanceof CubeTexture) {
501
+ const observer = currentEnvironmentTexture.onLoadObservable.add(this._onEnvironmentTextureLoaded);
502
+ if (observer) {
503
+ this._observedEnvironmentTextureUnsubscribe = () => currentEnvironmentTexture.onLoadObservable.remove(observer);
504
+ }
505
+ }
506
+ }
507
+ _getEnvironmentTextureInternal() {
508
+ const currentEnvironmentTexture = this._frameGraph.scene.environmentTexture;
509
+ if (!currentEnvironmentTexture || !currentEnvironmentTexture.isReadyOrNotBlocking()) {
510
+ return null;
511
+ }
512
+ const internalTexture = currentEnvironmentTexture.getInternalTexture();
513
+ return internalTexture?.isReady ? internalTexture : null;
514
+ }
515
+ _getAccumulationOutputTexture() {
516
+ try {
517
+ return this._frameGraph.textureManager.getTextureFromHandle(this._accumulationTask.outputTexture);
518
+ }
519
+ catch {
520
+ return null;
521
+ }
522
+ }
523
+ _notifyIfOutputTextureReady() {
524
+ const outputTexture = this._getAccumulationOutputTexture();
525
+ if (!outputTexture?.isReady || this._lastNotifiedOutputTexture === outputTexture) {
526
+ return;
527
+ }
528
+ this._lastNotifiedOutputTexture = outputTexture;
529
+ this._outputTextureReadyObservable.notifyObservers(outputTexture);
530
+ }
531
+ _applyMaterialPluginParameters() {
532
+ const accumulationTexture = this._getAccumulationOutputTexture();
533
+ for (const material of this._materialsWithRenderPlugin) {
534
+ const plugin = material.pluginManager?.getPlugin(IBLShadowsPluginMaterial.Name);
535
+ if (!plugin) {
536
+ continue;
537
+ }
538
+ if (accumulationTexture && accumulationTexture.isReady) {
539
+ plugin.iblShadowsTexture = accumulationTexture;
540
+ }
541
+ plugin.shadowOpacity = this._shadowOpacity;
542
+ plugin.isColored = this._tracingTask.coloredShadows;
543
+ plugin.isEnabled = !this._disabled && this._dependenciesResolved && !!accumulationTexture;
544
+ }
545
+ }
546
+ _addShadowReceivingMaterialInternal(material) {
547
+ const isSupportedMaterial = material instanceof PBRBaseMaterial || material instanceof StandardMaterial || material instanceof OpenPBRMaterial;
548
+ if (!isSupportedMaterial || this._materialsWithRenderPlugin.indexOf(material) !== -1) {
549
+ return;
550
+ }
551
+ const plugin = material.pluginManager?.getPlugin(IBLShadowsPluginMaterial.Name);
552
+ if (!plugin) {
553
+ new IBLShadowsPluginMaterial(material);
554
+ }
555
+ this._materialsWithRenderPlugin.push(material);
556
+ }
557
+ _tryEnableShadowsTasks() {
558
+ const scene = this._frameGraph.scene;
559
+ const icdfTexture = scene.iblCdfGenerator?.getIcdfTexture().getInternalTexture();
560
+ const environmentTexture = this._getEnvironmentTextureInternal();
561
+ const blueNoiseInternalTexture = this._blueNoiseTexture.getInternalTexture();
562
+ if (!icdfTexture?.isReady || icdfTexture.width === 1 || !environmentTexture?.isReady || !blueNoiseInternalTexture?.isReady) {
563
+ if (this._dependenciesResolved) {
564
+ this._dependenciesResolved = false;
565
+ this._applyMaterialPluginParameters();
566
+ }
567
+ return false;
568
+ }
569
+ const icdfChanged = this._lastImportedIcdfTexture !== icdfTexture;
570
+ const environmentChanged = this._lastImportedEnvironmentTexture !== environmentTexture;
571
+ const blueNoiseChanged = this._lastImportedBlueNoiseTexture !== blueNoiseInternalTexture;
572
+ if (icdfChanged) {
573
+ this._tracingTask.icdfTexture = this._frameGraph.textureManager.importTexture(`ICDF Texture`, icdfTexture, this._tracingTask.icdfTexture);
574
+ this._lastImportedIcdfTexture = icdfTexture;
575
+ }
576
+ if (environmentChanged) {
577
+ this._tracingTask.environmentTexture = this._frameGraph.textureManager.importTexture(`Environment Texture`, environmentTexture, this._tracingTask.environmentTexture);
578
+ this._lastImportedEnvironmentTexture = environmentTexture;
579
+ }
580
+ if (blueNoiseChanged) {
581
+ this._tracingTask.blueNoiseTexture = this._frameGraph.textureManager.importTexture(`Blue Noise Texture`, blueNoiseInternalTexture, this._tracingTask.blueNoiseTexture);
582
+ this._lastImportedBlueNoiseTexture = blueNoiseInternalTexture;
583
+ }
584
+ if (!this._dependenciesResolved) {
585
+ this._dependenciesResolved = true;
586
+ if (!this._disabled) {
587
+ this._accumulationTask.reset = true;
588
+ }
589
+ this._disposeDependencyObservers();
590
+ }
591
+ else if (icdfChanged || environmentChanged || blueNoiseChanged) {
592
+ this._accumulationTask.reset = true;
593
+ }
594
+ this._applyMaterialPluginParameters();
595
+ return true;
596
+ }
597
+ _initialize() {
598
+ const scene = this._frameGraph.scene;
599
+ this._voxelizationCompleteObserver = this._voxelizationTask.onVoxelizationCompleteObservable.add(() => {
600
+ this._tracingTask.voxelGridTexture = this._voxelizationTask.outputVoxelGridTexture;
601
+ this._accumulationTask.reset = true;
602
+ });
603
+ this._cdfTextureChangedObserver =
604
+ scene.iblCdfGenerator?.onTextureChangedObservable.add(() => {
605
+ this._lastImportedIcdfTexture = null;
606
+ this._accumulationTask.reset = true;
607
+ }) ?? null;
608
+ this._cdfGeneratedObserver =
609
+ scene.iblCdfGenerator?.onGeneratedObservable.add(() => {
610
+ this._lastImportedIcdfTexture = null;
611
+ this._tryEnableShadowsTasks();
612
+ }) ?? null;
613
+ this._environmentTextureChangedObserver = scene.onEnvironmentTextureChangedObservable.add(() => {
614
+ this._lastImportedEnvironmentTexture = null;
615
+ this._dependenciesResolved = false;
616
+ this._observeEnvironmentTexture();
617
+ this._applyMaterialPluginParameters();
618
+ this._tryEnableShadowsTasks();
619
+ });
620
+ this._observeEnvironmentTexture();
621
+ if (scene.environmentTexture?.isReadyOrNotBlocking()) {
622
+ this._tryEnableShadowsTasks();
623
+ }
624
+ this._blueNoiseLoadObserver = this._blueNoiseTexture.onLoadObservable.add(() => {
625
+ this._tryEnableShadowsTasks();
626
+ });
627
+ this._beforeRenderDependencyObserver = scene.onBeforeRenderObservable.add(() => {
628
+ this._tryEnableShadowsTasks();
629
+ });
630
+ this._beforeRenderOutputReadyObserver = scene.onBeforeRenderObservable.add(() => {
631
+ this._notifyIfOutputTextureReady();
632
+ });
633
+ this._tryEnableShadowsTasks();
634
+ this._texturesAllocatedObserver = this.onTexturesAllocatedObservable.add(() => {
635
+ this._applyMaterialPluginParameters();
636
+ this._notifyIfOutputTextureReady();
637
+ });
638
+ }
639
+ }
640
+ //# sourceMappingURL=iblShadowsRendererTask.js.map