rayzee 5.7.0 → 5.8.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.
@@ -95,6 +95,14 @@ export class NormalDepth extends RenderStage {
95
95
  this._bvhStorageNode = null;
96
96
  this._matStorageNode = null;
97
97
 
98
+ // Last-seen attribute identities. PathTracer replaces these in-place
99
+ // across model load / BVH rebuild; the compute's bind group is locked
100
+ // to whatever buffer was bound at pipeline compile time, so we rebuild
101
+ // when any of them swaps to a new object.
102
+ this._lastTriAttr = null;
103
+ this._lastBvhAttr = null;
104
+ this._lastMatAttr = null;
105
+
98
106
  // Compute node — built once when storage buffers are ready
99
107
  this._computeNode = null;
100
108
  this._computeBuilt = false;
@@ -138,50 +146,59 @@ export class NormalDepth extends RenderStage {
138
146
  const pt = this.pathTracer;
139
147
  if ( ! pt ) return false;
140
148
 
141
- // Triangle storage
149
+ const matStorageAttr = pt.materialData.materialStorageAttr;
150
+
151
+ // Detect attribute identity swap (PathTracer.setTriangleData /
152
+ // setBVHData replace the attribute object on growth). The compute
153
+ // node's bind group is locked to the buffer bound at compile time —
154
+ // updating the storage node's .value alone leaves the GPU binding
155
+ // pointing at the now-discarded buffer, so every traversal misses.
156
+ const triSwapped = pt.triangleStorageAttr && pt.triangleStorageAttr !== this._lastTriAttr;
157
+ const bvhSwapped = pt.bvhStorageAttr && pt.bvhStorageAttr !== this._lastBvhAttr;
158
+ const matSwapped = matStorageAttr && matStorageAttr !== this._lastMatAttr;
159
+
160
+ if ( triSwapped || bvhSwapped || matSwapped ) {
161
+
162
+ // Drop compute + storage nodes so they get rebuilt against the
163
+ // current buffers. Cheap: this only happens on model load.
164
+ this._computeNode?.dispose?.();
165
+ this._computeNode = null;
166
+ this._computeBuilt = false;
167
+ this._triStorageNode = null;
168
+ this._bvhStorageNode = null;
169
+ this._matStorageNode = null;
170
+ this._dirty = true;
171
+
172
+ }
173
+
142
174
  if ( pt.triangleStorageAttr && ! this._triStorageNode ) {
143
175
 
144
176
  this._triStorageNode = storage(
145
177
  pt.triangleStorageAttr, 'vec4', pt.triangleStorageAttr.count
146
178
  ).toReadOnly();
147
179
 
148
- } else if ( pt.triangleStorageAttr && this._triStorageNode ) {
149
-
150
- // Data changed (new model loaded) — update in-place
151
- this._triStorageNode.value = pt.triangleStorageAttr;
152
- this._triStorageNode.bufferCount = pt.triangleStorageAttr.count;
153
-
154
180
  }
155
181
 
156
- // BVH storage
157
182
  if ( pt.bvhStorageAttr && ! this._bvhStorageNode ) {
158
183
 
159
184
  this._bvhStorageNode = storage(
160
185
  pt.bvhStorageAttr, 'vec4', pt.bvhStorageAttr.count
161
186
  ).toReadOnly();
162
187
 
163
- } else if ( pt.bvhStorageAttr && this._bvhStorageNode ) {
164
-
165
- this._bvhStorageNode.value = pt.bvhStorageAttr;
166
- this._bvhStorageNode.bufferCount = pt.bvhStorageAttr.count;
167
-
168
188
  }
169
189
 
170
- // Material storage
171
- const matStorageAttr = pt.materialData.materialStorageAttr;
172
190
  if ( matStorageAttr && ! this._matStorageNode ) {
173
191
 
174
192
  this._matStorageNode = storage(
175
193
  matStorageAttr, 'vec4', matStorageAttr.count
176
194
  ).toReadOnly();
177
195
 
178
- } else if ( matStorageAttr && this._matStorageNode ) {
179
-
180
- this._matStorageNode.value = matStorageAttr;
181
- this._matStorageNode.bufferCount = matStorageAttr.count;
182
-
183
196
  }
184
197
 
198
+ this._lastTriAttr = pt.triangleStorageAttr || this._lastTriAttr;
199
+ this._lastBvhAttr = pt.bvhStorageAttr || this._lastBvhAttr;
200
+ this._lastMatAttr = matStorageAttr || this._lastMatAttr;
201
+
185
202
  return !! ( this._triStorageNode && this._bvhStorageNode && this._matStorageNode );
186
203
 
187
204
  }
@@ -41,7 +41,7 @@ export class DenoisingManager extends EventDispatcher {
41
41
  this.pipeline = pipeline;
42
42
 
43
43
  // Stage references — only used internally for orchestration
44
- this._stages = stages; // { pathTracer, asvgf, variance, bilateralFilter, adaptiveSampling, edgeFilter, ssrc, autoExposure, display }
44
+ this._stages = stages; // { pathTracer, asvgf, variance, bilateralFilter, adaptiveSampling, edgeFilter, ssrc, autoExposure, compositor }
45
45
 
46
46
  this._getExposure = getExposure;
47
47
  this._getSaturation = getSaturation;
@@ -295,9 +295,8 @@ export class DenoisingManager extends EventDispatcher {
295
295
  }
296
296
 
297
297
  /**
298
- * Enables/disables auto-exposure with proper exposure stacking management.
299
298
  * @param {boolean} enabled
300
- * @param {number} manualExposure - The manual exposure value to restore when disabling
299
+ * @param {number} manualExposure - Restored to renderer.toneMappingExposure when disabling.
301
300
  */
302
301
  setAutoExposureEnabled( enabled, manualExposure ) {
303
302
 
@@ -306,19 +305,10 @@ export class DenoisingManager extends EventDispatcher {
306
305
 
307
306
  s.autoExposure.enabled = enabled;
308
307
 
309
- if ( enabled ) {
310
-
311
- // Neutralize Display manual exposure to avoid stacking
312
- s.display?.setExposure( 1.0 );
313
-
314
- } else {
308
+ // AutoExposure overwrites renderer.toneMappingExposure each frame; restore manual on disable.
309
+ if ( ! enabled && this.renderer ) {
315
310
 
316
- s.display?.setExposure( manualExposure );
317
- if ( s.display && this.renderer ) {
318
-
319
- this.renderer.toneMappingExposure = 1.0;
320
-
321
- }
311
+ this.renderer.toneMappingExposure = manualExposure;
322
312
 
323
313
  }
324
314
 
@@ -417,10 +407,10 @@ export class DenoisingManager extends EventDispatcher {
417
407
 
418
408
  } else {
419
409
 
420
- // Re-render display stage so WebGPU canvas has valid content
421
- if ( this.upscaler?.enabled && this._stages.display && context ) {
410
+ // Re-render compositor stage so WebGPU canvas has valid content
411
+ if ( this.upscaler?.enabled && this._stages.compositor && context ) {
422
412
 
423
- this._stages.display.render( context );
413
+ this._stages.compositor.render( context );
424
414
 
425
415
  }
426
416
 
@@ -1,120 +0,0 @@
1
- import { vec4, vec3, uv, uniform, select, dot, mix } from 'three/tsl';
2
- import { MeshBasicNodeMaterial, QuadMesh, TextureNode } from 'three/webgpu';
3
- import { NoBlending } from 'three';
4
- import { RenderStage, StageExecutionMode } from '../Pipeline/RenderStage.js';
5
- import { REC709_LUMINANCE_COEFFICIENTS } from '../TSL/Common.js';
6
-
7
- /**
8
- * Display — Terminal pipeline stage for WebGPU.
9
- *
10
- * Reads the final colour texture from the pipeline context (using a
11
- * priority fallback chain), applies exposure, and renders to screen.
12
- *
13
- * When new post-processing stages are added between PathTracer and
14
- * Display, the fallback chain automatically picks up the latest output
15
- * without any wiring changes.
16
- */
17
- export class Display extends RenderStage {
18
-
19
- constructor( renderer, options = {} ) {
20
-
21
- super( 'Display', {
22
- ...options,
23
- executionMode: StageExecutionMode.ALWAYS
24
- } );
25
-
26
- this.renderer = renderer;
27
-
28
- // Exposure uniform — linear multiplier (consistent with auto-exposure)
29
- this.exposure = uniform( options.exposure ?? 1.0 );
30
-
31
- // Pre-tonemapping saturation — compensates for ACES/AgX desaturation (1.0 = neutral)
32
- this.saturation = uniform( options.saturation ?? 1.0 );
33
-
34
- // Transparent background toggle
35
- this._transparentBackground = uniform( 0, 'int' );
36
-
37
- // Updatable texture node — swap .value each frame, no shader recompile
38
- this._displayTexNode = new TextureNode();
39
-
40
- const texSample = this._displayTexNode.sample( uv() );
41
-
42
- // Build material once (TSL compiles on first render)
43
- const exposed = texSample.xyz.mul( this.exposure );
44
-
45
- // Saturation adjustment (before tonemapping): mix between luminance and color
46
- const luma = dot( exposed, REC709_LUMINANCE_COEFFICIENTS );
47
- let displayShader = mix( vec3( luma ), exposed, this.saturation );
48
-
49
- // Alpha: pass through source alpha when transparent, otherwise 1.0
50
- const outputAlpha = select( this._transparentBackground, texSample.w, 1.0 );
51
-
52
- this.displayMaterial = new MeshBasicNodeMaterial();
53
- this.displayMaterial.colorNode = vec4( displayShader, outputAlpha );
54
- this.displayMaterial.blending = NoBlending;
55
- this.displayMaterial.toneMapped = true;
56
-
57
- this.displayQuad = new QuadMesh( this.displayMaterial );
58
-
59
- }
60
-
61
- /**
62
- * Resolve the best available output texture from the pipeline context.
63
- * Later stages in the chain take priority; pathtracer:color is the
64
- * baseline fallback that is always present.
65
- */
66
- _resolveDisplayTexture( context ) {
67
-
68
- return context.getTexture( 'bloom:output' )
69
- || context.getTexture( 'edgeFiltering:output' )
70
- || context.getTexture( 'asvgf:output' )
71
- || context.getTexture( 'ssrc:output' )
72
- || context.getTexture( 'pathtracer:color' );
73
-
74
- }
75
-
76
- render( context ) {
77
-
78
- if ( ! this.enabled ) return;
79
-
80
- const displayTexture = this._resolveDisplayTexture( context );
81
-
82
- if ( ! displayTexture ) return;
83
-
84
- // Swap texture reference (no shader recompilation)
85
- this._displayTexNode.value = displayTexture;
86
-
87
- // Render to screen
88
- this.renderer.setRenderTarget( null );
89
- this.displayQuad.render( this.renderer );
90
-
91
- }
92
-
93
- setExposure( value ) {
94
-
95
- this.exposure.value = value;
96
-
97
- }
98
-
99
- setSaturation( value ) {
100
-
101
- this.saturation.value = value;
102
-
103
- }
104
-
105
- setTransparentBackground( enabled ) {
106
-
107
- this._transparentBackground.value = enabled ? 1 : 0;
108
-
109
- }
110
-
111
- dispose() {
112
-
113
- this._displayTexNode?.dispose();
114
- this.displayMaterial?.dispose();
115
- // QuadMesh extends Mesh — no dispose method; material already disposed.
116
- this.displayQuad = null;
117
-
118
- }
119
-
120
- }