babylonjs-editor-tools 5.5.1 → 5.5.2

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 (44) hide show
  1. package/build/index.node.js +407 -121
  2. package/build/src/decorators/apply.js +2 -2
  3. package/build/src/decorators/apply.js.map +1 -1
  4. package/build/src/decorators/scene.js +16 -16
  5. package/build/src/decorators/scene.js.map +1 -1
  6. package/build/src/decorators/sound.js +2 -2
  7. package/build/src/decorators/sound.js.map +1 -1
  8. package/build/src/index.js +1 -0
  9. package/build/src/index.js.map +1 -1
  10. package/build/src/loading/loader.js +21 -7
  11. package/build/src/loading/loader.js.map +1 -1
  12. package/build/src/rendering/order.js +110 -0
  13. package/build/src/rendering/order.js.map +1 -0
  14. package/build/src/rendering/ssao.js +1 -1
  15. package/build/src/rendering/ssao.js.map +1 -1
  16. package/build/src/rendering/tools.js +3 -0
  17. package/build/src/rendering/tools.js.map +1 -1
  18. package/build/src/rendering/volumetric/pipeline.js +403 -26
  19. package/build/src/rendering/volumetric/pipeline.js.map +1 -1
  20. package/build/src/rendering/volumetric/selector.js +2 -1
  21. package/build/src/rendering/volumetric/selector.js.map +1 -1
  22. package/build/src/rendering/volumetric/shaders-wgsl.js +197 -60
  23. package/build/src/rendering/volumetric/shaders-wgsl.js.map +1 -1
  24. package/build/src/rendering/volumetric/shaders.js +179 -5
  25. package/build/src/rendering/volumetric/shaders.js.map +1 -1
  26. package/build/src/rendering/volumetric/types.js +27 -1
  27. package/build/src/rendering/volumetric/types.js.map +1 -1
  28. package/build/src/rendering/volumetric-lighting.js.map +1 -1
  29. package/build/src/tools/scene.js +18 -5
  30. package/build/src/tools/scene.js.map +1 -1
  31. package/declaration/src/decorators/apply.d.ts +8 -4
  32. package/declaration/src/decorators/scene.d.ts +18 -9
  33. package/declaration/src/decorators/sound.d.ts +10 -1
  34. package/declaration/src/index.d.ts +1 -0
  35. package/declaration/src/loading/loader.d.ts +1 -1
  36. package/declaration/src/rendering/order.d.ts +31 -0
  37. package/declaration/src/rendering/volumetric/pipeline.d.ts +83 -1
  38. package/declaration/src/rendering/volumetric/selector.d.ts +6 -2
  39. package/declaration/src/rendering/volumetric/shaders-wgsl.d.ts +5 -1
  40. package/declaration/src/rendering/volumetric/shaders.d.ts +16 -2
  41. package/declaration/src/rendering/volumetric/types.d.ts +46 -1
  42. package/declaration/src/rendering/volumetric-lighting.d.ts +1 -1
  43. package/declaration/src/tools/scene.d.ts +2 -1
  44. package/package.json +1 -1
@@ -22,10 +22,12 @@ import { VolumetricDepthSource } from "./depth";
22
22
  * light is marched along the whole view ray, but a point or a spot light is only integrated over the part
23
23
  * of the view ray crossing its volume, so a light costs nothing to the pixels whose view ray misses it.
24
24
  *
25
- * The pipeline is composed of four passes:
25
+ * The pipeline is composed of the following passes:
26
26
  * - a pass keeping the color of the scene untouched and extracting its linear depth, which every later pass
27
27
  * reads instead of the depth map,
28
28
  * - the raymarching pass, rendered at a fraction of the resolution of the canvas,
29
+ * - when the temporal accumulation is enabled, a pass blending the result of the raymarching with the result of
30
+ * the previous frames, which lets the raymarching compute a fraction of its samples each frame,
29
31
  * - a separable depth aware blur denoising the result of the raymarching,
30
32
  * - a composition pass upsampling the result and adding it to the color of the scene.
31
33
  */
@@ -38,6 +40,10 @@ export declare class VolumetricLightingRenderingPipeline extends PostProcessRend
38
40
  * Defines the name of the render effect raymarching the participating medium.
39
41
  */
40
42
  static readonly ScatteringEffectName: string;
43
+ /**
44
+ * Defines the name of the render effect accumulating the result of the raymarching over the frames.
45
+ */
46
+ static readonly TemporalEffectName: string;
41
47
  /**
42
48
  * Defines the name of the render effect denoising the result of the raymarching.
43
49
  */
@@ -82,30 +88,51 @@ export declare class VolumetricLightingRenderingPipeline extends PostProcessRend
82
88
  private _textureType;
83
89
  private _shaderLanguage;
84
90
  private _ldrEncode;
91
+ private _linearDepthType;
85
92
  private _linearDepthPacked;
86
93
  private _msaaSamples;
87
94
  private _msaaSamplesAssigned;
88
95
  private _depthSource;
89
96
  private _depthRenderer;
90
97
  private _ownsDepthRenderer;
98
+ private _depthMapRenderedWithCamera;
91
99
  private _depthMode;
92
100
  private _prePassConfiguration;
93
101
  private _linearDepthPostProcess;
94
102
  private _scatteringPostProcess;
103
+ private _temporalPostProcess;
95
104
  private _blurPostProcesses;
96
105
  private _composePostProcess;
106
+ private _temporalSamplesDivider;
107
+ private _temporalClippingWidth;
108
+ private _temporalMotionTolerance;
109
+ private _previousCameraPosition;
110
+ private _historyTextures;
111
+ private _historyFrames;
112
+ private _historyEmpty;
113
+ private _historyIndex;
114
+ private _temporalFrame;
115
+ private _previousViewProjection;
116
+ private _previousViewProjectionRelative;
117
+ private _cameraTranslation;
97
118
  private _selection;
98
119
  private _budget;
99
120
  private _linearDepthDefines;
100
121
  private _scatteringDefines;
122
+ private _temporalDefines;
101
123
  private _blurDefines;
102
124
  private _composeDefines;
103
125
  private _frameCount;
104
126
  private _lightsDirty;
105
127
  private _disposed;
128
+ private _idle;
129
+ private _depthWarmup;
106
130
  private _beforeCameraRenderObserver;
131
+ private _afterCameraRenderObserver;
107
132
  private _lightAddedObserver;
108
133
  private _lightRemovedObserver;
134
+ private _meshAddedObserver;
135
+ private _meshRemovedObserver;
109
136
  private _inverseViewProjection;
110
137
  private _temporaryVector;
111
138
  private _temporaryColor;
@@ -150,6 +177,11 @@ export declare class VolumetricLightingRenderingPipeline extends PostProcessRend
150
177
  * change immediately, rebuilding the chain of post-processes when the change requires it.
151
178
  */
152
179
  get configuration(): IVolumetricLightingConfiguration;
180
+ /**
181
+ * Gets wether or not the pipeline had nothing to draw at its last update: no light reaches the view of the camera
182
+ * and the medium neither glows nor attenuates the scene. Its passes then cost next to nothing.
183
+ */
184
+ get isIdle(): boolean;
153
185
  /**
154
186
  * Gets where the depth of the scene is currently read from. @see VolumetricDepthSource
155
187
  */
@@ -231,6 +263,19 @@ export declare class VolumetricLightingRenderingPipeline extends PostProcessRend
231
263
  * depth pass, and detects the format it stores so the shader can be compiled for it.
232
264
  */
233
265
  private _setupDepthRenderer;
266
+ /**
267
+ * Returns wether or not the depth renderer of the camera the scene hands to the effects asking for it changed
268
+ * since the pipeline chose its own: created by another effect, or disabled by the one that created it.
269
+ */
270
+ private _hasDepthRendererOfCameraChanged;
271
+ /**
272
+ * Adds the depth map the pipeline owns to the render targets of the camera, or removes it. The scene collects
273
+ * its own render targets before the pipeline decides wether it has anything to draw this frame, but renders
274
+ * the ones of the camera after: the frame the pipeline has something to draw again, only the latter render the
275
+ * depth map in time. They are only used for that frame, rendering it with the ones of the scene costs less
276
+ * time to the CPU.
277
+ */
278
+ private _setDepthMapRenderedWithCamera;
234
279
  /**
235
280
  * Binds the two values needed to turn the content of the depth map back into a distance along the view
236
281
  * axis. The depth renderer stores "(clipZ + minZ) / (minZ + maxZ)", where "clipZ" is affine in the view
@@ -238,6 +283,15 @@ export declare class VolumetricLightingRenderingPipeline extends PostProcessRend
238
283
  * can be derived exactly from the projection matrix instead of being approximated.
239
284
  */
240
285
  private _bindDepthUniforms;
286
+ /**
287
+ * Returns the number of samples the raymarching computes each frame, fewer with the temporal accumulation.
288
+ */
289
+ private _getSamplingSteps;
290
+ /**
291
+ * Returns the dithering mode the raymarching is compiled with. The temporal accumulation needs the samples of
292
+ * neighboring pixels to differ: it tells its own noise from the changes of the scene with it.
293
+ */
294
+ private _getDitherMode;
241
295
  private _getEnvironment;
242
296
  /**
243
297
  * Returns the defines of the passes reading the linear depth, which only depend on how it is stored.
@@ -248,11 +302,23 @@ export declare class VolumetricLightingRenderingPipeline extends PostProcessRend
248
302
  */
249
303
  private _buildLinearDepthDefines;
250
304
  private _buildScatteringDefines;
305
+ private _buildTemporalDefines;
251
306
  private _buildBlurDefines;
252
307
  private _buildComposeDefines;
253
308
  private _createPostProcess;
254
309
  private _buildRenderEffects;
255
310
  private _disposePostProcesses;
311
+ /**
312
+ * Releases the textures holding the history of the temporal accumulation. The next frame starts over from the
313
+ * result of the raymarching alone.
314
+ */
315
+ private _disposeHistory;
316
+ /**
317
+ * Swaps the two textures holding the history of the temporal accumulation, as the pass is activated: the one
318
+ * written last frame is read back, the other one receives the result of this frame and is what the pass after
319
+ * it reads, the same way the TAA rendering pipeline of Babylon.js does.
320
+ */
321
+ private _prepareHistory;
256
322
  /**
257
323
  * Rebuilds the chain of post-processes. Changing the resolution of the scattering buffer or the number
258
324
  * of blur passes changes the shape of the chain, which a post-process can't do in place.
@@ -264,6 +330,21 @@ export declare class VolumetricLightingRenderingPipeline extends PostProcessRend
264
330
  * uniform update: only the directional lights and the kinds of the shadow maps shape the shader.
265
331
  */
266
332
  private _updateSelection;
333
+ /**
334
+ * Detects when the pipeline has nothing to draw: no light reaches the view of the camera and the medium neither
335
+ * glows nor attenuates the scene. Every pass then exits right away, the composition outputs the color of the
336
+ * scene exactly as it would under light shafts of zero intensity, and the depth renderer the pipeline owns stops
337
+ * rendering the scene a second time. This is driven by uniforms rather than by detaching the passes, so a light
338
+ * blinking on and off, a muzzle flash typically, never rebuilds anything.
339
+ */
340
+ private _updateIdleState;
341
+ /**
342
+ * Prepares the depth shaders of the meshes while the depth renderer the pipeline owns is off, a few meshes per
343
+ * frame. Without this, the first frame with something to draw after the scene got new meshes, or after the
344
+ * pipeline was created without anything to draw, would miss every mesh whose depth shader is still compiling.
345
+ * The checks are the ones the scene runs for its depth renderers when it waits to be ready.
346
+ */
347
+ private _warmUpDepthRenderer;
267
348
  /**
268
349
  * Fills the four vectors describing a light in the raymarching shader. The packing follows what
269
350
  * "Light.transferToEffect" writes for the surfaces of the scene so the shafts agree with them, except for
@@ -279,6 +360,7 @@ export declare class VolumetricLightingRenderingPipeline extends PostProcessRend
279
360
  * makes them all associate each texel of the scattering buffer with the same texel of the linear depth.
280
361
  */
281
362
  private _bindDepthRatio;
363
+ private _bindTemporal;
282
364
  private _bindBlur;
283
365
  private _bindCompose;
284
366
  }
@@ -235,7 +235,7 @@ export interface IVolumetricShaderEnvironment {
235
235
  transmittance: VolumetricTransmittanceMode;
236
236
  /**
237
237
  * Defines wether or not the linear depth of the scene is packed in an 8 bits RGBA texture because the
238
- * engine can't render to a 32 bits float one.
238
+ * engine can't render to a float one.
239
239
  */
240
240
  linearDepthPacked: boolean;
241
241
  /**
@@ -245,7 +245,11 @@ export interface IVolumetricShaderEnvironment {
245
245
  */
246
246
  arrayLightCapacity: number;
247
247
  /**
248
- * Defines the number of samples taken across the volume of each point and spot light.
248
+ * Defines the number of steps the directional lights are marched with each frame. @see getVolumetricSamplingSteps
249
+ */
250
+ steps: number;
251
+ /**
252
+ * Defines the number of samples taken across the volume of each point and spot light each frame.
249
253
  */
250
254
  lightSteps: number;
251
255
  }
@@ -7,6 +7,10 @@ export declare function buildVolumetricLightingLinearDepthShaderWGSL(): string;
7
7
  * @param shadowSlotCount defines the number of shadowed light slots the shader is generated for.
8
8
  */
9
9
  export declare function buildVolumetricLightingScatteringShaderWGSL(shadowSlotCount: number): string;
10
+ /**
11
+ * The temporal accumulation pass. @see buildVolumetricLightingTemporalShader.
12
+ */
13
+ export declare function buildVolumetricLightingTemporalShaderWGSL(): string;
10
14
  /**
11
15
  * The separable bilateral blur pass. @see buildVolumetricLightingBlurShader.
12
16
  */
@@ -16,6 +20,6 @@ export declare function buildVolumetricLightingBlurShaderWGSL(): string;
16
20
  */
17
21
  export declare function buildVolumetricLightingComposeShaderWGSL(): string;
18
22
  /**
19
- * Returns the four WGSL sources of the pipeline, keyed by the name they are registered under.
23
+ * Returns the WGSL sources of the passes of the pipeline, keyed by the name they are registered under.
20
24
  */
21
25
  export declare function getVolumetricLightingShadersWGSL(): Record<string, string>;
@@ -7,6 +7,10 @@ export declare const volumetricLightingLinearDepthShaderName = "volumetricLighti
7
7
  * Defines the name of the raymarching shader in the shader store of Babylon.js.
8
8
  */
9
9
  export declare const volumetricLightingScatteringShaderName = "volumetricLightingScattering";
10
+ /**
11
+ * Defines the name of the temporal accumulation shader in the shader store of Babylon.js.
12
+ */
13
+ export declare const volumetricLightingTemporalShaderName = "volumetricLightingTemporal";
10
14
  /**
11
15
  * Defines the name of the bilateral blur shader in the shader store of Babylon.js.
12
16
  */
@@ -19,8 +23,8 @@ export declare const volumetricLightingComposeShaderName = "volumetricLightingCo
19
23
  * The linear depth pass. It is the first pass of the pipeline, so its input is the untouched color of the
20
24
  * scene that the composition reads back, and it writes the distance along the view axis of each pixel.
21
25
  *
22
- * Every later pass reads this texture instead of the depth map of the depth source: a single 32 bits
23
- * channel is half the memory traffic of the 16 bits RGBA depth map, which matters for the thousands of reads
26
+ * Every later pass reads this texture instead of the depth map of the depth source: a single 16 bits
27
+ * channel is a fraction of the memory traffic of the RGBA depth map, which matters for the thousands of reads
24
28
  * of the depth-buffer occlusion, and it needs neither unpacking nor linearization. It is kept at the full
25
29
  * resolution so the occlusion sees the geometry exactly as the surfaces of the scene draw it.
26
30
  */
@@ -39,6 +43,16 @@ export declare function buildVolumetricLightingLinearDepthShader(): string;
39
43
  * @param shadowSlotCount defines the number of shadowed light slots the shader is generated for.
40
44
  */
41
45
  export declare function buildVolumetricLightingScatteringShader(shadowSlotCount: number): string;
46
+ /**
47
+ * The temporal accumulation pass. Blends the scattering of the current frame, whose samples are offset from one
48
+ * frame to the next, with the scattering accumulated over the previous frames: the result converges to the
49
+ * integral the samples of all these frames estimate together, which is what lets each frame compute fewer of them.
50
+ *
51
+ * The history is reprojected on the current view, and clipped to the range of values the current frame shows
52
+ * around the pixel so that a moving light, a moving occluder or a surface revealed by the motion of the camera
53
+ * never leaves a trail. The blend follows the "factor" of the TAA rendering pipeline: the weight of the current frame.
54
+ */
55
+ export declare function buildVolumetricLightingTemporalShader(): string;
42
56
  /**
43
57
  * The separable bilateral blur pass. Denoises the low resolution scattering buffer without letting the
44
58
  * light shafts bleed across the silhouettes of the geometry.
@@ -21,6 +21,12 @@ export declare const maxVolumetricArrayLights = 256;
21
21
  * point and spot lights, a directional light lights the whole view ray, so each one costs a full march.
22
22
  */
23
23
  export declare const maxVolumetricDirectionalLights = 4;
24
+ /**
25
+ * Defines by how much the temporal accumulation divides the number of samples the raymarching computes each
26
+ * frame. The samples of consecutive frames are offset from each other, so the accumulated result still
27
+ * averages at least as many positions along each view ray as the configured steps.
28
+ */
29
+ export declare const volumetricTemporalSamplesDivider = 3;
24
30
  /**
25
31
  * Defines the available step distributions used while raymarching the participating medium.
26
32
  */
@@ -168,16 +174,34 @@ export interface IVolumetricLightingConfiguration {
168
174
  stepDistribution: VolumetricStepDistribution;
169
175
  /**
170
176
  * Defines the dithering mode used to hide the banding produced by a low step count. @see VolumetricDitherMode
177
+ * With the temporal accumulation, "None" falls back on the interleaved gradient noise: the accumulation needs
178
+ * the samples of neighboring pixels to differ to tell the noise from the changes of the scene.
171
179
  */
172
180
  ditherMode: VolumetricDitherMode;
173
181
  /**
174
- * Defines the strength of the dithering applied to the starting offset of the rays.
182
+ * Defines the strength of the dithering applied to the starting offset of the rays. Not used by the temporal
183
+ * accumulation, which always spreads the samples over their whole segment.
175
184
  */
176
185
  ditherStrength: number;
177
186
  /**
178
187
  * Defines wether or not the dithering pattern is animated over time. Requires temporal anti-aliasing to converge.
188
+ * Not used by the temporal accumulation, which animates the samples on its own.
179
189
  */
180
190
  temporalJitter: boolean;
191
+ /**
192
+ * Defines wether or not the light shafts are accumulated over the frames. Each frame only computes a fraction
193
+ * of the samples of the raymarching, offset from one frame to the next, and blends them with the result of the
194
+ * previous frames reprojected on the current view: the result converges to the quality of the configured
195
+ * steps, or better, for a fraction of their cost. @see volumetricTemporalSamplesDivider
196
+ */
197
+ temporalAccumulation: boolean;
198
+ /**
199
+ * Defines the weight of the current frame when it is blended with the accumulated previous frames, like the
200
+ * "factor" of the TAA rendering pipeline. Lower values average more frames, which gives smoother light shafts,
201
+ * but make them slower to follow the changes of the scene. The current frame weighs more than this while the
202
+ * camera moves quickly compared to the distance of what it looks at, so the light shafts never lag behind it.
203
+ */
204
+ temporalAccumulationFactor: number;
181
205
  /**
182
206
  * Defines how the density of the medium evolves with the distance to the camera. @see VolumetricFogMode
183
207
  */
@@ -330,6 +354,27 @@ export declare function getDefaultVolumetricLightingConfiguration(): IVolumetric
330
354
  * @param configuration defines the configuration of the pipeline.
331
355
  */
332
356
  export declare function getVolumetricLightSteps(configuration: IVolumetricLightingConfiguration): number;
357
+ /**
358
+ * Defines the number of samples the raymarching computes for each pixel during a single frame.
359
+ */
360
+ export interface IVolumetricSamplingSteps {
361
+ /**
362
+ * Defines the number of steps of the march of the directional lights, and the minimum density of samples
363
+ * along the view ray for the point and spot lights.
364
+ */
365
+ steps: number;
366
+ /**
367
+ * Defines the number of samples taken across the volume of each point and spot light.
368
+ */
369
+ lightSteps: number;
370
+ }
371
+ /**
372
+ * Returns the number of samples the raymarching computes each frame. With the temporal accumulation the
373
+ * configured values are divided, the history of the previous frames providing the samples each frame skips.
374
+ * @param configuration defines the configuration of the pipeline.
375
+ * @param temporalSamplesDivider defines by how much the temporal accumulation divides the number of samples.
376
+ */
377
+ export declare function getVolumetricSamplingSteps(configuration: IVolumetricLightingConfiguration, temporalSamplesDivider?: number): IVolumetricSamplingSteps;
333
378
  /**
334
379
  * Normalizes the given serialized per-light volumetric configuration by merging it over the default one.
335
380
  * This is what makes projects saved by an older version of the editor load without any migration step.
@@ -1,7 +1,7 @@
1
1
  import { Scene } from "@babylonjs/core/scene";
2
2
  import { Camera } from "@babylonjs/core/Cameras/camera";
3
- import { VolumetricLightingRenderingPipeline } from "./volumetric/pipeline";
4
3
  import { IRenderingOptions } from "./tools";
4
+ import { VolumetricLightingRenderingPipeline } from "./volumetric/pipeline";
5
5
  export declare function getVolumetricLightingRenderingPipelineConfiguration(): any;
6
6
  export declare function setVolumetricLightingRenderingPipelineConfiguration(config: any): void;
7
7
  export declare function getVolumetricLightingRenderingPipeline(): VolumetricLightingRenderingPipeline | null;
@@ -1,4 +1,5 @@
1
1
  import { Scene } from "@babylonjs/core/scene";
2
+ import { AssetContainer } from "@babylonjs/core/assetContainer";
2
3
  /**
3
4
  * Returns the node with the given name in the given scene.
4
5
  * This method also retrieves light nodes from clustered light containers.
@@ -6,7 +7,7 @@ import { Scene } from "@babylonjs/core/scene";
6
7
  * @param scene defines the reference to the scene to search the node in.
7
8
  * @returns the node if found, otherwise null.
8
9
  */
9
- export declare function getNodeByName(name: string, scene: Scene): import("@babylonjs/core").Node | null;
10
+ export declare function getNodeByName(name: string, scene: Scene, container?: AssetContainer | null): import("@babylonjs/core").Node | null;
10
11
  /**
11
12
  * Returns the node with the given id in the given scene.
12
13
  * This method also retrieves light nodes from clustered light containers.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babylonjs-editor-tools",
3
- "version": "5.5.1",
3
+ "version": "5.5.2",
4
4
  "description": "Babylon.js Editor Tools is a set of tools to help you create, edit and manage your Babylon.js scenes made using the Babylon.js Editor",
5
5
  "productName": "Babylon.js Editor Tools",
6
6
  "scripts": {