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.
package/README.md CHANGED
@@ -17,6 +17,7 @@ https://librn.com/
17
17
  * Component-oriented
18
18
  * Blittable Memory Architecture (Original GPU data storage system with floating point texture)
19
19
  * Physically-based Rendering with Image-based Lighting
20
+ * Clustered Forward Rendering
20
21
  * Node-based Shader System
21
22
  * Node-based Raymarching System (with integration to polygon rendering)
22
23
  * Support loading the following 3D model files: [glTF2](https://github.com/KhronosGroup/glTF), glTF1, [VRM](https://vrm.dev/en/)
@@ -27,7 +28,6 @@ https://librn.com/
27
28
 
28
29
  ## What's the "Blittable Memory Architecture"
29
30
 
30
-
31
31
  With the Blittable Memory Architecture, Rhodonite stores almost all of its data in a large pre-allocated ArrayBuffer. Data storage for matrix or vector classes in Rhodonite's component classes and materials are assigned from the memory pool, which means most of the data are on that memory pool, transferred to the GPU every frame as a floating-point texture.
32
32
  This architecture allows all shaders always to access a vast amount of data.
33
33
 
@@ -39,10 +39,10 @@ You can try our library via https://editor.librn.com/.
39
39
  This viewer supports glTF/VRM/efkpkg(Effekseer package) files Drag & Drop to display.
40
40
  (Drag & Drop all files if glTF data consists of multiple files.)
41
41
 
42
- Poly model
43
- ![poly](./assets/images/screenshot_poly.jpg)
42
+ Clustered Forward Rendering
43
+ ![poly](./assets/images/screenshot_clustered_forward.jpg)
44
44
 
45
- Advanced PBR
45
+ Advanced PBR with Image-based Lighting
46
46
  ![PBR](./assets/images/screenshot_pbr.jpg)
47
47
 
48
48
  VRM avatar model and VRMA animation
package/VERSION-FILE CHANGED
@@ -1,2 +1,2 @@
1
- v0.22.0-1-ge32bbaa78-dirty
1
+ v0.22.1-1-g3c9f63c3b-dirty
2
2
  main
@@ -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;