rhodonite 0.22.1 → 0.22.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/VERSION-FILE +1 -1
- package/dist/esm/foundation/components/SceneGraph/SceneGraphComponent.d.ts +26 -1
- package/dist/esm/foundation/core/ComponentRepository.d.ts +7 -0
- package/dist/esm/foundation/renderer/lightCluster/LightClusterBuilder.d.ts +7 -1
- package/dist/esm/foundation/renderer/lightCluster/LightClusterLayout.d.ts +11 -0
- package/dist/esm/foundation/renderer/lightCluster/LightClusterSystem.d.ts +22 -0
- package/dist/esm/index.js +204 -123
- package/dist/esm/webgl/WebGLStrategyWebGL2.d.ts +9 -5
- package/dist/esm/webgpu/convertFloat32ToFloat16Bits.d.ts +16 -0
- package/dist/esm/webgpu/packRgbaRowsForUpload.d.ts +23 -0
- package/dist/esmdev/foundation/components/SceneGraph/SceneGraphComponent.d.ts +26 -1
- package/dist/esmdev/foundation/core/ComponentRepository.d.ts +7 -0
- package/dist/esmdev/foundation/renderer/lightCluster/LightClusterBuilder.d.ts +7 -1
- package/dist/esmdev/foundation/renderer/lightCluster/LightClusterLayout.d.ts +11 -0
- package/dist/esmdev/foundation/renderer/lightCluster/LightClusterSystem.d.ts +22 -0
- package/dist/esmdev/index.js +693 -50
- package/dist/esmdev/webgl/WebGLStrategyWebGL2.d.ts +9 -5
- package/dist/esmdev/webgpu/convertFloat32ToFloat16Bits.d.ts +16 -0
- package/dist/esmdev/webgpu/packRgbaRowsForUpload.d.ts +23 -0
- package/package.json +1 -1
|
@@ -489,16 +489,20 @@ export declare class WebGLStrategyWebGL2 implements CGAPIStrategy, WebGLStrategy
|
|
|
489
489
|
* between draw calls and only updating GPU state when necessary.
|
|
490
490
|
*/
|
|
491
491
|
private __renderInner;
|
|
492
|
-
/**
|
|
493
|
-
* Uploads the currentComponentSIDs uniform unless the same values were already uploaded to the
|
|
494
|
-
* same program by the previous upload. Uniform values persist in the program object, so
|
|
495
|
-
* consecutive draws of the same material (e.g. a shadow pass) do not need to upload again.
|
|
496
|
-
*/
|
|
497
492
|
/**
|
|
498
493
|
* Uploads the light cluster view of the camera of the draw (`u_lightClusterView`) when the program uses it and
|
|
499
494
|
* the camera or the light cluster data changed since the last upload to the program.
|
|
495
|
+
*
|
|
496
|
+
* The 7 vec4 are [header (6 vec4)][(view vec4 index, 0, 0, 0)], or a view index of -1 when the camera has no
|
|
497
|
+
* clusters. Uniform values persist in the program object, so consecutive draws of the same camera skip the
|
|
498
|
+
* upload; the check keeps the per-draw cost to a comparison in the common case.
|
|
500
499
|
*/
|
|
501
500
|
private __uploadLightClusterView;
|
|
501
|
+
/**
|
|
502
|
+
* Uploads the currentComponentSIDs uniform unless the same values were already uploaded to the
|
|
503
|
+
* same program by the previous upload. Uniform values persist in the program object, so
|
|
504
|
+
* consecutive draws of the same material (e.g. a shadow pass) do not need to upload again.
|
|
505
|
+
*/
|
|
502
506
|
private __uploadCurrentComponentSIDs;
|
|
503
507
|
/**
|
|
504
508
|
* Binds the data texture to the WebGL context for shader access.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts Float32 values to IEEE 754 half-float (Float16) bits.
|
|
3
|
+
*
|
|
4
|
+
* HDR textures are uploaded as half floats on devices without the optional
|
|
5
|
+
* `float32-filterable` feature (e.g. iOS Safari). There an `rgba32float` texture cannot be
|
|
6
|
+
* bound with the default `sampleType: 'float'` of the texture bind group layouts, so every
|
|
7
|
+
* draw using it is rejected. Filtering 16-bit float textures is core WebGPU, so half floats
|
|
8
|
+
* work everywhere.
|
|
9
|
+
*
|
|
10
|
+
* The conversion rounds to nearest, ties to even, and handles denormals, Infinity and NaN
|
|
11
|
+
* exactly like the platform `Float16Array` conversion.
|
|
12
|
+
*
|
|
13
|
+
* @param src - Float32 values
|
|
14
|
+
* @returns The same values encoded as half-float bits
|
|
15
|
+
*/
|
|
16
|
+
export declare function convertFloat32ToFloat16Bits(src: Float32Array): Uint16Array;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** RGBA float rows packed for GPUQueue.copyBufferToTexture. */
|
|
2
|
+
export type PackedRgbaRows = {
|
|
3
|
+
/** Padded rows, ready to copy into a mapped GPUBuffer. */
|
|
4
|
+
data: Uint16Array | Float32Array;
|
|
5
|
+
/** `bytesPerRow` for the copy, padded to the 256-byte alignment WebGPU requires. */
|
|
6
|
+
bytesPerRow: number;
|
|
7
|
+
/** Number of array elements per row (row stride of `data`). */
|
|
8
|
+
elementsPerRow: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Packs tightly packed RGBA Float32 rows into the padded layout that
|
|
12
|
+
* GPUQueue.copyBufferToTexture requires.
|
|
13
|
+
*
|
|
14
|
+
* Rows must be padded to a multiple of 256 bytes. A row also has to be copied at
|
|
15
|
+
* `elementsPerRow` in the destination array (components per row, including padding),
|
|
16
|
+
* not at the number of texels in the row.
|
|
17
|
+
*
|
|
18
|
+
* @param src - Tightly packed RGBA Float32 pixel data
|
|
19
|
+
* @param width - Width in pixels
|
|
20
|
+
* @param height - Height in pixels
|
|
21
|
+
* @param isFloat16 - Encode as half floats instead of 32-bit floats
|
|
22
|
+
*/
|
|
23
|
+
export declare function packRgbaRowsForUpload(src: Float32Array, width: number, height: number, isFloat16: boolean): PackedRgbaRows;
|
|
@@ -31,6 +31,12 @@ export declare class SceneGraphComponent extends Component {
|
|
|
31
31
|
private __isGizmoChild;
|
|
32
32
|
private __physicsComponentCountInSubtree;
|
|
33
33
|
private static __hierarchyVersion;
|
|
34
|
+
/**
|
|
35
|
+
* Validity epoch of the per-node `__aabbDirtyChainEpoch` marks. Advancing it invalidates all marks at
|
|
36
|
+
* once; this is required whenever an AABB-dirty flag is cleared or a parent-child link changes, since
|
|
37
|
+
* either can break the "this node and all ancestors are AABB-dirty" guarantee of a mark.
|
|
38
|
+
*/
|
|
39
|
+
private static __aabbDirtyChainEpoch;
|
|
34
40
|
private _worldMatrix;
|
|
35
41
|
private _worldMatrixRest;
|
|
36
42
|
private _normalMatrix;
|
|
@@ -47,6 +53,16 @@ export declare class SceneGraphComponent extends Component {
|
|
|
47
53
|
private __worldMergedAABBWithSkeletal;
|
|
48
54
|
private __worldMergedAABB;
|
|
49
55
|
private __isWorldAABBDirty;
|
|
56
|
+
/**
|
|
57
|
+
* Epoch at which this node was last visited by {@link setWorldAABBDirtyParentRecursively}.
|
|
58
|
+
* While it equals the static epoch, this node and all of its ancestors are known to be AABB-dirty,
|
|
59
|
+
* so an upward propagation reaching this node can stop here.
|
|
60
|
+
*/
|
|
61
|
+
private __aabbDirtyChainEpoch;
|
|
62
|
+
/** `__worldMatrixVersion` when logicForce last ran; while unchanged, $logic has nothing to update. */
|
|
63
|
+
private __settledWorldMatrixVersion;
|
|
64
|
+
/** Component creation count when logicForce last ran (a mesh may have been attached since). */
|
|
65
|
+
private __settledComponentCreationCount;
|
|
50
66
|
private _isVisible;
|
|
51
67
|
private _isBillboard;
|
|
52
68
|
private __aabbGizmo?;
|
|
@@ -223,6 +239,10 @@ export declare class SceneGraphComponent extends Component {
|
|
|
223
239
|
* @returns The hierarchy version counter
|
|
224
240
|
*/
|
|
225
241
|
static get hierarchyVersion(): number;
|
|
242
|
+
/**
|
|
243
|
+
* Advances the hierarchy version after a parent-child relationship changed.
|
|
244
|
+
*/
|
|
245
|
+
private static __bumpHierarchyVersion;
|
|
226
246
|
static get componentTID(): 4;
|
|
227
247
|
/**
|
|
228
248
|
* Gets the component type identifier for this instance.
|
|
@@ -257,7 +277,12 @@ export declare class SceneGraphComponent extends Component {
|
|
|
257
277
|
*/
|
|
258
278
|
setWorldMatrixDirtyRecursively(): void;
|
|
259
279
|
/**
|
|
260
|
-
*
|
|
280
|
+
* Marks the world AABB of this node and all of its ancestors as dirty.
|
|
281
|
+
*
|
|
282
|
+
* The walk stops at the first node already marked in the current epoch: that node and all of its
|
|
283
|
+
* ancestors are known to be dirty. Many nodes of the same subtree changing in one frame (e.g. every
|
|
284
|
+
* joint of an animated skeleton) therefore cost O(number of distinct ancestors) in total instead of
|
|
285
|
+
* O(changed nodes * depth).
|
|
261
286
|
*/
|
|
262
287
|
setWorldAABBDirtyParentRecursively(): void;
|
|
263
288
|
/**
|
|
@@ -15,7 +15,14 @@ export declare class ComponentRepository {
|
|
|
15
15
|
private __renderingComponentTIDs;
|
|
16
16
|
static readonly invalidComponentSID = -1;
|
|
17
17
|
private __engine;
|
|
18
|
+
private __componentCreationCount;
|
|
18
19
|
constructor(engine: Engine);
|
|
20
|
+
/**
|
|
21
|
+
* Number of components created in this repository so far, of any type.
|
|
22
|
+
* Consumers compare it with a remembered value to detect that components were attached to entities.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
get _componentCreationCount(): number;
|
|
19
26
|
/**
|
|
20
27
|
* Registers a component class with the repository.
|
|
21
28
|
* This method associates a component class with its unique ComponentTID for later instantiation.
|
|
@@ -79,13 +79,19 @@ export declare function buildLightClustersOnCpu(dst: Float32Array, viewOffset: n
|
|
|
79
79
|
*/
|
|
80
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
81
|
/**
|
|
82
|
-
* The reference implementation of the cluster lookup of the shaders (`getLightList`
|
|
82
|
+
* The reference implementation of the cluster lookup of the shaders (`getLightList` in opticalDefinition.glsl /
|
|
83
|
+
* .wgsl), used by the tests and by CPU-side code that needs the cluster of a position.
|
|
84
|
+
*
|
|
85
|
+
* It reads the same header rows as the shaders, so a change to one form must be made to the other.
|
|
83
86
|
*
|
|
84
87
|
* @returns The cluster index, or -1 when the position uses the all-light list (behind the eye plane or overflow).
|
|
85
88
|
*/
|
|
86
89
|
export declare function computeLightClusterIndex(dst: Float32Array, viewOffset: number, px: number, py: number, pz: number): number;
|
|
87
90
|
/**
|
|
88
91
|
* Reads the light entries of a cluster built by `buildLightClustersOnCpu` (or by the compute shader).
|
|
92
|
+
*
|
|
93
|
+
* This follows the same two-level lookup as the shaders: the table entry gives the vec4 offset and the entry count
|
|
94
|
+
* of the cluster, and the entries themselves are read from the index list from that offset.
|
|
89
95
|
*/
|
|
90
96
|
export declare function readLightClusterEntries(dst: Float32Array, viewOffset: number, layout: LightClusterViewLayout, clusterIndex: number): number[];
|
|
91
97
|
/**
|
|
@@ -58,10 +58,17 @@ export declare const LightClusterLayout: {
|
|
|
58
58
|
export declare function getLightListCapacity(maxLightListLength: number): number;
|
|
59
59
|
/**
|
|
60
60
|
* Returns the array length (in vec4) of the `clusteredLightData` global property.
|
|
61
|
+
*
|
|
62
|
+
* The light entries are read 4 at a time (`entries[n >> 2][n & 3]` in the shaders), so the list is rounded up to
|
|
63
|
+
* whole vec4s: the last vec4 can hold fewer than 4 lights.
|
|
61
64
|
*/
|
|
62
65
|
export declare function getLightClusterGlobalPropertyLength(maxLightListLength: number): number;
|
|
63
66
|
/**
|
|
64
67
|
* Packs a light component SID and a shadow slot into a light entry.
|
|
68
|
+
*
|
|
69
|
+
* The SID is stored in the low 16 bits and `shadowSlot + 1` above them, so -1 (no shadow slot) is representable
|
|
70
|
+
* without a sign. The shaders unpack the same way: `(entry & 0xFFFF, (entry >> 16) - 1)`.
|
|
71
|
+
* The value stays below 2^24, so a float32 stores it exactly.
|
|
65
72
|
*/
|
|
66
73
|
export declare function packLightEntry(lightComponentSid: number, shadowSlot: number): number;
|
|
67
74
|
/**
|
|
@@ -92,6 +99,10 @@ export declare function getLightClusterViewLayout(gridSize: readonly [number, nu
|
|
|
92
99
|
/**
|
|
93
100
|
* Splits the byte range `[start, end)` into the parts outside the excluded ranges.
|
|
94
101
|
*
|
|
102
|
+
* The rendering strategies use this to upload the whole GPU instance data in one call while leaving out the
|
|
103
|
+
* regions owned by the light cluster system: the cluster tables are large, are unchanged for many frames and
|
|
104
|
+
* may be written by compute shaders, so they are uploaded (or not uploaded) separately as dirty ranges.
|
|
105
|
+
*
|
|
95
106
|
* @param excluded - Ranges `[start, end)` sorted by their start
|
|
96
107
|
* @returns The remaining ranges `[start, end)` in ascending order
|
|
97
108
|
*/
|
|
@@ -37,6 +37,17 @@ export type LightClusterGpuBuildParams = {
|
|
|
37
37
|
*
|
|
38
38
|
* The data lives in the GPU instance data, so it is uploaded by the rendering strategy. `dataVersion` changes
|
|
39
39
|
* whenever this system writes the data, and the strategies upload the data when it changes.
|
|
40
|
+
*
|
|
41
|
+
* ## Reading guide (the order of the code below)
|
|
42
|
+
* 1. `update()` is the frame entry point, called by `Engine` after the Logic stage.
|
|
43
|
+
* 2. `__collectLights()` turns the light components into the all-light list (`__entries`) and the light spheres
|
|
44
|
+
* (`__spheres`), and detects whether anything changed since the previous frame.
|
|
45
|
+
* 3. `__writeGlobalData()` publishes the all-light list in the `clusteredLightData` global property.
|
|
46
|
+
* 4. `__collectCameras()` / `__assignViews()` choose the cameras whose fragments use clusters, allocate their
|
|
47
|
+
* view regions (header + cluster table + light index list) and build them (`LightClusterBuilder.ts` on the CPU,
|
|
48
|
+
* `WebGpuLightClusterBuilder.ts` on the GPU).
|
|
49
|
+
* 5. The fragment shaders (`opticalDefinition.glsl` / `.wgsl`, `getLightList`) look up the cluster of a fragment
|
|
50
|
+
* and read its light list. The layout of both the list and the view region is in `LightClusterLayout.ts`.
|
|
40
51
|
*/
|
|
41
52
|
export declare class LightClusterSystem {
|
|
42
53
|
private __engine;
|
|
@@ -142,6 +153,13 @@ export declare class LightClusterSystem {
|
|
|
142
153
|
* @returns true if the lists changed since the previous frame
|
|
143
154
|
*/
|
|
144
155
|
private __collectLights;
|
|
156
|
+
/**
|
|
157
|
+
* Writes the all-light list into the `clusteredLightData` global property.
|
|
158
|
+
*
|
|
159
|
+
* The layout is documented in LightClusterLayout.ts: (allCount, globalCount, localCount, sphereBase) followed by
|
|
160
|
+
* the entries, 4 per vec4. The shaders read the counts from the header: `globalCount` is how many entries they
|
|
161
|
+
* read from the all-light list, and the rest of the list of a clustered fragment comes from the view region.
|
|
162
|
+
*/
|
|
145
163
|
private __writeGlobalData;
|
|
146
164
|
/**
|
|
147
165
|
* Lists the cameras of the render passes that may draw lit materials, in the order of the render passes.
|
|
@@ -166,6 +184,10 @@ export declare class LightClusterSystem {
|
|
|
166
184
|
private __prepareViewBuild;
|
|
167
185
|
/**
|
|
168
186
|
* Allocates a region in the GPU instance data. Returns undefined (and disables the clusters) when it fails.
|
|
187
|
+
*
|
|
188
|
+
* The region is ordinary GPU instance data: the WebGL2 data texture / the WebGPU storage buffer. That is why the
|
|
189
|
+
* shaders can read the table with the same `fetchElement` / `get_clusteredLightData` accessor as any other data,
|
|
190
|
+
* and why the strategies have to skip it in the generic upload (see `_getExcludedByteRanges`).
|
|
169
191
|
*/
|
|
170
192
|
private __allocate;
|
|
171
193
|
}
|