rhodonite 0.21.0 → 0.22.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/VERSION-FILE +1 -1
- package/dist/esm/foundation/components/Camera/CameraComponent.d.ts +15 -0
- package/dist/esm/foundation/components/Light/LightComponent.d.ts +109 -4
- package/dist/esm/foundation/core/Config.d.ts +165 -3
- package/dist/esm/foundation/helpers/Shadow/PointShadowMap.d.ts +3 -1
- package/dist/esm/foundation/helpers/Shadow/ShadowSystem.d.ts +13 -0
- package/dist/esm/foundation/renderer/index.d.ts +1 -0
- package/dist/esm/foundation/renderer/lightCluster/LightClusterBuilder.d.ts +97 -0
- package/dist/esm/foundation/renderer/lightCluster/LightClusterLayout.d.ts +98 -0
- package/dist/esm/foundation/renderer/lightCluster/LightClusterSystem.d.ts +171 -0
- package/dist/esm/foundation/renderer/lightCluster/index.d.ts +1 -0
- package/dist/esm/foundation/system/Engine.d.ts +7 -0
- package/dist/esm/foundation/textures/TextureArray.d.ts +1 -1
- package/dist/esm/index.js +1096 -616
- package/dist/esm/webgl/WebGLStrategyWebGL2.d.ts +16 -0
- package/dist/esm/webgpu/WebGpuLightClusterBuilder.d.ts +34 -0
- package/dist/esm/webgpu/WebGpuResourceRepository.d.ts +28 -3
- package/dist/esm/webgpu/WebGpuStrategyBasic.d.ts +18 -1
- package/dist/esmdev/foundation/components/Camera/CameraComponent.d.ts +15 -0
- package/dist/esmdev/foundation/components/Light/LightComponent.d.ts +109 -4
- package/dist/esmdev/foundation/core/Config.d.ts +165 -3
- package/dist/esmdev/foundation/helpers/Shadow/PointShadowMap.d.ts +3 -1
- package/dist/esmdev/foundation/helpers/Shadow/ShadowSystem.d.ts +13 -0
- package/dist/esmdev/foundation/renderer/index.d.ts +1 -0
- package/dist/esmdev/foundation/renderer/lightCluster/LightClusterBuilder.d.ts +97 -0
- package/dist/esmdev/foundation/renderer/lightCluster/LightClusterLayout.d.ts +98 -0
- package/dist/esmdev/foundation/renderer/lightCluster/LightClusterSystem.d.ts +171 -0
- package/dist/esmdev/foundation/renderer/lightCluster/index.d.ts +1 -0
- package/dist/esmdev/foundation/system/Engine.d.ts +7 -0
- package/dist/esmdev/foundation/textures/TextureArray.d.ts +1 -1
- package/dist/esmdev/index.js +2141 -144
- package/dist/esmdev/webgl/WebGLStrategyWebGL2.d.ts +16 -0
- package/dist/esmdev/webgpu/WebGpuLightClusterBuilder.d.ts +34 -0
- package/dist/esmdev/webgpu/WebGpuResourceRepository.d.ts +28 -3
- package/dist/esmdev/webgpu/WebGpuStrategyBasic.d.ts +18 -1
- package/package.json +1 -1
|
@@ -56,6 +56,8 @@ export declare class WebGLStrategyWebGL2 implements CGAPIStrategy, WebGLStrategy
|
|
|
56
56
|
private __lastBlendShapeComponentsUpdateCountForWeights;
|
|
57
57
|
private __lastMorphMaxIndex;
|
|
58
58
|
private __lastMaterialsUpdateCount;
|
|
59
|
+
private __lastLightClusterDataVersion;
|
|
60
|
+
private __lastLightComponentsUpdateCount;
|
|
59
61
|
private __lastTotalSizeOfGPUShaderDataStorageExceptMorphData;
|
|
60
62
|
private __lastTransformComponentsUpdateCount;
|
|
61
63
|
private __lastSceneGraphComponentsUpdateCount;
|
|
@@ -232,6 +234,15 @@ export declare class WebGLStrategyWebGL2 implements CGAPIStrategy, WebGLStrategy
|
|
|
232
234
|
* - Manages texture alignment and padding requirements
|
|
233
235
|
*/
|
|
234
236
|
private __createAndUpdateDataTextureInner;
|
|
237
|
+
/**
|
|
238
|
+
* Uploads the bytes `[start, end)` of the GPU instance data (16-byte aligned, in the concatenated layers) to the
|
|
239
|
+
* data texture, where texel `n` holds bytes `16n` to `16n + 15`. The range is split into a partial first row, full
|
|
240
|
+
* rows and a partial last row.
|
|
241
|
+
*
|
|
242
|
+
* @param layerArray - The whole memory of the layer that contains the range
|
|
243
|
+
* @param layerByteOffset - The byte offset of the layer in the concatenated layers
|
|
244
|
+
*/
|
|
245
|
+
private __uploadDataTextureTexels;
|
|
235
246
|
/**
|
|
236
247
|
* Deletes the current data texture and frees associated GPU resources.
|
|
237
248
|
* This method should be called when the data texture needs to be recreated
|
|
@@ -483,6 +494,11 @@ export declare class WebGLStrategyWebGL2 implements CGAPIStrategy, WebGLStrategy
|
|
|
483
494
|
* same program by the previous upload. Uniform values persist in the program object, so
|
|
484
495
|
* consecutive draws of the same material (e.g. a shadow pass) do not need to upload again.
|
|
485
496
|
*/
|
|
497
|
+
/**
|
|
498
|
+
* Uploads the light cluster view of the camera of the draw (`u_lightClusterView`) when the program uses it and
|
|
499
|
+
* the camera or the light cluster data changed since the last upload to the program.
|
|
500
|
+
*/
|
|
501
|
+
private __uploadLightClusterView;
|
|
486
502
|
private __uploadCurrentComponentSIDs;
|
|
487
503
|
/**
|
|
488
504
|
* Binds the data texture to the WebGL context for shader access.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { LightClusterGpuBuildParams } from '../foundation/renderer/lightCluster/LightClusterSystem';
|
|
2
|
+
/**
|
|
3
|
+
* Builds the light cluster tables of Clustered Forward rendering with compute shaders.
|
|
4
|
+
* The tables are written into the storage buffer of the GPU instance data, where the CPU build would write them.
|
|
5
|
+
*
|
|
6
|
+
* The sorted light input of the views (spheres, entries and Z slice ranges) is uploaded to a separate storage buffer,
|
|
7
|
+
* because it is small (some tens of KiB) and reused for all views.
|
|
8
|
+
*/
|
|
9
|
+
export declare class WebGpuLightClusterBuilder {
|
|
10
|
+
private __device;
|
|
11
|
+
private __bindGroupLayout;
|
|
12
|
+
private __pipeline;
|
|
13
|
+
private __paramsBuffer?;
|
|
14
|
+
private __paramsStride;
|
|
15
|
+
private __paramsCapacity;
|
|
16
|
+
private __paramsArray;
|
|
17
|
+
private __buildDataBuffer?;
|
|
18
|
+
private __buildDataCapacity;
|
|
19
|
+
private __bindGroup?;
|
|
20
|
+
private __bindGroupStorageBuffer?;
|
|
21
|
+
constructor(device: GPUDevice);
|
|
22
|
+
/**
|
|
23
|
+
* Builds the clusters of the views and submits the work immediately, so that it runs after the upload of the
|
|
24
|
+
* GPU instance data (queue.writeBuffer) and before the render commands of the frame.
|
|
25
|
+
*
|
|
26
|
+
* @param storageBuffer - The storage buffer of the GPU instance data
|
|
27
|
+
* @param params - The views to build and their sorted light input
|
|
28
|
+
*/
|
|
29
|
+
build(storageBuffer: GPUBuffer, params: LightClusterGpuBuildParams): void;
|
|
30
|
+
/**
|
|
31
|
+
* Releases the GPU resources.
|
|
32
|
+
*/
|
|
33
|
+
destroy(): void;
|
|
34
|
+
}
|
|
@@ -92,6 +92,8 @@ export declare class WebGpuResourceRepository extends CGAPIResourceRepository im
|
|
|
92
92
|
/** Cached `gpuDevice.queue` ([SameObject]), read on every frame by flush(). */
|
|
93
93
|
private __gpuQueue?;
|
|
94
94
|
private __renderBundles;
|
|
95
|
+
/** Fragment module of the depth prepass pipelines (it writes nothing; the color targets use writeMask 0). */
|
|
96
|
+
private __depthOnlyFragmentModule?;
|
|
95
97
|
private __renderBundleEncoder?;
|
|
96
98
|
private __renderBundleEncoderKey?;
|
|
97
99
|
private __systemDepthTexture?;
|
|
@@ -476,8 +478,13 @@ export declare class WebGpuResourceRepository extends CGAPIResourceRepository im
|
|
|
476
478
|
* @param renderPass - The render pass defining render targets and clear operations
|
|
477
479
|
* @param cameraId - Identifier for the camera used for rendering
|
|
478
480
|
* @param zWrite - Whether to enable depth writing during rendering
|
|
481
|
+
* @param options - `depthOnly` draws the primitive with a depth-only pipeline (the depth prepass);
|
|
482
|
+
* `allowEqualDepth` lets the color pass pass the depth written by the prepass
|
|
479
483
|
*/
|
|
480
|
-
draw(engine: Engine, primitive: Primitive, material: Material, renderPass: RenderPass, cameraId: number, zWrite: boolean, _displayIdx: number
|
|
484
|
+
draw(engine: Engine, primitive: Primitive, material: Material, renderPass: RenderPass, cameraId: number, zWrite: boolean, _displayIdx: number, options?: {
|
|
485
|
+
depthOnly?: boolean;
|
|
486
|
+
allowEqualDepth?: boolean;
|
|
487
|
+
}): void;
|
|
481
488
|
/**
|
|
482
489
|
* Creates a render bundle encoder for efficient rendering.
|
|
483
490
|
* Render bundles allow pre-recording of rendering commands for better performance.
|
|
@@ -575,7 +582,11 @@ export declare class WebGpuResourceRepository extends CGAPIResourceRepository im
|
|
|
575
582
|
finishRenderBundleEncoderAndKeepRenderPass(engine: Engine, renderPass: RenderPass, displayIdx: number): GPURenderPassEncoder | undefined;
|
|
576
583
|
getOrCreateRenderPassEncoderForExternalRendering(engine: Engine, renderPass: RenderPass, displayIdx: number): GPURenderPassEncoder | undefined;
|
|
577
584
|
endRenderPassEncoderForExternalRendering(): void;
|
|
578
|
-
|
|
585
|
+
private __getDepthOnlyFragmentModule;
|
|
586
|
+
getOrCreateRenderPipeline(renderPipelineId: string, pipelineLayoutKey: string, pipelineLayout: GPUPipelineLayout, primitive: Primitive, material: Material, renderPass: RenderPass, zWrite: boolean, options?: {
|
|
587
|
+
depthOnly?: boolean;
|
|
588
|
+
allowEqualDepth?: boolean;
|
|
589
|
+
}): [GPURenderPipeline, boolean];
|
|
579
590
|
/**
|
|
580
591
|
* Submits all recorded commands to the GPU queue and resets the command encoder.
|
|
581
592
|
* This method must be called to execute any recorded rendering commands.
|
|
@@ -633,7 +644,21 @@ export declare class WebGpuResourceRepository extends CGAPIResourceRepository im
|
|
|
633
644
|
* @param storageBufferHandle - Handle to the storage buffer to update
|
|
634
645
|
* @param gpuInstanceDataBuffers - New data to write to the buffer
|
|
635
646
|
*/
|
|
636
|
-
updateStorageBuffer(storageBufferHandle: WebGPUResourceHandle, gpuInstanceDataBuffers: Buffer[]): void;
|
|
647
|
+
updateStorageBuffer(storageBufferHandle: WebGPUResourceHandle, gpuInstanceDataBuffers: Buffer[], excludedByteRanges?: readonly [number, number][]): void;
|
|
648
|
+
/**
|
|
649
|
+
* Writes byte ranges of the GPU instance data to the storage buffer.
|
|
650
|
+
*
|
|
651
|
+
* @param storageBufferHandle - Handle to the storage buffer
|
|
652
|
+
* @param gpuInstanceDataBuffers - The GPU instance data buffers (layers)
|
|
653
|
+
* @param byteRanges - The ranges `[start, end)` in the concatenated layers. A range must not span layers.
|
|
654
|
+
*/
|
|
655
|
+
updateStorageBufferRanges(storageBufferHandle: WebGPUResourceHandle, gpuInstanceDataBuffers: Buffer[], byteRanges: readonly [number, number][]): void;
|
|
656
|
+
/**
|
|
657
|
+
* The storage buffer of the GPU instance data (bound at group 0, binding 0 of the render pipelines).
|
|
658
|
+
*
|
|
659
|
+
* @internal
|
|
660
|
+
*/
|
|
661
|
+
_getStorageBuffer(): GPUBuffer | undefined;
|
|
637
662
|
destroyStorageBuffer(storageBufferHandle: WebGPUResourceHandle): void;
|
|
638
663
|
/**
|
|
639
664
|
* Updates a portion of a storage buffer with new data at a specific offset.
|
|
@@ -32,6 +32,10 @@ export declare class WebGpuStrategyBasic implements CGAPIStrategy {
|
|
|
32
32
|
private __uniformMorphOffsetsTypedArray?;
|
|
33
33
|
private __uniformMorphWeightsTypedArray?;
|
|
34
34
|
private __lastMaterialsUpdateCount;
|
|
35
|
+
private __lastLightClusterDataVersion;
|
|
36
|
+
private __lastLightComponentsUpdateCount;
|
|
37
|
+
private __lightClusterBuilder?;
|
|
38
|
+
private __lastLightClusterBuildDataVersion;
|
|
35
39
|
private __lastTransformComponentsUpdateCount;
|
|
36
40
|
private __lastSceneGraphComponentsUpdateCount;
|
|
37
41
|
private __lastCameraComponentsUpdateCount;
|
|
@@ -157,6 +161,11 @@ export declare class WebGpuStrategyBasic implements CGAPIStrategy {
|
|
|
157
161
|
* @param renderPass - The render pass containing the material and rendering configuration
|
|
158
162
|
*/
|
|
159
163
|
private __renderWithoutBuffers;
|
|
164
|
+
/**
|
|
165
|
+
* Whether the depth prepass can run for the render pass: it must be enabled, draw the scene itself (render passes
|
|
166
|
+
* with a material override such as shadow maps and post effects are excluded), and write depth.
|
|
167
|
+
*/
|
|
168
|
+
private __isDepthPrepassAvailable;
|
|
160
169
|
/**
|
|
161
170
|
* Renders a single primitive with the specified material and render settings.
|
|
162
171
|
* Handles shader setup, uniform buffer updates, and the actual draw call.
|
|
@@ -167,13 +176,21 @@ export declare class WebGpuStrategyBasic implements CGAPIStrategy {
|
|
|
167
176
|
* @param displayIdx - The index of the display to render to
|
|
168
177
|
* @returns True if the primitive was successfully rendered
|
|
169
178
|
*/
|
|
170
|
-
renderInner(primitiveUid: PrimitiveUID, renderPass: RenderPass, zWrite: boolean, displayIdx: Index
|
|
179
|
+
renderInner(primitiveUid: PrimitiveUID, renderPass: RenderPass, zWrite: boolean, displayIdx: Index, options?: {
|
|
180
|
+
depthOnly?: boolean;
|
|
181
|
+
allowEqualDepth?: boolean;
|
|
182
|
+
}): boolean;
|
|
171
183
|
/**
|
|
172
184
|
* Creates or updates the main storage buffer containing all GPU instance data.
|
|
173
185
|
* This buffer holds transform matrices, material properties, and other per-instance data
|
|
174
186
|
* required for rendering all objects in the scene.
|
|
175
187
|
*/
|
|
176
188
|
private __createAndUpdateStorageBuffer;
|
|
189
|
+
/**
|
|
190
|
+
* Builds the Clustered Forward light cluster tables with compute shaders when the LightClusterSystem
|
|
191
|
+
* builds them on the GPU. It must run after every upload of the GPU instance data, which overwrites the tables.
|
|
192
|
+
*/
|
|
193
|
+
private __buildLightClustersOnGpu;
|
|
177
194
|
/**
|
|
178
195
|
* Creates or updates the storage buffer containing blend shape vertex data.
|
|
179
196
|
* This buffer holds morph target positions and other vertex attributes needed for blend shape animation.
|
|
@@ -8,6 +8,7 @@ import type { ICameraEntity } from '../../helpers/EntityHelper';
|
|
|
8
8
|
import { Matrix44 } from '../../math/Matrix44';
|
|
9
9
|
import { MutableMatrix44 } from '../../math/MutableMatrix44';
|
|
10
10
|
import { MutableVector3 } from '../../math/MutableVector3';
|
|
11
|
+
import { MutableVector4 } from '../../math/MutableVector4';
|
|
11
12
|
import { Vector3 } from '../../math/Vector3';
|
|
12
13
|
import { Vector4 } from '../../math/Vector4';
|
|
13
14
|
import type { Engine } from '../../system/Engine';
|
|
@@ -39,6 +40,7 @@ export declare class CameraComponent extends Component {
|
|
|
39
40
|
private _projectionMatrix;
|
|
40
41
|
private _viewMatrix;
|
|
41
42
|
private _viewPosition;
|
|
43
|
+
private _lightClusterViewInfo;
|
|
42
44
|
private static __currentMap;
|
|
43
45
|
private static returnVector3;
|
|
44
46
|
private static __tmpVector3_0;
|
|
@@ -486,6 +488,19 @@ export declare class CameraComponent extends Component {
|
|
|
486
488
|
* @param projectionMatrix - The projection matrix to set
|
|
487
489
|
*/
|
|
488
490
|
set projectionMatrix(projectionMatrix: Matrix44);
|
|
491
|
+
/**
|
|
492
|
+
* The projection matrix that is uploaded to the GPU (in XR mode, the matrix of the eye copied in $logic).
|
|
493
|
+
*
|
|
494
|
+
* @internal
|
|
495
|
+
*/
|
|
496
|
+
get _projectionMatrixForGpu(): Matrix44;
|
|
497
|
+
/**
|
|
498
|
+
* The light cluster view info uploaded to the GPU.
|
|
499
|
+
* x: the vec4 index of the light cluster view region of this camera (-1: none).
|
|
500
|
+
*
|
|
501
|
+
* @internal
|
|
502
|
+
*/
|
|
503
|
+
get _lightClusterViewInfoForGpu(): MutableVector4;
|
|
489
504
|
/**
|
|
490
505
|
* Gets the combined view-projection matrix.
|
|
491
506
|
*
|
|
@@ -2,7 +2,9 @@ import type { ComponentSID, ComponentTID, EntityUID } from '../../../types/Commo
|
|
|
2
2
|
import { Component } from '../../core/Component';
|
|
3
3
|
import type { IEntity } from '../../core/Entity';
|
|
4
4
|
import { type EntityRepository } from '../../core/EntityRepository';
|
|
5
|
+
import { type LightTypeEnum } from '../../definitions/LightType';
|
|
5
6
|
import type { ILightEntity } from '../../helpers/EntityHelper';
|
|
7
|
+
import { MutableVector4 } from '../../math/MutableVector4';
|
|
6
8
|
import { Vector3 } from '../../math/Vector3';
|
|
7
9
|
import type { Engine } from '../../system/Engine';
|
|
8
10
|
import type { ComponentToComponentMethods } from '../ComponentTypes';
|
|
@@ -13,15 +15,17 @@ import type { ComponentToComponentMethods } from '../ComponentTypes';
|
|
|
13
15
|
* the light looks towards the local -Z axis in right hand coordinate system.
|
|
14
16
|
*/
|
|
15
17
|
export declare class LightComponent extends Component {
|
|
16
|
-
|
|
18
|
+
private __type;
|
|
17
19
|
private __color;
|
|
20
|
+
/** The components of the color at the last change, to detect changes of a mutated color object. */
|
|
21
|
+
private __lastColor;
|
|
18
22
|
private __intensity;
|
|
19
23
|
private readonly __initialDirection;
|
|
20
24
|
private __direction;
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
private __innerConeAngle;
|
|
26
|
+
private __outerConeAngle;
|
|
23
27
|
private __range;
|
|
24
|
-
|
|
28
|
+
private __enable;
|
|
25
29
|
private __shadowAreaSizeForDirectionalLight;
|
|
26
30
|
private __shadowZNearForDirectionalLight;
|
|
27
31
|
private __shadowCameraOffsetForDirectionalLight;
|
|
@@ -32,9 +36,13 @@ export declare class LightComponent extends Component {
|
|
|
32
36
|
private _lightProperty;
|
|
33
37
|
private static __lightNumber;
|
|
34
38
|
private __lightGizmo?;
|
|
39
|
+
/** The shadow slot assigned by a ShadowSystem. `undefined` means the default slot (see `_shadowSlot`). */
|
|
40
|
+
private __shadowSlot;
|
|
35
41
|
private __updateCount;
|
|
36
42
|
private __lastUpdateCount;
|
|
37
43
|
private __lastTransformUpdateCount;
|
|
44
|
+
/** The number of changes of all light components, per engine. */
|
|
45
|
+
private static __updateCountMap;
|
|
38
46
|
/**
|
|
39
47
|
* Creates a new LightComponent instance.
|
|
40
48
|
*
|
|
@@ -45,6 +53,56 @@ export declare class LightComponent extends Component {
|
|
|
45
53
|
* @param isReUse - Whether this component is being reused from a pool
|
|
46
54
|
*/
|
|
47
55
|
constructor(engine: Engine, entityUid: EntityUID, componentSid: ComponentSID, entityRepository: EntityRepository, isReUse: boolean);
|
|
56
|
+
/**
|
|
57
|
+
* Gets the number of changes of all light components of the engine (creation, destruction and property changes).
|
|
58
|
+
* The engine and the rendering strategies use it to process and upload the light data only when it changed.
|
|
59
|
+
*
|
|
60
|
+
* @param engine - The engine instance
|
|
61
|
+
* @returns The update count
|
|
62
|
+
*/
|
|
63
|
+
static getUpdateCount(engine: Engine): number;
|
|
64
|
+
private static __incrementUpdateCount;
|
|
65
|
+
/**
|
|
66
|
+
* Cleans up the static data of the engine.
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
static _cleanupForEngine(engine: Engine): void;
|
|
70
|
+
/**
|
|
71
|
+
* Records a change of a property, so that the light data is recomputed and uploaded.
|
|
72
|
+
*/
|
|
73
|
+
private __markUpdated;
|
|
74
|
+
/**
|
|
75
|
+
* Gets the type of the light.
|
|
76
|
+
*/
|
|
77
|
+
get type(): LightTypeEnum;
|
|
78
|
+
/**
|
|
79
|
+
* Sets the type of the light.
|
|
80
|
+
*/
|
|
81
|
+
set type(value: LightTypeEnum);
|
|
82
|
+
/**
|
|
83
|
+
* Gets whether the light is enabled.
|
|
84
|
+
*/
|
|
85
|
+
get enable(): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Sets whether the light is enabled. A disabled light does not light anything.
|
|
88
|
+
*/
|
|
89
|
+
set enable(value: boolean);
|
|
90
|
+
/**
|
|
91
|
+
* Gets the inner cone angle of the spot light (in radian).
|
|
92
|
+
*/
|
|
93
|
+
get innerConeAngle(): number;
|
|
94
|
+
/**
|
|
95
|
+
* Sets the inner cone angle of the spot light (in radian).
|
|
96
|
+
*/
|
|
97
|
+
set innerConeAngle(value: number);
|
|
98
|
+
/**
|
|
99
|
+
* Gets the outer cone angle of the spot light (in radian).
|
|
100
|
+
*/
|
|
101
|
+
get outerConeAngle(): number;
|
|
102
|
+
/**
|
|
103
|
+
* Sets the outer cone angle of the spot light (in radian).
|
|
104
|
+
*/
|
|
105
|
+
set outerConeAngle(value: number);
|
|
48
106
|
/**
|
|
49
107
|
* Gets the component type identifier for LightComponent.
|
|
50
108
|
*
|
|
@@ -144,6 +202,48 @@ export declare class LightComponent extends Component {
|
|
|
144
202
|
* @returns The RGB color vector
|
|
145
203
|
*/
|
|
146
204
|
get color(): Vector3;
|
|
205
|
+
/**
|
|
206
|
+
* The index of the shadow data of this light in the per-material shadow arrays
|
|
207
|
+
* (`depthTextureIndexList` and `depthBiasPV`), or -1 when the light has no shadow data.
|
|
208
|
+
*
|
|
209
|
+
* @remarks
|
|
210
|
+
* A ShadowSystem assigns the slots of the lights it manages. Otherwise the slot is the component SID
|
|
211
|
+
* when it is below `Config.maxLightNumber`, which is the convention of manual shadow map setups.
|
|
212
|
+
*
|
|
213
|
+
* @internal
|
|
214
|
+
*/
|
|
215
|
+
get _shadowSlot(): number;
|
|
216
|
+
/**
|
|
217
|
+
* Sets the shadow slot of this light. `undefined` restores the default slot.
|
|
218
|
+
*
|
|
219
|
+
* @internal
|
|
220
|
+
*/
|
|
221
|
+
set _shadowSlot(slot: number | undefined);
|
|
222
|
+
/**
|
|
223
|
+
* The world position of the light as uploaded to the GPU (updated in $logic).
|
|
224
|
+
*
|
|
225
|
+
* @internal
|
|
226
|
+
*/
|
|
227
|
+
get _lightPositionForGpu(): MutableVector4;
|
|
228
|
+
/**
|
|
229
|
+
* The world direction of the light as uploaded to the GPU (updated in $logic).
|
|
230
|
+
*
|
|
231
|
+
* @internal
|
|
232
|
+
*/
|
|
233
|
+
get _lightDirectionForGpu(): MutableVector4;
|
|
234
|
+
/**
|
|
235
|
+
* The light property (type, effective range, cos of the inner and outer cone angles) as uploaded to the GPU
|
|
236
|
+
* (updated in $logic).
|
|
237
|
+
*
|
|
238
|
+
* @internal
|
|
239
|
+
*/
|
|
240
|
+
get _lightPropertyForGpu(): MutableVector4;
|
|
241
|
+
/**
|
|
242
|
+
* The intensity of the light (color * intensity) as uploaded to the GPU (updated in $logic).
|
|
243
|
+
*
|
|
244
|
+
* @internal
|
|
245
|
+
*/
|
|
246
|
+
get _lightIntensityForGpu(): MutableVector4;
|
|
147
247
|
/**
|
|
148
248
|
* Gets the up vector for the light in local space.
|
|
149
249
|
* This is used for light orientation calculations.
|
|
@@ -195,6 +295,11 @@ export declare class LightComponent extends Component {
|
|
|
195
295
|
* to avoid unnecessary recalculations when nothing has changed.
|
|
196
296
|
*/
|
|
197
297
|
$logic(): void;
|
|
298
|
+
/**
|
|
299
|
+
* Returns the range used for shading. Point and spot lights without a range get an automatic range
|
|
300
|
+
* when `Config.lightAutoRangeThreshold` is greater than 0.
|
|
301
|
+
*/
|
|
302
|
+
private __getEffectiveRange;
|
|
198
303
|
/**
|
|
199
304
|
* Cleans up the light component when it's being destroyed.
|
|
200
305
|
* Resets the light intensity values in the global data arrays.
|
|
@@ -21,7 +21,22 @@ type ConfigInitDescription = {
|
|
|
21
21
|
bufferSizeDivisionRatiosForGPUInstanceDataUsage?: number[];
|
|
22
22
|
logLevel?: LogLevel;
|
|
23
23
|
isMultiDrawEnabled?: boolean;
|
|
24
|
+
isDepthPrepassEnabled?: boolean;
|
|
25
|
+
isClusteredForwardEnabled?: boolean;
|
|
26
|
+
clusteredForwardBuildMode?: ClusteredForwardBuildMode;
|
|
27
|
+
clusteredForwardGridSize?: [number, number, number];
|
|
28
|
+
clusteredForwardMaxViewNumber?: number;
|
|
29
|
+
clusteredForwardLightCapacityPerCluster?: number;
|
|
30
|
+
clusteredForwardMinLocalLightNumber?: number;
|
|
31
|
+
maxLightListLength?: number;
|
|
32
|
+
lightAutoRangeThreshold?: number;
|
|
24
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* Where the light clusters of Clustered Forward rendering are built.
|
|
36
|
+
* - `'auto'`: WebGPU builds them with compute shaders, WebGL2 builds them on the CPU.
|
|
37
|
+
* - `'cpu'`: Both backends build them on the CPU.
|
|
38
|
+
*/
|
|
39
|
+
export type ClusteredForwardBuildMode = 'auto' | 'cpu';
|
|
25
40
|
/**
|
|
26
41
|
* Config is a configuration class that contains the configuration for the library.
|
|
27
42
|
*/
|
|
@@ -32,10 +47,133 @@ export declare class Config {
|
|
|
32
47
|
skeletalComponentCountPerBufferView: number;
|
|
33
48
|
/** The number of camera components per buffer view */
|
|
34
49
|
cameraComponentCountPerBufferView: number;
|
|
35
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* The number of light components per buffer view.
|
|
52
|
+
* Every new buffer view changes the generated shader getters and recompiles all shaders,
|
|
53
|
+
* so this is large enough for scenes with many lights.
|
|
54
|
+
*/
|
|
36
55
|
lightComponentCountPerBufferView: number;
|
|
37
|
-
/**
|
|
38
|
-
|
|
56
|
+
/**
|
|
57
|
+
* The maximum number of lights that can cast shadows at the same time.
|
|
58
|
+
* This is also the length of the per-light arrays of the MToon 0.x shader.
|
|
59
|
+
*
|
|
60
|
+
* @remarks
|
|
61
|
+
* 0 disables the per-light shadow map slots: the shaders compile out the shadow sampling and no shadow map
|
|
62
|
+
* textures are created. The shader arrays themselves cannot have a length of 0, so they use
|
|
63
|
+
* {@link Config.maxLightNumberOrOne} instead. Negative and NaN values are treated as 0.
|
|
64
|
+
*/
|
|
65
|
+
private __maxLightNumber;
|
|
66
|
+
/** See {@link Config.maxLightNumber}. */
|
|
67
|
+
get maxLightNumber(): number;
|
|
68
|
+
/** See {@link Config.maxLightNumber}. */
|
|
69
|
+
set maxLightNumber(value: number);
|
|
70
|
+
/**
|
|
71
|
+
* The length-safe value of {@link Config.maxLightNumber}: `maxLightNumber`, or 1 when it is 0.
|
|
72
|
+
*
|
|
73
|
+
* @remarks
|
|
74
|
+
* Shader arrays, material parameters and texture arrays cannot have a length of 0. The shaders use this value
|
|
75
|
+
* for their per-light array sizes and loop bounds. Shadow processing itself is controlled by
|
|
76
|
+
* {@link Config.maxLightNumber}: when it is 0, the shadow code is compiled out and no shadow slots are assigned.
|
|
77
|
+
*/
|
|
78
|
+
get maxLightNumberOrOne(): number;
|
|
79
|
+
/**
|
|
80
|
+
* Whether Clustered Forward rendering is enabled.
|
|
81
|
+
* When enabled, each fragment evaluates only the lights whose range reaches the cluster (froxel) of the fragment.
|
|
82
|
+
* Lights without a range limit and directional lights are always evaluated.
|
|
83
|
+
*/
|
|
84
|
+
isClusteredForwardEnabled: boolean;
|
|
85
|
+
/** Where the light clusters are built. See {@link ClusteredForwardBuildMode}. */
|
|
86
|
+
clusteredForwardBuildMode: ClusteredForwardBuildMode;
|
|
87
|
+
/**
|
|
88
|
+
* The number of clusters along the screen X, screen Y and view depth axes.
|
|
89
|
+
*
|
|
90
|
+
* @remarks
|
|
91
|
+
* The default puts about a 40 pixel tile on a 1920x1080 canvas. The screen tiles should stay roughly 30-40 pixels
|
|
92
|
+
* at the rendered resolution: a coarser grid lets many lights share each cluster (the cost is paid by every
|
|
93
|
+
* fragment), and a finer grid increases the per-frame cluster build cost (the cost is paid once per frame, and the
|
|
94
|
+
* build is proportional to the cluster count in the current implementation).
|
|
95
|
+
*/
|
|
96
|
+
clusteredForwardGridSize: [number, number, number];
|
|
97
|
+
/**
|
|
98
|
+
* The maximum number of cameras whose light clusters are built in one frame.
|
|
99
|
+
* The other cameras evaluate all lights.
|
|
100
|
+
*/
|
|
101
|
+
clusteredForwardMaxViewNumber: number;
|
|
102
|
+
/**
|
|
103
|
+
* The light clusters are built only when the number of lights that can be culled (point and spot lights with a
|
|
104
|
+
* range, including an automatic range of {@link Config.lightAutoRangeThreshold}) and emit light (an intensity
|
|
105
|
+
* greater than 0) is at least this value. With fewer lights, every fragment evaluates all lights as in plain forward
|
|
106
|
+
* rendering, which skips the cluster build and the cluster lookup of the fragment shaders.
|
|
107
|
+
*
|
|
108
|
+
* @remarks
|
|
109
|
+
* The default value 1 is the measured break-even point of both backends: on Apple M2 Max (Chrome, ANGLE-Metal /
|
|
110
|
+
* Dawn-Metal) with a full-screen 2048x2048 PBR surface, the GPU frame time with and without clusters was
|
|
111
|
+
* (ratio = clustered / plain forward, lower is better; a range is the spread of several runs):
|
|
112
|
+
*
|
|
113
|
+
* | Lights | WebGL2 (radius 3 / 6) | WebGPU (radius 3 / 6) |
|
|
114
|
+
* |--------|------------------------|-----------------------|
|
|
115
|
+
* | 1 | 0.90-0.92 / 0.82-1.09 | 0.83 / 0.92 |
|
|
116
|
+
* | 2 | 0.64 / 0.76-0.84 | 0.61 / 0.76 |
|
|
117
|
+
* | 3 | 0.62 / 0.72 | 0.49 / 0.66 |
|
|
118
|
+
* | 8 | 0.42 / 0.62 | 0.32 / 0.51 |
|
|
119
|
+
*
|
|
120
|
+
* (A light with the radius 3 or 6 covers about 7% or 28% of the screen.) The cluster lookup costs about half a
|
|
121
|
+
* light in both backends. The Classic shader and a moving camera (clusters rebuilt every frame) gave the same
|
|
122
|
+
* break-even points. Lights that cover the whole screen can not be culled, so clustering them is always a few
|
|
123
|
+
* percent slower (WebGL2 2-3%, WebGPU 1-11%) whatever this value is. Raise this value for such scenes.
|
|
124
|
+
* Other GPUs may differ.
|
|
125
|
+
*/
|
|
126
|
+
clusteredForwardMinLocalLightNumber: number;
|
|
127
|
+
/**
|
|
128
|
+
* The maximum number of lights in the list of each cluster.
|
|
129
|
+
*
|
|
130
|
+
* @remarks
|
|
131
|
+
* Every cluster keeps at most this many lights. When the number of local lights is greater than this value, the
|
|
132
|
+
* lights are sorted by their view depth and each cluster keeps the nearest ones, so the lights that are dropped
|
|
133
|
+
* are the farthest ones. The cost of a fragment is bounded by this value.
|
|
134
|
+
*
|
|
135
|
+
* Memory per camera: about `16 * clusterCount * ceil(value / 4)` bytes, where clusterCount is the product of
|
|
136
|
+
* {@link Config.clusteredForwardGridSize} (62,208 by default). The default 96 is about 25 MB per camera.
|
|
137
|
+
*/
|
|
138
|
+
clusteredForwardLightCapacityPerCluster: number;
|
|
139
|
+
/** The maximum number of enabled lights that are shaded. The other lights are ignored. (max: 65535) */
|
|
140
|
+
maxLightListLength: number;
|
|
141
|
+
/**
|
|
142
|
+
* When greater than 0, point and spot lights without a range get an effective range where their intensity
|
|
143
|
+
* (the maximum of color * intensity, divided by the squared distance) falls to this value.
|
|
144
|
+
* This makes those lights fade out smoothly at that distance and lets Clustered Forward rendering cull them.
|
|
145
|
+
* 0 (default) disables it. Lights with a range and directional lights are not affected.
|
|
146
|
+
*
|
|
147
|
+
* @remarks
|
|
148
|
+
* The effective range is `R = sqrt(max(color) * intensity / lightAutoRangeThreshold)`. With the range window
|
|
149
|
+
* of the shaders (`(1 - (d / R)^4) / d^2`), the difference from the unlimited inverse-square falloff at the
|
|
150
|
+
* distance `d` is `lightAutoRangeThreshold * (d / R)^2`. So this value is the upper bound of the error added to
|
|
151
|
+
* the linear brightness (for the diffuse lighting of a white surface facing the light). The error is largest at
|
|
152
|
+
* the border of the range and smaller inside it.
|
|
153
|
+
*
|
|
154
|
+
* Reference values (without tone mapping, exposure 1):
|
|
155
|
+
*
|
|
156
|
+
* | Value | Range (intensity 1 / 10) | Effect on the image |
|
|
157
|
+
* |--------|--------------------------|---------------------|
|
|
158
|
+
* | 0.0003 | 58 / 183 | Practically lossless, but the range is so large that the lights are rarely culled. |
|
|
159
|
+
* | 0.001 | 32 / 100 | At most about 3/255 even on a black background. Not noticeable on lit surfaces. Recommended starting point. |
|
|
160
|
+
* | 0.003 | 18 / 58 | Hardly noticeable in scenes with ambient light or IBL. |
|
|
161
|
+
* | 0.01 | 10 / 32 | On a dark background, the tail of the light fades out a little early. About 3/255 on lit surfaces. |
|
|
162
|
+
*
|
|
163
|
+
* Tips:
|
|
164
|
+
* - Compare the resulting range with the visible area and the spacing of the lights. A range larger than them
|
|
165
|
+
* puts the light in almost every cluster, so it does not make rendering faster.
|
|
166
|
+
* - Scale the value with the brightness level of the scene. For example, when the light intensities are in the
|
|
167
|
+
* hundreds and the exposure brings them down, scale the value by the same factor. About 1/300 to 1/1000 of the
|
|
168
|
+
* typical brightness of the scene is a good guide.
|
|
169
|
+
* - Use a smaller value for dark scenes or when the exposure brightens dark areas, where the cut-off tail is
|
|
170
|
+
* more noticeable.
|
|
171
|
+
* - The error of specular highlights on glossy surfaces can be larger than the table above, but the light is
|
|
172
|
+
* weak near the border of the range, so it is rarely noticeable.
|
|
173
|
+
* - Set this when initializing the engine. A change at runtime takes effect for each light when the light is
|
|
174
|
+
* updated next.
|
|
175
|
+
*/
|
|
176
|
+
lightAutoRangeThreshold: number;
|
|
39
177
|
/**
|
|
40
178
|
* Number of instances of each material type to be placed consecutively in memory.
|
|
41
179
|
* This is on the memory layout, and the number of material instances that can be generated is not limited by this setting.
|
|
@@ -73,6 +211,30 @@ export declare class Config {
|
|
|
73
211
|
* vertex/index buffers and consecutive draws with the same state are issued with WEBGL_multi_draw.
|
|
74
212
|
*/
|
|
75
213
|
isMultiDrawEnabled: boolean;
|
|
214
|
+
/**
|
|
215
|
+
* Whether to render a depth prepass for the opaque primitives of the main render passes (WebGPU only).
|
|
216
|
+
*
|
|
217
|
+
* @remarks
|
|
218
|
+
* The prepass draws the opaque primitives with a depth-only pipeline before the color pass, and the color pass
|
|
219
|
+
* tests the depth with `less-equal`. Hidden fragments are rejected before the fragment shader, so the cost of the
|
|
220
|
+
* prepass (vertex processing and a trivial fragment shader) is traded for the shading of the overdrawn fragments.
|
|
221
|
+
*
|
|
222
|
+
* Primitives that alpha test (Mask), alpha-to-coverage, discard for wireframe, or blend are not part of the prepass:
|
|
223
|
+
* they keep their normal draw, depth test and depth write. A material that discards in another way should not be
|
|
224
|
+
* used with this option. At exactly coplanar surfaces the visible surface can change, because the color pass passes
|
|
225
|
+
* fragments whose depth is equal to the prepass depth (a few hundred pixels on a Sponza-scale scene).
|
|
226
|
+
*
|
|
227
|
+
* Render passes with a material override (shadow maps, post effects and other helper passes) are not affected.
|
|
228
|
+
* The prepass is per render pass, so stereo rendering runs it once per eye. The WebGL2 backend ignores this option
|
|
229
|
+
* (its multi-draw path keeps the material order).
|
|
230
|
+
*
|
|
231
|
+
* @remarks
|
|
232
|
+
* Measured on the 1000-point-light Sponza (WebGPU, Apple M2 Max): the GPU time fell by about 5-7% (1280x720:
|
|
233
|
+
* 4.46 -> 4.13 ms) and the frame wall time by about 0-10% (the run was thermally throttled, so treat the wall
|
|
234
|
+
* number as an upper bound). The gain grows with the amount of overdrawn shading. The default is off because the
|
|
235
|
+
* extra geometry pass hurts scenes with little overdraw or heavy vertex shaders.
|
|
236
|
+
*/
|
|
237
|
+
isDepthPrepassEnabled: boolean;
|
|
76
238
|
constructor(initDescription?: ConfigInitDescription);
|
|
77
239
|
}
|
|
78
240
|
export {};
|
|
@@ -26,9 +26,11 @@ export declare class PointShadowMap {
|
|
|
26
26
|
*
|
|
27
27
|
* @param entities - Array of scene graph entities to be rendered for shadow map generation
|
|
28
28
|
* @param lightEntity - The point light entity that casts shadows
|
|
29
|
+
* @param shadowSlot - The shadow slot of the light (below `Config.maxLightNumber`). Defaults to the shadow slot
|
|
30
|
+
* of the light component.
|
|
29
31
|
* @returns An array containing two render passes: [frontRenderPass, backRenderPass]
|
|
30
32
|
*/
|
|
31
|
-
getRenderPasses(entities: ISceneGraphEntity[], lightEntity: ISceneGraphEntity & ILightEntityMethods): RenderPass[];
|
|
33
|
+
getRenderPasses(entities: ISceneGraphEntity[], lightEntity: ISceneGraphEntity & ILightEntityMethods, shadowSlot?: number): RenderPass[];
|
|
32
34
|
/**
|
|
33
35
|
* Gets the framebuffer used for storing shadow moment data.
|
|
34
36
|
* This framebuffer contains the encoded depth moments for variance shadow mapping.
|
|
@@ -15,6 +15,8 @@ export declare class ShadowSystem {
|
|
|
15
15
|
private __lightTypes;
|
|
16
16
|
private __lightEnables;
|
|
17
17
|
private __lightCastShadows;
|
|
18
|
+
private __lightSids;
|
|
19
|
+
private __isShadowSlotShortageWarned;
|
|
18
20
|
/** Reused by setDepthBiasPV() on every frame. */
|
|
19
21
|
private __depthBiasPVArray?;
|
|
20
22
|
private __depthBiasPV?;
|
|
@@ -42,6 +44,17 @@ export declare class ShadowSystem {
|
|
|
42
44
|
* @returns Array of Expression objects containing the shadow mapping render passes
|
|
43
45
|
*/
|
|
44
46
|
getExpressions(entities: ISceneGraphEntity[]): Expression[];
|
|
47
|
+
/**
|
|
48
|
+
* Assigns the shadow slots (the indices of the per-material shadow arrays) to the lights.
|
|
49
|
+
*
|
|
50
|
+
* A shadow casting light keeps the slot equal to its component SID when the SID is below
|
|
51
|
+
* `Config.maxLightNumber` (the convention of manual shadow map setups), and the other shadow casting lights
|
|
52
|
+
* use the free slots. Lights that do not cast shadows get no slot.
|
|
53
|
+
*
|
|
54
|
+
* @param lightComponents - The live light components
|
|
55
|
+
* @param hasShadowCasters - Whether any entity is rendered to the shadow maps
|
|
56
|
+
*/
|
|
57
|
+
private __assignShadowSlots;
|
|
45
58
|
/**
|
|
46
59
|
* Sets the blurred shadow map texture for directional and spot lights on all entity materials.
|
|
47
60
|
* Creates a linear sampler and assigns the shadow map texture to the 'depthTexture' parameter.
|
|
@@ -2,6 +2,7 @@ export * from './CGAPIResourceRepository';
|
|
|
2
2
|
export * from './Expression';
|
|
3
3
|
export * from './Frame';
|
|
4
4
|
export * from './FrameBuffer';
|
|
5
|
+
export * from './lightCluster';
|
|
5
6
|
export * from './pipelines';
|
|
6
7
|
export * from './RenderingCommonMethods';
|
|
7
8
|
export * from './RenderPass';
|