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.
Files changed (36) hide show
  1. package/VERSION-FILE +1 -1
  2. package/dist/esm/foundation/components/Camera/CameraComponent.d.ts +15 -0
  3. package/dist/esm/foundation/components/Light/LightComponent.d.ts +109 -4
  4. package/dist/esm/foundation/core/Config.d.ts +165 -3
  5. package/dist/esm/foundation/helpers/Shadow/PointShadowMap.d.ts +3 -1
  6. package/dist/esm/foundation/helpers/Shadow/ShadowSystem.d.ts +13 -0
  7. package/dist/esm/foundation/renderer/index.d.ts +1 -0
  8. package/dist/esm/foundation/renderer/lightCluster/LightClusterBuilder.d.ts +97 -0
  9. package/dist/esm/foundation/renderer/lightCluster/LightClusterLayout.d.ts +98 -0
  10. package/dist/esm/foundation/renderer/lightCluster/LightClusterSystem.d.ts +171 -0
  11. package/dist/esm/foundation/renderer/lightCluster/index.d.ts +1 -0
  12. package/dist/esm/foundation/system/Engine.d.ts +7 -0
  13. package/dist/esm/foundation/textures/TextureArray.d.ts +1 -1
  14. package/dist/esm/index.js +1096 -616
  15. package/dist/esm/webgl/WebGLStrategyWebGL2.d.ts +16 -0
  16. package/dist/esm/webgpu/WebGpuLightClusterBuilder.d.ts +34 -0
  17. package/dist/esm/webgpu/WebGpuResourceRepository.d.ts +28 -3
  18. package/dist/esm/webgpu/WebGpuStrategyBasic.d.ts +18 -1
  19. package/dist/esmdev/foundation/components/Camera/CameraComponent.d.ts +15 -0
  20. package/dist/esmdev/foundation/components/Light/LightComponent.d.ts +109 -4
  21. package/dist/esmdev/foundation/core/Config.d.ts +165 -3
  22. package/dist/esmdev/foundation/helpers/Shadow/PointShadowMap.d.ts +3 -1
  23. package/dist/esmdev/foundation/helpers/Shadow/ShadowSystem.d.ts +13 -0
  24. package/dist/esmdev/foundation/renderer/index.d.ts +1 -0
  25. package/dist/esmdev/foundation/renderer/lightCluster/LightClusterBuilder.d.ts +97 -0
  26. package/dist/esmdev/foundation/renderer/lightCluster/LightClusterLayout.d.ts +98 -0
  27. package/dist/esmdev/foundation/renderer/lightCluster/LightClusterSystem.d.ts +171 -0
  28. package/dist/esmdev/foundation/renderer/lightCluster/index.d.ts +1 -0
  29. package/dist/esmdev/foundation/system/Engine.d.ts +7 -0
  30. package/dist/esmdev/foundation/textures/TextureArray.d.ts +1 -1
  31. package/dist/esmdev/index.js +2141 -144
  32. package/dist/esmdev/webgl/WebGLStrategyWebGL2.d.ts +16 -0
  33. package/dist/esmdev/webgpu/WebGpuLightClusterBuilder.d.ts +34 -0
  34. package/dist/esmdev/webgpu/WebGpuResourceRepository.d.ts +28 -3
  35. package/dist/esmdev/webgpu/WebGpuStrategyBasic.d.ts +18 -1
  36. package/package.json +1 -1
@@ -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;
@@ -238,6 +241,10 @@ export declare class Engine extends RnObject {
238
241
  get webARSystem(): WebARSystem;
239
242
  get memoryManager(): MemoryManager;
240
243
  get globalDataRepository(): GlobalDataRepository;
244
+ /**
245
+ * The system that builds the light lists of Clustered Forward rendering.
246
+ */
247
+ get lightClusterSystem(): LightClusterSystem;
241
248
  get materialRepository(): MaterialRepository;
242
249
  get webglResourceRepository(): WebGLResourceRepository;
243
250
  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.maxLightNumber),
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)