rayzee 7.22.6 → 7.22.7
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/dist/rayzee.es.js +93 -73
- package/dist/rayzee.umd.js +22 -22
- package/package.json +1 -1
- package/src/PathTracerApp.js +33 -10
- package/src/Stages/PathTracer.js +64 -8
- package/src/TSL/FinalWriteKernel.js +5 -3
- package/src/managers/DenoisingManager.js +12 -0
- package/src/managers/UniformManager.js +4 -0
package/package.json
CHANGED
package/src/PathTracerApp.js
CHANGED
|
@@ -442,16 +442,7 @@ export class PathTracerApp extends EventDispatcher {
|
|
|
442
442
|
|
|
443
443
|
}
|
|
444
444
|
|
|
445
|
-
|
|
446
|
-
this.denoisingManager?.abort( this.canvas );
|
|
447
|
-
|
|
448
|
-
if ( this.denoisingManager?.restoreBaseResolution() ) {
|
|
449
|
-
|
|
450
|
-
const w = this.denoisingManager._lastRenderWidth;
|
|
451
|
-
const h = this.denoisingManager._lastRenderHeight;
|
|
452
|
-
this.dispatchEvent( { type: 'resolution_changed', width: w, height: h } );
|
|
453
|
-
|
|
454
|
-
}
|
|
445
|
+
this._abortPostProcess();
|
|
455
446
|
|
|
456
447
|
this.completion.reset();
|
|
457
448
|
this.wake();
|
|
@@ -1524,6 +1515,37 @@ export class PathTracerApp extends EventDispatcher {
|
|
|
1524
1515
|
|
|
1525
1516
|
}
|
|
1526
1517
|
|
|
1518
|
+
// Aborts any in-flight denoise/upscale and puts the denoiser canvas back at base resolution (the
|
|
1519
|
+
// upscaler leaves it enlarged), so the live canvas is what's on screen again.
|
|
1520
|
+
_abortPostProcess() {
|
|
1521
|
+
|
|
1522
|
+
this.denoisingManager?.abort( this.canvas );
|
|
1523
|
+
|
|
1524
|
+
if ( this.denoisingManager?.restoreBaseResolution() ) {
|
|
1525
|
+
|
|
1526
|
+
const w = this.denoisingManager._lastRenderWidth;
|
|
1527
|
+
const h = this.denoisingManager._lastRenderHeight;
|
|
1528
|
+
this.dispatchEvent( { type: 'resolution_changed', width: w, height: h } );
|
|
1529
|
+
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
/**
|
|
1535
|
+
* Re-runs the post-process chain (OIDN → upscaler) against the accumulated image. The chain fires once,
|
|
1536
|
+
* on the frame the render completes, so a denoiser switched on afterwards would otherwise never run.
|
|
1537
|
+
*/
|
|
1538
|
+
requestPostProcessRefresh() {
|
|
1539
|
+
|
|
1540
|
+
if ( ! this.stages.pathTracer?.isReady || this._deviceLost ) return;
|
|
1541
|
+
|
|
1542
|
+
this._abortPostProcess();
|
|
1543
|
+
|
|
1544
|
+
this.completion.renderCompleteDispatched = false;
|
|
1545
|
+
this.wake();
|
|
1546
|
+
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1527
1549
|
// ═══════════════════════════════════════════════════════════════
|
|
1528
1550
|
// Deterministic / headless control
|
|
1529
1551
|
// ═══════════════════════════════════════════════════════════════
|
|
@@ -2408,6 +2430,7 @@ export class PathTracerApp extends EventDispatcher {
|
|
|
2408
2430
|
|
|
2409
2431
|
this.denoisingManager.setOverlayManager( this.overlayManager );
|
|
2410
2432
|
this.denoisingManager.setResetCallback( () => this.reset() );
|
|
2433
|
+
this.denoisingManager.setPostProcessRefreshCallback( () => this.requestPostProcessRefresh() );
|
|
2411
2434
|
this.denoisingManager.setSettings( this.settings );
|
|
2412
2435
|
|
|
2413
2436
|
// Expose environment manager (lives on pathTracer stage)
|
package/src/Stages/PathTracer.js
CHANGED
|
@@ -68,6 +68,10 @@ export class PathTracer extends PathTracerStage {
|
|
|
68
68
|
// of the point-sampled per-frame value that leaks noise. Off for fast/ASVGF (they want the bump normal).
|
|
69
69
|
this._cleanAuxNormalEnabled = false;
|
|
70
70
|
this._cleanAuxNormalUniform = uniform( 0, 'uint' );
|
|
71
|
+
// Aux MRT accumulates on an epoch of its own: enabling the denoiser at colour frame N must not leave
|
|
72
|
+
// the stale aux pinned by the colour's 1/(N+1) alpha.
|
|
73
|
+
this._auxSamples = 0;
|
|
74
|
+
this._auxSeedPending = false;
|
|
71
75
|
|
|
72
76
|
// CPU sizes per-bounce kernels from last frame's survivor curve; kernels bound on ENTERING_COUNT so over-sizing is safe. (indirect dispatch not viable — three.js doesn't sync compute-written indirect buffers across submissions)
|
|
73
77
|
this._useDynamicDispatch = true;
|
|
@@ -238,8 +242,17 @@ export class PathTracer extends PathTracerStage {
|
|
|
238
242
|
|
|
239
243
|
if ( this.isComplete || this.frameCount >= this.completionThreshold || this._isConvergedComplete() ) {
|
|
240
244
|
|
|
241
|
-
|
|
242
|
-
|
|
245
|
+
// Denoiser switched on after the render finished — spend one more frame to fill the aux MRT.
|
|
246
|
+
if ( this._auxSeedPending ) {
|
|
247
|
+
|
|
248
|
+
this.isComplete = false;
|
|
249
|
+
|
|
250
|
+
} else {
|
|
251
|
+
|
|
252
|
+
if ( ! this.isComplete ) this.isComplete = true;
|
|
253
|
+
return;
|
|
254
|
+
|
|
255
|
+
}
|
|
243
256
|
|
|
244
257
|
}
|
|
245
258
|
|
|
@@ -283,6 +296,7 @@ export class PathTracer extends PathTracerStage {
|
|
|
283
296
|
}
|
|
284
297
|
|
|
285
298
|
this._updateAccumulationUniforms( frameValue, renderMode );
|
|
299
|
+
const auxMixes = this._updateAuxAccumulationUniforms( frameValue );
|
|
286
300
|
this.frame.value = frameValue;
|
|
287
301
|
this.seedFrame.value = this._seedTick ++;
|
|
288
302
|
|
|
@@ -354,7 +368,8 @@ export class PathTracer extends PathTracerStage {
|
|
|
354
368
|
|
|
355
369
|
// Tier-2 bounce-0 grid size from the stale settled active-pixel count (single-chunk only; else full).
|
|
356
370
|
// Monotonic freeze ⇒ a stale count is a safe over-estimate; reset/camera-move → _curveSizingValid=false.
|
|
357
|
-
|
|
371
|
+
// An aux seed frame must trace every pixel: Generate/Shade skip the G-buffer for frozen ones.
|
|
372
|
+
const adaptiveFreeze = this.usePixelFreeze.value > 0 && ! this._auxSeedPending;
|
|
358
373
|
const activeBounce0 = ( singleChunk && adaptiveFreeze && this._curveSizingValid && this._lastActivePixelCount > 0 )
|
|
359
374
|
? this._lastActivePixelCount : maxRays;
|
|
360
375
|
|
|
@@ -488,6 +503,9 @@ export class PathTracer extends PathTracerStage {
|
|
|
488
503
|
// Don't count interaction-mode (1-SPP feedback) frames toward completion (megakernel parity Stages/PathTracer.js:1240) — else a continuous orbit "completes" on noise.
|
|
489
504
|
if ( ! this.cameraOptimizer?.isInInteractionMode() ) this.frameCount ++;
|
|
490
505
|
|
|
506
|
+
if ( this._auxGBufferEnabled ) this._auxSamples = auxMixes ? this._auxSamples + 1 : 1;
|
|
507
|
+
this._auxSeedPending = false;
|
|
508
|
+
|
|
491
509
|
if ( originalMaxBounces !== null ) this.maxBounces.value = originalMaxBounces;
|
|
492
510
|
|
|
493
511
|
this.performanceMonitor?.end();
|
|
@@ -518,6 +536,8 @@ export class PathTracer extends PathTracerStage {
|
|
|
518
536
|
this._convergedFraction = 0;
|
|
519
537
|
this._convergedGeometryFraction = 0;
|
|
520
538
|
this._lastActivePixelCount = 0;
|
|
539
|
+
this._auxSamples = 0;
|
|
540
|
+
this._auxSeedPending = false;
|
|
521
541
|
|
|
522
542
|
}
|
|
523
543
|
|
|
@@ -585,28 +605,62 @@ export class PathTracer extends PathTracerStage {
|
|
|
585
605
|
}
|
|
586
606
|
|
|
587
607
|
// Aux MRT (normalDepth/albedo) is needed only by the denoiser/OIDN; DenoisingManager calls this to
|
|
588
|
-
// turn the wavefront's aux writes on/off. It's a live uniform, so toggling is just a value flip
|
|
589
|
-
//
|
|
608
|
+
// turn the wavefront's aux writes on/off. It's a live uniform, so toggling is just a value flip —
|
|
609
|
+
// no kernel rebuild, no UI freeze.
|
|
590
610
|
setAuxGBufferEnabled( enabled ) {
|
|
591
611
|
|
|
592
612
|
enabled = !! enabled;
|
|
593
613
|
if ( this._auxGBufferEnabled === enabled ) return;
|
|
594
614
|
this._auxGBufferEnabled = enabled;
|
|
595
615
|
this._auxGBufferUniform.value = enabled ? 1 : 0;
|
|
596
|
-
this.
|
|
616
|
+
this.restartAuxAccumulation();
|
|
597
617
|
|
|
598
618
|
}
|
|
599
619
|
|
|
600
620
|
// Clean-aux normal: when a clean-aux OIDN model is active (calb_cnrm/high, alb_nrm/balanced), FinalWrite
|
|
601
621
|
// temporally accumulates + renormalizes the aux normal so the model isn't fed per-frame point-sampled
|
|
602
|
-
// noise. DenoisingManager calls this on OIDN enable + quality change.
|
|
622
|
+
// noise. DenoisingManager calls this on OIDN enable + quality change. The two modes write the normal in
|
|
623
|
+
// incompatible ways, so the aux buffer has to refill.
|
|
603
624
|
setCleanAuxNormal( enabled ) {
|
|
604
625
|
|
|
605
626
|
enabled = !! enabled;
|
|
606
627
|
if ( this._cleanAuxNormalEnabled === enabled ) return;
|
|
607
628
|
this._cleanAuxNormalEnabled = enabled;
|
|
608
629
|
this._cleanAuxNormalUniform.value = enabled ? 1 : 0;
|
|
609
|
-
this.
|
|
630
|
+
this.restartAuxAccumulation();
|
|
631
|
+
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/** Drops the aux MRT's history, leaving the colour's accumulation intact. */
|
|
635
|
+
restartAuxAccumulation() {
|
|
636
|
+
|
|
637
|
+
this._auxSamples = 0;
|
|
638
|
+
this._auxSeedPending = this._auxGBufferEnabled;
|
|
639
|
+
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* @returns {boolean} whether FinalWrite will MIX the aux this frame rather than seed it.
|
|
644
|
+
*
|
|
645
|
+
* colorAccumulates mirrors FinalWrite's outer gate: when that gate is false the aux is written verbatim
|
|
646
|
+
* regardless, which restarts the epoch. A mismatch costs aux quality only — the shader also reads
|
|
647
|
+
* hasPreviousAux, so it can never mix against textures this epoch has not written.
|
|
648
|
+
*/
|
|
649
|
+
_updateAuxAccumulationUniforms( frameValue ) {
|
|
650
|
+
|
|
651
|
+
const colorAccumulates = this.accumulationEnabled
|
|
652
|
+
&& ! this.cameraIsMoving.value
|
|
653
|
+
&& frameValue > 0
|
|
654
|
+
&& this.hasPreviousAccumulated.value > 0
|
|
655
|
+
&& this.visMode.value !== 11;
|
|
656
|
+
|
|
657
|
+
const mixes = this._auxGBufferEnabled && colorAccumulates
|
|
658
|
+
&& ! this._auxSeedPending && this._auxSamples > 0;
|
|
659
|
+
|
|
660
|
+
this.hasPreviousAux.value = mixes ? 1 : 0;
|
|
661
|
+
this.auxAccumulationAlpha.value = mixes ? 1 / ( this._auxSamples + 1 ) : 1.0;
|
|
662
|
+
|
|
663
|
+
return mixes;
|
|
610
664
|
|
|
611
665
|
}
|
|
612
666
|
|
|
@@ -1483,6 +1537,8 @@ export class PathTracer extends PathTracerStage {
|
|
|
1483
1537
|
enableAccumulation: this.enableAccumulation,
|
|
1484
1538
|
hasPreviousAccumulated: this.hasPreviousAccumulated,
|
|
1485
1539
|
accumulationAlpha: this.accumulationAlpha,
|
|
1540
|
+
hasPreviousAux: this.hasPreviousAux,
|
|
1541
|
+
auxAccumulationAlpha: this.auxAccumulationAlpha,
|
|
1486
1542
|
cameraIsMoving: this.cameraIsMoving,
|
|
1487
1543
|
transparentBackground: this.transparentBackground,
|
|
1488
1544
|
prevAccumTexture: prevColor,
|
|
@@ -37,6 +37,8 @@ export function buildFinalWriteKernel( params ) {
|
|
|
37
37
|
writeColorTex, writeNDTex, writeAlbedoTex,
|
|
38
38
|
resolution, frame,
|
|
39
39
|
enableAccumulation, hasPreviousAccumulated, accumulationAlpha, cameraIsMoving,
|
|
40
|
+
// Aux MRT accumulates on its own epoch; hasPreviousAux=0 → write it verbatim instead of mixing.
|
|
41
|
+
hasPreviousAux, auxAccumulationAlpha,
|
|
40
42
|
transparentBackground,
|
|
41
43
|
prevAccumTexture, prevAlbedoTexture, prevNormalDepthTexture,
|
|
42
44
|
renderWidth,
|
|
@@ -113,10 +115,10 @@ export function buildFinalWriteKernel( params ) {
|
|
|
113
115
|
|
|
114
116
|
// Frozen pixels pass prev colour through unchanged (stale sample); active pixels accumulate.
|
|
115
117
|
finalColor.assign( select( wasFrozen, prevAccumSample.xyz, mix( prevAccumSample.xyz, sampleColor.xyz, accumulationAlpha ) ) );
|
|
116
|
-
If( auxOn, () => {
|
|
118
|
+
If( auxOn.and( hasPreviousAux ), () => {
|
|
117
119
|
|
|
118
120
|
// Albedo averages cleanly (it's a colour).
|
|
119
|
-
finalAlbedo.assign( mix( texture( prevAlbedoTexture, prevUV, 0 ).xyz, finalAlbedo,
|
|
121
|
+
finalAlbedo.assign( mix( texture( prevAlbedoTexture, prevUV, 0 ).xyz, finalAlbedo, auxAccumulationAlpha ) );
|
|
120
122
|
|
|
121
123
|
// NORMAL: by default keep this frame's POINT-SAMPLED normal — it varies with the bump,
|
|
122
124
|
// which fast/ASVGF want to preserve edge detail. But a CLEAN-AUX OIDN model (calb_cnrm/high,
|
|
@@ -129,7 +131,7 @@ export function buildFinalWriteKernel( params ) {
|
|
|
129
131
|
|
|
130
132
|
const prevN = texture( prevNormalDepthTexture, prevUV, 0 ).xyz.mul( 2.0 ).sub( 1.0 );
|
|
131
133
|
const curN = finalNormalDepth.xyz.mul( 2.0 ).sub( 1.0 ).toVar();
|
|
132
|
-
const mixedN = mix( prevN, curN,
|
|
134
|
+
const mixedN = mix( prevN, curN, auxAccumulationAlpha ).toVar();
|
|
133
135
|
const len = length( mixedN );
|
|
134
136
|
const avgN = select( len.greaterThan( 1e-4 ), mixedN.div( len ), curN );
|
|
135
137
|
finalNormalDepth.assign( vec4( avgN.mul( 0.5 ).add( 0.5 ), finalNormalDepth.w ) );
|
|
@@ -50,6 +50,9 @@ export class DenoisingManager extends EventDispatcher {
|
|
|
50
50
|
this.denoiser = null;
|
|
51
51
|
this.upscaler = null;
|
|
52
52
|
|
|
53
|
+
this._onReset = null;
|
|
54
|
+
this._onPostProcessRefresh = null;
|
|
55
|
+
|
|
53
56
|
// Resolution tracking — used for canvas restoration on reset
|
|
54
57
|
this._lastRenderWidth = 0;
|
|
55
58
|
this._lastRenderHeight = 0;
|
|
@@ -547,6 +550,13 @@ export class DenoisingManager extends EventDispatcher {
|
|
|
547
550
|
|
|
548
551
|
}
|
|
549
552
|
|
|
553
|
+
/** @param {Function} fn - () => void, re-runs the completion chain on the accumulated image */
|
|
554
|
+
setPostProcessRefreshCallback( fn ) {
|
|
555
|
+
|
|
556
|
+
this._onPostProcessRefresh = fn;
|
|
557
|
+
|
|
558
|
+
}
|
|
559
|
+
|
|
550
560
|
/** @param {import('../RenderSettings.js').RenderSettings} settings */
|
|
551
561
|
setSettings( settings ) {
|
|
552
562
|
|
|
@@ -620,6 +630,7 @@ export class DenoisingManager extends EventDispatcher {
|
|
|
620
630
|
if ( this.denoiser ) this.denoiser.enabled = enabled;
|
|
621
631
|
// OIDN reads the PathTracer aux MRT; re-sync so the wavefront produces it while OIDN is on.
|
|
622
632
|
this._syncGBufferStages();
|
|
633
|
+
this._onPostProcessRefresh?.();
|
|
623
634
|
|
|
624
635
|
}
|
|
625
636
|
|
|
@@ -629,6 +640,7 @@ export class DenoisingManager extends EventDispatcher {
|
|
|
629
640
|
this.denoiser?.updateQuality( quality );
|
|
630
641
|
// Clean-aux normal follows the model: balanced/high (clean-aux models) → accumulate; fast → keep bump.
|
|
631
642
|
this._stages.pathTracer?.setCleanAuxNormal?.( !! this.denoiser?.enabled && quality !== 'fast' );
|
|
643
|
+
this._onPostProcessRefresh?.();
|
|
632
644
|
|
|
633
645
|
}
|
|
634
646
|
|
|
@@ -196,6 +196,10 @@ export class UniformManager {
|
|
|
196
196
|
ub( 'cameraIsMoving', false );
|
|
197
197
|
ub( 'hasPreviousAccumulated', false );
|
|
198
198
|
|
|
199
|
+
// Aux MRT epoch, separate from the colour's so the denoiser can be enabled mid-render.
|
|
200
|
+
u( 'auxAccumulationAlpha', 1.0, 'float' );
|
|
201
|
+
ub( 'hasPreviousAux', false );
|
|
202
|
+
|
|
199
203
|
// Environment
|
|
200
204
|
u( 'environmentIntensity', DEFAULT_STATE.environmentIntensity, 'float' );
|
|
201
205
|
u( 'backgroundIntensity', DEFAULT_STATE.backgroundIntensity, 'float' );
|