rhodonite 0.21.0 → 0.22.1
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/README.md +4 -4
- 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 +116 -4
- package/dist/esm/foundation/components/SceneGraph/SceneGraphComponent.d.ts +2 -0
- package/dist/esm/foundation/core/Config.d.ts +199 -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/math/Transform3D.d.ts +26 -2
- 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 +20 -2
- package/dist/esm/foundation/textures/TextureArray.d.ts +1 -1
- package/dist/esm/index.js +1216 -650
- package/dist/esm/webgl/WebGLStrategyWebGL2.d.ts +16 -0
- package/dist/esm/webgpu/WebGpuGpuTimer.d.ts +18 -7
- package/dist/esm/webgpu/WebGpuLightClusterBuilder.d.ts +37 -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 +116 -4
- package/dist/esmdev/foundation/components/SceneGraph/SceneGraphComponent.d.ts +2 -0
- package/dist/esmdev/foundation/core/Config.d.ts +199 -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/math/Transform3D.d.ts +26 -2
- 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 +20 -2
- package/dist/esmdev/foundation/textures/TextureArray.d.ts +1 -1
- package/dist/esmdev/index.js +2394 -214
- package/dist/esmdev/webgl/WebGLStrategyWebGL2.d.ts +16 -0
- package/dist/esmdev/webgpu/WebGpuGpuTimer.d.ts +18 -7
- package/dist/esmdev/webgpu/WebGpuLightClusterBuilder.d.ts +37 -0
- package/dist/esmdev/webgpu/WebGpuResourceRepository.d.ts +28 -3
- package/dist/esmdev/webgpu/WebGpuStrategyBasic.d.ts +18 -1
- package/package.json +1 -1
|
@@ -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][];
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import type { Engine } from '../../system/Engine';
|
|
2
|
+
import type { Expression } from '../Expression';
|
|
3
|
+
import { type LightClusterViewLayout } from './LightClusterLayout';
|
|
4
|
+
/**
|
|
5
|
+
* The parameters of the light cluster build on the GPU (WebGPU compute shaders).
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export type LightClusterGpuBuildView = {
|
|
10
|
+
/** The vec4 index of the view region to build. */
|
|
11
|
+
viewVec4Base: number;
|
|
12
|
+
/** The number of local lights of the view. */
|
|
13
|
+
localCount: number;
|
|
14
|
+
/** The float offset of the view in `data`. */
|
|
15
|
+
dataOffset: number;
|
|
16
|
+
};
|
|
17
|
+
export type LightClusterGpuBuildParams = {
|
|
18
|
+
views: readonly LightClusterGpuBuildView[];
|
|
19
|
+
/** The sorted light spheres, entries and Z slice ranges of the views, `dataStride` floats per view. */
|
|
20
|
+
data: Float32Array;
|
|
21
|
+
dataStride: number;
|
|
22
|
+
/** The maximum number of local lights stored in the build data of a view. */
|
|
23
|
+
localCapacity: number;
|
|
24
|
+
layout: LightClusterViewLayout;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Builds the light lists of Clustered Forward rendering once per frame.
|
|
28
|
+
*
|
|
29
|
+
* - Every enabled light is written to the all-light list of the `clusteredLightData` global property
|
|
30
|
+
* (lights that can not be culled first, then the local lights, each sorted by the component SID).
|
|
31
|
+
* - For each camera used by the render passes of the frame (up to `Config.clusteredForwardMaxViewNumber`),
|
|
32
|
+
* a view region with the cluster grid is built when there are local lights, and the camera's
|
|
33
|
+
* `lightClusterViewInfo` points to it. Other cameras use the all-light list.
|
|
34
|
+
*
|
|
35
|
+
* The light data is read from the GPU instance data of the light components (the values the shaders see),
|
|
36
|
+
* so the clusters always match the lights the shaders evaluate.
|
|
37
|
+
*
|
|
38
|
+
* The data lives in the GPU instance data, so it is uploaded by the rendering strategy. `dataVersion` changes
|
|
39
|
+
* whenever this system writes the data, and the strategies upload the data when it changes.
|
|
40
|
+
*/
|
|
41
|
+
export declare class LightClusterSystem {
|
|
42
|
+
private __engine;
|
|
43
|
+
private __dataVersion;
|
|
44
|
+
private __globalData?;
|
|
45
|
+
private __globalDataVec4Base;
|
|
46
|
+
private __capacity;
|
|
47
|
+
private __layout?;
|
|
48
|
+
private __scratch?;
|
|
49
|
+
private __entries;
|
|
50
|
+
private __prevEntries;
|
|
51
|
+
private __spheres;
|
|
52
|
+
private __prevSpheres;
|
|
53
|
+
private __localEntries;
|
|
54
|
+
private __allCount;
|
|
55
|
+
private __globalCount;
|
|
56
|
+
private __localCount;
|
|
57
|
+
/** The number of local lights that emit light (counted for Config.clusteredForwardMinLocalLightNumber). */
|
|
58
|
+
private __emittingLocalCount;
|
|
59
|
+
private __prevAllCount;
|
|
60
|
+
private __prevGlobalCount;
|
|
61
|
+
private __prevSphereVec4Base;
|
|
62
|
+
private __viewRegions;
|
|
63
|
+
/** The camera component SID of each view slot (-1: free). */
|
|
64
|
+
private __slotCameraSids;
|
|
65
|
+
/** Whether each view slot holds valid clusters for its camera, the current lights and the matrices below. */
|
|
66
|
+
private __slotValid;
|
|
67
|
+
/** The view and projection matrices each view slot was built with. */
|
|
68
|
+
private __slotMatrices;
|
|
69
|
+
/** The cameras whose `lightClusterViewInfo` currently points to a view region. */
|
|
70
|
+
private __camerasWithView;
|
|
71
|
+
private __isAllocationFailed;
|
|
72
|
+
private __isCapacityWarned;
|
|
73
|
+
/** The order of the local lights of the view being built, sorted by view depth when the number of lights is large. */
|
|
74
|
+
private __sortOrder;
|
|
75
|
+
private __sortDepths;
|
|
76
|
+
private __sortedSpheres;
|
|
77
|
+
private __sortedEntries;
|
|
78
|
+
private __sliceRanges;
|
|
79
|
+
/** The GPU build inputs (sorted spheres, entries and slice ranges) of the views, stored per view slot. */
|
|
80
|
+
private __gpuBuildData;
|
|
81
|
+
private __gpuBuildStride;
|
|
82
|
+
private __gpuBuildViews;
|
|
83
|
+
/** The number of local lights of the view built in each slot. */
|
|
84
|
+
private __slotLocalCounts;
|
|
85
|
+
/**
|
|
86
|
+
* The byte ranges (in the GPU instance data) of the cluster tables and light index lists of the views. They are
|
|
87
|
+
* large and written by this system or the compute shaders, so the generic upload of the GPU instance data skips them.
|
|
88
|
+
*/
|
|
89
|
+
private __excludedByteRanges;
|
|
90
|
+
/** The byte ranges built on the CPU since the last upload, which the rendering strategy uploads separately. */
|
|
91
|
+
private __dirtyByteRanges;
|
|
92
|
+
/** The data of `u_lightClusterView` of the WebGL2 shaders (7 vec4). */
|
|
93
|
+
private __viewUniformData;
|
|
94
|
+
constructor(engine: Engine);
|
|
95
|
+
/**
|
|
96
|
+
* Incremented whenever this system writes to the GPU instance data.
|
|
97
|
+
*/
|
|
98
|
+
get dataVersion(): number;
|
|
99
|
+
/**
|
|
100
|
+
* Whether the cluster tables are built by WebGPU compute shaders instead of the CPU.
|
|
101
|
+
*/
|
|
102
|
+
get isGpuBuild(): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* The parameters of the views to build on the GPU, or undefined when nothing has to be built on the GPU.
|
|
105
|
+
*
|
|
106
|
+
* @internal
|
|
107
|
+
*/
|
|
108
|
+
_getGpuBuildParams(): LightClusterGpuBuildParams | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* The byte ranges of the GPU instance data that the generic upload must skip, sorted by the start.
|
|
111
|
+
* The ranges are uploaded by `_takeDirtyByteRanges` (CPU build) or written by the compute shaders (GPU build).
|
|
112
|
+
*
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
_getExcludedByteRanges(): readonly [number, number][];
|
|
116
|
+
/**
|
|
117
|
+
* Returns the byte ranges of the GPU instance data built on the CPU since the last call, and clears them.
|
|
118
|
+
* The rendering strategy uploads them after the generic upload.
|
|
119
|
+
*
|
|
120
|
+
* @internal
|
|
121
|
+
*/
|
|
122
|
+
_takeDirtyByteRanges(): [number, number][];
|
|
123
|
+
/**
|
|
124
|
+
* Returns the data of the `u_lightClusterView` uniform of the WebGL2 shaders for a camera: the view header
|
|
125
|
+
* (6 vec4) and (vec4 index of the view, 0, 0, 0), or a view index of -1 when the camera has no light clusters.
|
|
126
|
+
* The returned array is reused.
|
|
127
|
+
*
|
|
128
|
+
* @internal
|
|
129
|
+
*/
|
|
130
|
+
_getViewUniformData(cameraSid: number): Float32Array;
|
|
131
|
+
/**
|
|
132
|
+
* Updates the light lists for the render passes of this frame.
|
|
133
|
+
* This must be called after the Logic stage (the light and camera data are final) and before the strategy
|
|
134
|
+
* uploads the GPU instance data.
|
|
135
|
+
*
|
|
136
|
+
* @param expressions - The expressions rendered in this frame
|
|
137
|
+
*/
|
|
138
|
+
update(expressions: readonly Expression[]): void;
|
|
139
|
+
private __initialize;
|
|
140
|
+
/**
|
|
141
|
+
* Collects the enabled lights into the all-light list and the local light spheres.
|
|
142
|
+
* @returns true if the lists changed since the previous frame
|
|
143
|
+
*/
|
|
144
|
+
private __collectLights;
|
|
145
|
+
private __writeGlobalData;
|
|
146
|
+
/**
|
|
147
|
+
* Lists the cameras of the render passes that may draw lit materials, in the order of the render passes.
|
|
148
|
+
* The rules are the same as the camera selection of the rendering strategies.
|
|
149
|
+
*/
|
|
150
|
+
private __collectCameras;
|
|
151
|
+
/**
|
|
152
|
+
* Assigns the view slots to the cameras, builds the views whose inputs changed and updates the
|
|
153
|
+
* `lightClusterViewInfo` of the cameras.
|
|
154
|
+
* @returns true if anything was written
|
|
155
|
+
*/
|
|
156
|
+
private __assignViews;
|
|
157
|
+
/**
|
|
158
|
+
* Prepares the light order and the Z slice ranges of a view for the builders.
|
|
159
|
+
*
|
|
160
|
+
* The lights are sorted by their view depth when there are more local lights than the capacity of a cluster, so
|
|
161
|
+
* that a cluster which is full keeps its nearest lights. Otherwise the light component SID order is kept (no
|
|
162
|
+
* cluster can be full), which keeps the result identical to a build without a capacity.
|
|
163
|
+
*
|
|
164
|
+
* For the GPU build, the sorted spheres, entries and ranges are copied to the GPU build data of the view.
|
|
165
|
+
*/
|
|
166
|
+
private __prepareViewBuild;
|
|
167
|
+
/**
|
|
168
|
+
* Allocates a region in the GPU instance data. Returns undefined (and disables the clusters) when it fails.
|
|
169
|
+
*/
|
|
170
|
+
private __allocate;
|
|
171
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './LightClusterSystem';
|
|
@@ -14,6 +14,7 @@ import { Logger } from '../misc/Logger';
|
|
|
14
14
|
import { type ICGAPIResourceRepository } from '../renderer/CGAPIResourceRepository';
|
|
15
15
|
import { Expression } from '../renderer/Expression';
|
|
16
16
|
import { Frame } from '../renderer/Frame';
|
|
17
|
+
import { LightClusterSystem } from '../renderer/lightCluster/LightClusterSystem';
|
|
17
18
|
import { EngineState } from './EngineState';
|
|
18
19
|
import type { WebARSystem } from '../../xr/WebARSystem';
|
|
19
20
|
import type { WebXRSystem } from '../../xr/WebXRSystem';
|
|
@@ -68,6 +69,7 @@ export declare class Engine extends RnObject {
|
|
|
68
69
|
private __memoryManager?;
|
|
69
70
|
private __materialRepository;
|
|
70
71
|
private __globalDataRepository;
|
|
72
|
+
private __lightClusterSystem;
|
|
71
73
|
private __config;
|
|
72
74
|
private __logger;
|
|
73
75
|
private __dummyTextures?;
|
|
@@ -75,6 +77,7 @@ export declare class Engine extends RnObject {
|
|
|
75
77
|
private __lastCameraControllerComponentsUpdateCount;
|
|
76
78
|
private __lastTransformComponentsUpdateCount;
|
|
77
79
|
private __lastPrimitiveCount;
|
|
80
|
+
private __lastLightComponentsUpdateCount;
|
|
78
81
|
/** Shader program cache map for this engine instance. Maps shader text to program UIDs. */
|
|
79
82
|
private __shaderProgramCache;
|
|
80
83
|
private __gpuTimerEnabled;
|
|
@@ -190,10 +193,21 @@ export declare class Engine extends RnObject {
|
|
|
190
193
|
* @remarks
|
|
191
194
|
* Undefined until a result is available, or when {@link gpuTimerEnabled} is false or the environment does
|
|
192
195
|
* not support GPU timer queries. GPU results arrive asynchronously, so the value lags behind by a few
|
|
193
|
-
* frames. In WebGPU it is the sum of the durations of the render passes
|
|
194
|
-
* spent on all the commands issued during
|
|
196
|
+
* frames. In WebGPU it is the sum of the durations of the render passes and the compute passes (such as
|
|
197
|
+
* the light cluster build); in WebGL2 it is the time the GPU spent on all the commands issued during
|
|
198
|
+
* process().
|
|
195
199
|
*/
|
|
196
200
|
get gpuTimeMilliseconds(): number | undefined;
|
|
201
|
+
/**
|
|
202
|
+
* The GPU time of each pass of the latest measured process() call, in milliseconds, keyed by the pass label.
|
|
203
|
+
*
|
|
204
|
+
* @remarks
|
|
205
|
+
* WebGPU only. Undefined until a complete result is available, when {@link gpuTimerEnabled} is false, or
|
|
206
|
+
* when the GPU timer is not supported. The labels are the labels of the GPU passes: the unique names of the
|
|
207
|
+
* render passes, `DepthPrepass`, `LightClusterBuild`, and so on. Passes with the same label are summed.
|
|
208
|
+
* Like {@link gpuTimeMilliseconds}, the value lags behind by a few frames.
|
|
209
|
+
*/
|
|
210
|
+
get gpuPassTimesMilliseconds(): ReadonlyMap<string, number> | undefined;
|
|
197
211
|
private __getWebGLGpuTimer;
|
|
198
212
|
private __beginGpuTimer;
|
|
199
213
|
private __endGpuTimer;
|
|
@@ -238,6 +252,10 @@ export declare class Engine extends RnObject {
|
|
|
238
252
|
get webARSystem(): WebARSystem;
|
|
239
253
|
get memoryManager(): MemoryManager;
|
|
240
254
|
get globalDataRepository(): GlobalDataRepository;
|
|
255
|
+
/**
|
|
256
|
+
* The system that builds the light lists of Clustered Forward rendering.
|
|
257
|
+
*/
|
|
258
|
+
get lightClusterSystem(): LightClusterSystem;
|
|
241
259
|
get materialRepository(): MaterialRepository;
|
|
242
260
|
get webglResourceRepository(): WebGLResourceRepository;
|
|
243
261
|
get cgApiResourceRepository(): ICGAPIResourceRepository;
|
|
@@ -29,7 +29,7 @@ export declare class TextureArray extends AbstractTexture implements Disposable
|
|
|
29
29
|
private static __deleteInternalTexture;
|
|
30
30
|
/**
|
|
31
31
|
* Loads a 1x1 texture array with a solid color.
|
|
32
|
-
* This creates a texture array with the specified number of layers (Config.
|
|
32
|
+
* This creates a texture array with the specified number of layers (Config.maxLightNumberOrOne),
|
|
33
33
|
* each containing a single pixel of the specified color.
|
|
34
34
|
*
|
|
35
35
|
* @param rgbaStr - CSS color string in rgba format (default: 'rgba(0,0,0,1)' for black)
|