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
package/VERSION-FILE
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
v0.
|
|
1
|
+
v0.22.0-1-ge32bbaa78-dirty
|
|
2
2
|
main
|
|
@@ -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';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { type LightClusterViewLayout } from './LightClusterLayout';
|
|
2
|
+
/**
|
|
3
|
+
* Pure functions that build the Clustered Forward light clusters of a view on the CPU.
|
|
4
|
+
* The memory layout is described in LightClusterLayout.ts.
|
|
5
|
+
*
|
|
6
|
+
* A light is assigned to a cluster `(x, y, z)` when its bounding sphere `(c, r)` passes all of these tests
|
|
7
|
+
* (the WebGPU compute shader in WebGpuLightClusterBuilder.ts implements the same tests):
|
|
8
|
+
* - The sphere is not entirely behind the eye plane: `dot(rowW, c) / |rowW.xyz| > -r` (skipped when rowW.xyz is 0).
|
|
9
|
+
* - Column: `x == 0 || dist(rowX - x * rowW, c) >= -r` and `x == gridX - 1 || dist((x + 1) * rowW - rowX, c) >= -r`.
|
|
10
|
+
* - Row: the same with rowY and y.
|
|
11
|
+
* - Slice: `z == 0 || d + r >= zs(z)` and `z == gridZ - 1 || d - r <= zs(z + 1)`,
|
|
12
|
+
* where `d = dot(rowDepth, c)` and `zs(k) = exp((k - sliceBias) / sliceScale)`.
|
|
13
|
+
*
|
|
14
|
+
* `dist(plane, c)` is the signed distance `(dot(plane.xyz, c) + plane.w) / |plane.xyz|`.
|
|
15
|
+
* The clusters at the borders of the grid extend to infinity, so a fragment whose cluster coordinates are clamped
|
|
16
|
+
* is still inside its cluster.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* The result of a light cluster build.
|
|
20
|
+
* - `'built'`: every light was stored.
|
|
21
|
+
* - `'truncated'`: some clusters had more lights than `clusterLightCapacity` and kept only their nearest lights.
|
|
22
|
+
*/
|
|
23
|
+
export type LightClusterBuildResult = 'built' | 'truncated';
|
|
24
|
+
/** Scratch memory reused between builds. */
|
|
25
|
+
export type LightClusterBuildScratch = {
|
|
26
|
+
/** The number of vec4 of the light index list used by the last build. */
|
|
27
|
+
usedIndexVec4Count: number;
|
|
28
|
+
counts: Uint32Array;
|
|
29
|
+
offsets: Uint32Array;
|
|
30
|
+
sliceBoundaries: Float64Array;
|
|
31
|
+
/** The normalized tile planes `rowX - k * rowW` (k = 0..gridX), (nx, ny, nz, w) each. Degenerate planes are 0. */
|
|
32
|
+
planesX: Float64Array;
|
|
33
|
+
/** The normalized tile planes `rowY - k * rowW` (k = 0..gridY). */
|
|
34
|
+
planesY: Float64Array;
|
|
35
|
+
/**
|
|
36
|
+
* The columns, rows and slices each light passes (gridX + gridY + gridZ flags per light), evaluated once and
|
|
37
|
+
* reused by the count and fill passes. Grown on demand.
|
|
38
|
+
*/
|
|
39
|
+
axisPass: Uint8Array;
|
|
40
|
+
/** Whether each light touches any cluster. Grown on demand. */
|
|
41
|
+
isLightInView: Uint8Array;
|
|
42
|
+
/** The first and last passing column, row and slice of each light (6 per light). Grown on demand. */
|
|
43
|
+
axisRanges: Int32Array;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Creates the scratch memory for a layout.
|
|
47
|
+
*/
|
|
48
|
+
export declare function createLightClusterBuildScratch(layout: LightClusterViewLayout): LightClusterBuildScratch;
|
|
49
|
+
/**
|
|
50
|
+
* Writes the header of a view region: the clip rows, the depth row, the grid size and the depth slices.
|
|
51
|
+
*
|
|
52
|
+
* The depth range of the slices is the intersection of the depth range of the light spheres and the visible depth
|
|
53
|
+
* range of the camera: the slices are not wasted on depths where no light reaches, nor in front of the camera near
|
|
54
|
+
* plane or beyond the far plane.
|
|
55
|
+
*
|
|
56
|
+
* @param dst - The memory of the view region
|
|
57
|
+
* @param viewOffset - The float offset of the view region in `dst`
|
|
58
|
+
* @param viewMatrix - The view matrix (column-major, as uploaded to the GPU)
|
|
59
|
+
* @param projectionMatrix - The projection matrix (column-major, as uploaded to the GPU)
|
|
60
|
+
* @param spheres - The light spheres in world space (cx, cy, cz, r) * localCount
|
|
61
|
+
* @param localCount - The number of light spheres
|
|
62
|
+
* @param layout - The layout of the view region
|
|
63
|
+
* @param visibleNearDepth - The view depth of the camera near plane (0 disables the clamp)
|
|
64
|
+
* @param visibleFarDepth - The view depth of the camera far plane (Infinity disables the clamp)
|
|
65
|
+
*/
|
|
66
|
+
export declare function writeLightClusterViewHeader(dst: Float32Array, viewOffset: number, viewMatrix: ArrayLike<number>, projectionMatrix: ArrayLike<number>, spheres: ArrayLike<number>, localCount: number, layout: LightClusterViewLayout, visibleNearDepth?: number, visibleFarDepth?: number): void;
|
|
67
|
+
/**
|
|
68
|
+
* Builds the cluster table and the light index list of a view whose header has been written.
|
|
69
|
+
*
|
|
70
|
+
* The lights of each cluster are stored in the order of `localEntries`. The caller passes the lights sorted by their
|
|
71
|
+
* view depth (nearest first) when the number of local lights exceeds the capacity, so that a cluster which is full
|
|
72
|
+
* keeps its nearest lights. Every cluster keeps at most `layout.clusterLightCapacity` lights, so the list cannot
|
|
73
|
+
* overflow.
|
|
74
|
+
*/
|
|
75
|
+
export declare function buildLightClustersOnCpu(dst: Float32Array, viewOffset: number, layout: LightClusterViewLayout, spheres: ArrayLike<number>, localEntries: ArrayLike<number>, localCount: number, scratch: LightClusterBuildScratch): LightClusterBuildResult;
|
|
76
|
+
/**
|
|
77
|
+
* The cluster-centric form of the assignment test (the form the WebGPU compute shader uses).
|
|
78
|
+
* It must agree with the light-centric build of `buildLightClustersOnCpu`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function sphereIntersectsLightCluster(dst: Float32Array, viewOffset: number, layout: LightClusterViewLayout, x: number, y: number, z: number, cx: number, cy: number, cz: number, r: number): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* The reference implementation of the cluster lookup of the shaders (`getLightList`).
|
|
83
|
+
*
|
|
84
|
+
* @returns The cluster index, or -1 when the position uses the all-light list (behind the eye plane or overflow).
|
|
85
|
+
*/
|
|
86
|
+
export declare function computeLightClusterIndex(dst: Float32Array, viewOffset: number, px: number, py: number, pz: number): number;
|
|
87
|
+
/**
|
|
88
|
+
* Reads the light entries of a cluster built by `buildLightClustersOnCpu` (or by the compute shader).
|
|
89
|
+
*/
|
|
90
|
+
export declare function readLightClusterEntries(dst: Float32Array, viewOffset: number, layout: LightClusterViewLayout, clusterIndex: number): number[];
|
|
91
|
+
/**
|
|
92
|
+
* Computes the bounding sphere of a light from the values uploaded to the GPU.
|
|
93
|
+
* Returns the radius, or -1 when the light can not be culled (directional lights and lights without range).
|
|
94
|
+
*
|
|
95
|
+
* @param out - Receives (cx, cy, cz, r) at `outOffset`
|
|
96
|
+
*/
|
|
97
|
+
export declare function computeLightBoundingSphere(typeValue: number, position: ArrayLike<number>, direction: ArrayLike<number>, range: number, outerConeCos: number, out: Float64Array, outOffset: number): number;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory layout of the Clustered Forward light data.
|
|
3
|
+
*
|
|
4
|
+
* All values are stored as 32-bit floats in the GPU instance data (the data texture in WebGL2,
|
|
5
|
+
* the storage buffer in WebGPU) and read with `fetchElement(vec4Index)` / `get_clusteredLightData(0u, idx)`.
|
|
6
|
+
* Integers are below 2^24 and are therefore represented exactly.
|
|
7
|
+
*
|
|
8
|
+
* ## Global property `clusteredLightData` (always present)
|
|
9
|
+
* ```
|
|
10
|
+
* [0] (allCount, globalCount, localCount, sphereBase)
|
|
11
|
+
* [1..] allList: light entries, 4 entries per vec4.
|
|
12
|
+
* The lights that can not be culled (directional lights, lights without range) come first,
|
|
13
|
+
* then the local lights. Both groups are sorted by the light component SID.
|
|
14
|
+
* ```
|
|
15
|
+
* `sphereBase` is -1 (the GPU cluster build receives its own sorted light input in a separate storage buffer).
|
|
16
|
+
*
|
|
17
|
+
* ## Light entry
|
|
18
|
+
* `entry = lightComponentSID + 65536 * (shadowSlot + 1)` (`shadowSlot` is -1 when the light has no shadow slot).
|
|
19
|
+
*
|
|
20
|
+
* ## View region (one per camera, allocated on demand, referenced by `CameraComponent.lightClusterViewInfo.x`)
|
|
21
|
+
* ```
|
|
22
|
+
* [0] rowX 0.5 * gridX * (clipRow0 + clipRow3): tileX = floor(dot(rowX, p) / dot(rowW, p))
|
|
23
|
+
* [1] rowY 0.5 * gridY * (clipRow1 + clipRow3)
|
|
24
|
+
* [2] rowW clipRow3
|
|
25
|
+
* [3] rowDepth normalized view depth row: depth = dot(rowDepth, p) (positive in front of the camera)
|
|
26
|
+
* [4] (gridX, gridY, gridZ, state) state: 0 (valid; reserved)
|
|
27
|
+
* [5] (sliceScale, sliceBias, zNear, zFar) slice = floor(log(depth) * sliceScale + sliceBias)
|
|
28
|
+
* [6..] cluster table: one vec4 per cluster, (offset, count, 0, 0).
|
|
29
|
+
* offset is the vec4 index of the list of the cluster from the index list start.
|
|
30
|
+
* [6 + clusterCount..] index list: 4 entries per vec4.
|
|
31
|
+
* The CPU build packs the lists densely (offset is the exclusive prefix sum of the cluster counts); the WebGPU
|
|
32
|
+
* build gives every cluster its own `ceil(clusterLightCapacity / 4)` vec4s (offset = cluster * that). The rest
|
|
33
|
+
* of the last vec4 of a list is zero.
|
|
34
|
+
* ```
|
|
35
|
+
* The cluster index is `(z * gridY + y) * gridX + x`. The clusters at the borders of the grid extend to infinity,
|
|
36
|
+
* so clamping the cluster coordinates of a fragment is always correct.
|
|
37
|
+
*
|
|
38
|
+
* Every cluster owns whole vec4s of the table and of the index list, so the compute shaders never write to a vec4
|
|
39
|
+
* that another invocation writes (some backends store a vector component by rewriting the whole vector).
|
|
40
|
+
*/
|
|
41
|
+
export declare const LightClusterLayout: {
|
|
42
|
+
/** The radix used to pack the shadow slot into a light entry. */
|
|
43
|
+
readonly entryRadix: 65536;
|
|
44
|
+
/** The maximum number of lights in the light list (light component SIDs must be below the radix). */
|
|
45
|
+
readonly maxLightListLength: 65535;
|
|
46
|
+
/** The number of vec4 of the header of the global property. */
|
|
47
|
+
readonly globalHeaderVec4Count: 1;
|
|
48
|
+
/** The number of vec4 of the header of a view region. */
|
|
49
|
+
readonly viewHeaderVec4Count: 6;
|
|
50
|
+
/** The vec4 offset of the grid info (gridX, gridY, gridZ, state) in a view region. */
|
|
51
|
+
readonly viewGridOffset: 4;
|
|
52
|
+
/** The vec4 offset of the slice info (sliceScale, sliceBias, zNear, zFar) in a view region. */
|
|
53
|
+
readonly viewSliceOffset: 5;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Clamps the length of the light list to the supported range.
|
|
57
|
+
*/
|
|
58
|
+
export declare function getLightListCapacity(maxLightListLength: number): number;
|
|
59
|
+
/**
|
|
60
|
+
* Returns the array length (in vec4) of the `clusteredLightData` global property.
|
|
61
|
+
*/
|
|
62
|
+
export declare function getLightClusterGlobalPropertyLength(maxLightListLength: number): number;
|
|
63
|
+
/**
|
|
64
|
+
* Packs a light component SID and a shadow slot into a light entry.
|
|
65
|
+
*/
|
|
66
|
+
export declare function packLightEntry(lightComponentSid: number, shadowSlot: number): number;
|
|
67
|
+
/**
|
|
68
|
+
* Unpacks a light entry into the light component SID and the shadow slot (-1 = no shadow slot).
|
|
69
|
+
*/
|
|
70
|
+
export declare function unpackLightEntry(entry: number): [number, number];
|
|
71
|
+
/**
|
|
72
|
+
* The sizes of a view region (in vec4).
|
|
73
|
+
*/
|
|
74
|
+
export type LightClusterViewLayout = {
|
|
75
|
+
gridX: number;
|
|
76
|
+
gridY: number;
|
|
77
|
+
gridZ: number;
|
|
78
|
+
clusterCount: number;
|
|
79
|
+
tableVec4Count: number;
|
|
80
|
+
indexCapacity: number;
|
|
81
|
+
indexVec4Count: number;
|
|
82
|
+
/** The maximum number of lights stored in one cluster. */
|
|
83
|
+
clusterLightCapacity: number;
|
|
84
|
+
viewVec4Count: number;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Computes the sizes of a view region from the grid size and the number of lights per cluster the light index list
|
|
88
|
+
* is sized for. The list is shared by the clusters, and each cluster pads its list to a multiple of 4 entries, so
|
|
89
|
+
* the list never overflows while no cluster has more lights than `lightCapacityPerCluster`.
|
|
90
|
+
*/
|
|
91
|
+
export declare function getLightClusterViewLayout(gridSize: readonly [number, number, number], lightCapacityPerCluster: number): LightClusterViewLayout;
|
|
92
|
+
/**
|
|
93
|
+
* Splits the byte range `[start, end)` into the parts outside the excluded ranges.
|
|
94
|
+
*
|
|
95
|
+
* @param excluded - Ranges `[start, end)` sorted by their start
|
|
96
|
+
* @returns The remaining ranges `[start, end)` in ascending order
|
|
97
|
+
*/
|
|
98
|
+
export declare function subtractByteRanges(start: number, end: number, excluded: readonly [number, number][]): [number, number][];
|