rhodonite 0.22.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.
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * Measures the GPU time of each frame with the `timestamp-query` feature.
3
3
  *
4
- * Every render pass begun between beginFrame() and endFrame() writes timestamps at its beginning and end;
5
- * the frame's GPU time is the sum of the pass durations. The timestamps are resolved when the command
4
+ * Every render or compute pass begun between beginFrame() and endFrame() writes timestamps at its beginning and
5
+ * end; the frame's GPU time is the sum of the pass durations. The timestamps are resolved when the command
6
6
  * encoder is submitted and read back asynchronously, so `lastGpuTimeMilliseconds` reports the latest
7
- * frame whose results have arrived, not the current one.
7
+ * frame whose results have arrived, not the current one. The duration of each pass label is also published.
8
8
  *
9
9
  * Browsers may quantize timestamps (e.g. to 100µs) unless developer features are enabled.
10
10
  */
@@ -16,25 +16,36 @@ export declare class WebGpuGpuTimer {
16
16
  private __readbackBufferCount;
17
17
  /** Timestamps written by passes recorded into the current command encoder. */
18
18
  private __timestampCount;
19
+ /** The labels of the passes recorded into the current command encoder, one per pass. */
20
+ private __encoderPassLabels;
19
21
  /** The frame the timestamps of the current command encoder belong to. */
20
22
  private __encoderFrame?;
21
23
  private __currentFrame?;
22
24
  private __readbacksToMap;
23
25
  private __lastGpuTimeMilliseconds?;
26
+ private __lastPassGpuTimesMilliseconds?;
24
27
  constructor(device: GPUDevice);
25
28
  /** Whether the device supports timestamp queries. */
26
29
  get isSupported(): boolean;
27
30
  /** The GPU time of the latest measured frame in milliseconds, or undefined if none is available yet. */
28
31
  get lastGpuTimeMilliseconds(): number | undefined;
29
- /** Starts measuring the render passes begun from now on. */
32
+ /**
33
+ * The GPU time of each pass of the latest measured frame in milliseconds, keyed by the pass label.
34
+ * Undefined until a complete frame is available.
35
+ */
36
+ get lastPassGpuTimesMilliseconds(): ReadonlyMap<string, number> | undefined;
37
+ /** Starts measuring the render and compute passes begun from now on. */
30
38
  beginFrame(): void;
31
39
  /** Stops measuring. The frame's time is published once all of its timestamps have been read back. */
32
40
  endFrame(): void;
33
41
  /**
34
- * Returns the timestamp writes to set on a render pass descriptor, or undefined when the pass is not
35
- * measured (outside a frame, or when the query set is full).
42
+ * Returns the timestamp writes to set on a render or compute pass descriptor, or undefined when the
43
+ * pass is not measured (outside a frame, or when the query set is full).
44
+ *
45
+ * @param label - The label of the pass, used to report its duration in
46
+ * {@link WebGpuGpuTimer.lastPassGpuTimesMilliseconds}. Passes with the same label are summed.
36
47
  */
37
- getTimestampWrites(): GPURenderPassTimestampWrites | undefined;
48
+ getTimestampWrites(label: string): GPURenderPassTimestampWrites | undefined;
38
49
  /**
39
50
  * Encodes the resolve of the timestamps written by the passes of `encoder`.
40
51
  * Call this before finishing the encoder, and call afterSubmit() after submitting it.
@@ -1,4 +1,5 @@
1
1
  import type { LightClusterGpuBuildParams } from '../foundation/renderer/lightCluster/LightClusterSystem';
2
+ import type { WebGpuGpuTimer } from './WebGpuGpuTimer';
2
3
  /**
3
4
  * Builds the light cluster tables of Clustered Forward rendering with compute shaders.
4
5
  * The tables are written into the storage buffer of the GPU instance data, where the CPU build would write them.
@@ -25,8 +26,10 @@ export declare class WebGpuLightClusterBuilder {
25
26
  *
26
27
  * @param storageBuffer - The storage buffer of the GPU instance data
27
28
  * @param params - The views to build and their sorted light input
29
+ * @param gpuTimer - When set (and a frame is being measured), measures the build as the
30
+ * 'LightClusterBuild' pass
28
31
  */
29
- build(storageBuffer: GPUBuffer, params: LightClusterGpuBuildParams): void;
32
+ build(storageBuffer: GPUBuffer, params: LightClusterGpuBuildParams, gpuTimer?: WebGpuGpuTimer): void;
30
33
  /**
31
34
  * Releases the GPU resources.
32
35
  */
@@ -41,6 +41,7 @@ export declare class LightComponent extends Component {
41
41
  private __updateCount;
42
42
  private __lastUpdateCount;
43
43
  private __lastTransformUpdateCount;
44
+ private __lastRangeScale;
44
45
  /** The number of changes of all light components, per engine. */
45
46
  private static __updateCountMap;
46
47
  /**
@@ -295,6 +296,12 @@ export declare class LightComponent extends Component {
295
296
  * to avoid unnecessary recalculations when nothing has changed.
296
297
  */
297
298
  $logic(): void;
299
+ /**
300
+ * Returns the intensity factor that compensates the shortened range. The factors are the measured brightness
301
+ * balance of the Sponza scene: 0.9 -> 1.16 and 0.8 -> 1.35. Values in between interpolate; below 0.8 the last
302
+ * slope continues. A constant factor compensates the range window approximately, not exactly.
303
+ */
304
+ private static __getIntensityScale;
298
305
  /**
299
306
  * Returns the range used for shading. Point and spot lights without a range get an automatic range
300
307
  * when `Config.lightAutoRangeThreshold` is greater than 0.
@@ -55,6 +55,8 @@ export declare class SceneGraphComponent extends Component {
55
55
  private __rotationGizmo?;
56
56
  private __scaleGizmo?;
57
57
  private __jointGizmo?;
58
+ /** True when any gizmo of this node has been set up: skips the per-frame gizmo checks of plain nodes. */
59
+ private __hasGizmos;
58
60
  private __transformGizmoSpace;
59
61
  private __latestPrimitivePositionAccessorVersion;
60
62
  toMakeWorldMatrixTheSameAsLocalMatrix: boolean;
@@ -30,6 +30,7 @@ type ConfigInitDescription = {
30
30
  clusteredForwardMinLocalLightNumber?: number;
31
31
  maxLightListLength?: number;
32
32
  lightAutoRangeThreshold?: number;
33
+ lightRangeScale?: number;
33
34
  };
34
35
  /**
35
36
  * Where the light clusters of Clustered Forward rendering are built.
@@ -174,6 +175,39 @@ export declare class Config {
174
175
  * updated next.
175
176
  */
176
177
  lightAutoRangeThreshold: number;
178
+ /**
179
+ * Scales the effective range of the point and spot lights, and raises their intensity to compensate.
180
+ * A shorter range reaches fewer clusters, so fewer fragments evaluate the light in Clustered Forward rendering.
181
+ *
182
+ * @remarks
183
+ * `1` (default) applies no adjustment. The measured presets are:
184
+ *
185
+ * | lightRangeScale | Intensity | GPU frame time (measured) |
186
+ * |-----------------|-----------|----------------------------|
187
+ * | 1 | x1 | 5.5-6.4 ms |
188
+ * | 0.9 | x1.16 | 4.2-4.5 ms (-20 to -24%) |
189
+ * | 0.8 | x1.35 | 3.1-3.2 ms (-43 to -50%) |
190
+ *
191
+ * The measurement is a Sponza scene with 1000 animated point lights (WebGPU, 1920x1080, clustered forward).
192
+ * Intermediate values interpolate the measured intensity factors: `1 -> 1`, `0.9 -> 1.16`, `0.8 -> 1.35`,
193
+ * and below 0.8 the last slope continues. A constant factor cannot compensate the range window exactly: with
194
+ * a shorter range the falloff `(1 - (d / range)^4)^4 / d^2` is slightly dimmer at mid distances, and the lights
195
+ * fade out closer to their centers. 0.9 changes only 0.1% of the pixels by more than 32/255; 0.8 changes about
196
+ * 7% of the pixels that much (the lit area of each light becomes smaller).
197
+ *
198
+ * The engine does not change this value by itself. An application that targets a frame budget can adjust it
199
+ * at runtime (for example, from the measured GPU time and the display refresh interval).
200
+ *
201
+ * Only point and spot lights with a positive effective range are adjusted. Directional lights and lights without
202
+ * a range limit are unchanged. The values of `LightComponent.range` and `LightComponent.intensity` themselves are
203
+ * not modified: only the values uploaded to the GPU (and read by the light clusters and the shaders) are scaled,
204
+ * so all rendering paths see the same light.
205
+ */
206
+ private __lightRangeScale;
207
+ /** See {@link Config.lightRangeScale}. */
208
+ get lightRangeScale(): number;
209
+ /** See {@link Config.lightRangeScale}. */
210
+ set lightRangeScale(value: number);
177
211
  /**
178
212
  * Number of instances of each material type to be placed consecutively in memory.
179
213
  * This is on the memory layout, and the number of material instances that can be generated is not limited by this setting.
@@ -26,6 +26,13 @@ export declare class Transform3D {
26
26
  private __scale;
27
27
  private __rotation;
28
28
  private __updateCount;
29
+ /** The local matrix composed from the current position, rotation and scale. */
30
+ private __matrix;
31
+ private __isMatrixUpToDate;
32
+ /** The position, rotation and scale the cached matrix was composed from (to detect direct inner mutations). */
33
+ private __matrixPosition;
34
+ private __matrixRotation;
35
+ private __matrixScale;
29
36
  private static __tmpMatrix44_0;
30
37
  private static __tmpVector3_0;
31
38
  private static __tmpVector3_1;
@@ -126,9 +133,15 @@ export declare class Transform3D {
126
133
  get rotationInner(): Quaternion;
127
134
  /**
128
135
  * Internal method to increment the update counter when transform changes.
136
+ *
137
+ * A position-only change updates the translation column of the cached matrix instead of invalidating it.
138
+ * Animations that move nodes (the common case with many lights) then avoid the quaternion-to-matrix
139
+ * composition every frame. A rotation or scale change invalidates the matrix.
140
+ *
141
+ * @param change - What changed: `'position'` or everything (`'all'`).
129
142
  * @private
130
143
  */
131
- __updateTransform(): void;
144
+ __updateTransform(change?: 'all' | 'position'): void;
132
145
  /**
133
146
  * Sets the transform from a 4x4 transformation matrix.
134
147
  * Decomposes the matrix into position, rotation, and scale components.
@@ -146,9 +159,20 @@ export declare class Transform3D {
146
159
  * @returns A MutableMatrix44 representing the composed transformation
147
160
  */
148
161
  get matrixInner(): MutableMatrix44;
162
+ /**
163
+ * Composes the local matrix from the current position, rotation and scale and stores it in the cache.
164
+ */
165
+ private __composeMatrix;
166
+ /**
167
+ * Brings the cached matrix up to date. Direct mutations of the inner vectors (positionInner and the like)
168
+ * bypass the setters, so they are detected here: a position-only change updates the translation column, and
169
+ * a rotation or scale change recomposes the matrix.
170
+ */
171
+ private __ensureMatrixUpToDate;
149
172
  /**
150
173
  * Efficiently computes the transformation matrix and stores it in the provided matrix.
151
- * This method avoids memory allocation by reusing an existing matrix object.
174
+ * The composed matrix is cached, so repeated reads (including animated translations) do not
175
+ * recompose the rotation and scale.
152
176
  * @param mat - The target matrix to store the result in
153
177
  */
154
178
  getMatrixInnerTo(mat: MutableMatrix44): void;
@@ -193,10 +193,21 @@ export declare class Engine extends RnObject {
193
193
  * @remarks
194
194
  * Undefined until a result is available, or when {@link gpuTimerEnabled} is false or the environment does
195
195
  * not support GPU timer queries. GPU results arrive asynchronously, so the value lags behind by a few
196
- * frames. In WebGPU it is the sum of the durations of the render passes; in WebGL2 it is the time the GPU
197
- * spent on all the commands issued during process().
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().
198
199
  */
199
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;
200
211
  private __getWebGLGpuTimer;
201
212
  private __beginGpuTimer;
202
213
  private __endGpuTimer;