rayzee 11.6.0 → 11.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.
Files changed (72) hide show
  1. package/README.md +26 -14
  2. package/dist/{ArchiveImporter-iofnC8zB.js → ArchiveImporter-_sJm5uaK.js} +1923 -1243
  3. package/dist/{BidirectionalIntegrator-CqAilt2I.js → BidirectionalIntegrator-Dzt4Z97x.js} +290 -289
  4. package/dist/{ColorManagement-oeEk7oSu.js → ColorManagement-30MfpHwQ.js} +1 -1
  5. package/dist/{EngineIssues-CIZnXHsF.js → EngineIssues-xljoXM0E.js} +18 -8
  6. package/dist/{NeuralRetouch-DFI4pOjO.js → NeuralRetouch-BKQCsmEs.js} +2 -2
  7. package/dist/{NeuralSuperRes-ChCiiilS.js → NeuralSuperRes-C4ymq68e.js} +2 -2
  8. package/dist/{PathTracer-BX4sJLx7.js → PathTracer-C_to_i40.js} +3158 -3102
  9. package/dist/{PhysicalSky-Biv39eTA.js → PhysicalSky-bMHbm_7H.js} +1 -1
  10. package/dist/{RayzeeRenderer-D8XRKU3A.js → RayzeeRenderer-B_aB6VTJ.js} +370 -372
  11. package/dist/SceneMetadata-CSmlJW4c.js +183 -0
  12. package/dist/{ToneMapGPU-sAs8wdgI.js → ToneMapGPU-4GPwoG_c.js} +13 -6
  13. package/dist/addons/archives.es.js +1 -1
  14. package/dist/addons/bidirectional.es.js +1 -1
  15. package/dist/addons/color.es.js +1 -1
  16. package/dist/addons/physical-sky.es.js +1 -1
  17. package/dist/addons/storage.es.js +1 -1
  18. package/dist/{openStorage-Fe9BoS1_.js → openStorage-B085D9FR.js} +1 -1
  19. package/dist/rayzee-core.es.js +5 -5
  20. package/dist/rayzee.es.js +917 -1624
  21. package/dist/rayzee.umd.js +113 -156
  22. package/dist/{sceneCachePolicy-W5PLbzuR.js → sceneCachePolicy-D_uBSbQF.js} +2 -2
  23. package/package.json +1 -1
  24. package/src/EngineIssues.js +20 -6
  25. package/src/Passes/AIUpscaler.js +4 -0
  26. package/src/Passes/OIDNDenoiser.js +17 -17
  27. package/src/PathTracerApp.js +16 -18
  28. package/src/Pipeline/BindingAudit.js +2 -3
  29. package/src/Pipeline/PipelineContext.js +0 -1
  30. package/src/Pipeline/RenderPipeline.js +1 -2
  31. package/src/Pipeline/RenderStage.js +1 -1
  32. package/src/Processor/ArchiveImporter.js +23 -6
  33. package/src/Processor/AssetLoader.js +15 -0
  34. package/src/Processor/LightSerializer.js +6 -2
  35. package/src/Processor/PBRT/PBRTMaterials.js +2 -1
  36. package/src/Processor/PBRT/PBRTSceneBuilder.js +1 -1
  37. package/src/Processor/PackedRayBuffer.js +2 -2
  38. package/src/Processor/PlatformImageLoader.js +9 -0
  39. package/src/Processor/StorageTexturePool.js +1 -1
  40. package/src/Processor/TextureCreator.js +44 -4
  41. package/src/Processor/ToneMapCPU.js +34 -5
  42. package/src/Processor/ToneMapGPU.js +15 -9
  43. package/src/Processor/USD/USDScene.js +981 -17
  44. package/src/RayzeeRenderer.js +82 -27
  45. package/src/Stages/AutoExposure.js +21 -8
  46. package/src/Stages/Compositor.js +39 -1
  47. package/src/Stages/DenoiserSettings.js +5 -81
  48. package/src/Stages/LocalExposure.js +44 -18
  49. package/src/Stages/MotionVector.js +21 -215
  50. package/src/Stages/NormalDepth.js +12 -8
  51. package/src/Stages/PathTracer.js +26 -2
  52. package/src/Stages/PathTracerStage.js +13 -18
  53. package/src/TSL/CameraRay.js +12 -1
  54. package/src/TSL/DebugKernel.js +3 -2
  55. package/src/TSL/FinalWriteKernel.js +6 -9
  56. package/src/TSL/GenerateKernel.js +6 -2
  57. package/src/TSL/LightSplatKernel.js +7 -4
  58. package/src/TSL/LightsCore.js +6 -2
  59. package/src/TSL/LightsSampling.js +45 -12
  60. package/src/TSL/SceneResources.js +11 -0
  61. package/src/TSL/ShadeKernel.js +4 -5
  62. package/src/index.js +1 -1
  63. package/src/integrators/BidirectionalIntegrator.js +1 -0
  64. package/src/managers/CameraManager.js +9 -0
  65. package/src/managers/DenoisingManager.js +79 -187
  66. package/src/managers/InteractionManager.js +6 -0
  67. package/src/managers/UniformManager.js +3 -1
  68. package/dist/SceneMetadata-D2Sh-0e-.js +0 -110
  69. package/src/Stages/ASVGF.js +0 -932
  70. package/src/Stages/BilateralFilter.js +0 -486
  71. package/src/Stages/EdgeFilter.js +0 -545
  72. package/src/Stages/Variance.js +0 -443
@@ -1,7 +1,7 @@
1
1
  import { t as e } from "./EngineEvents-CLckhYbL.js";
2
2
  import { a as t, i as n, r } from "./Logger-dDDGj9Av.js";
3
3
  import { f as i, v as a, y as o } from "./BufferLayout-xPRH9jYD.js";
4
- import { n as s } from "./EngineIssues-CIZnXHsF.js";
4
+ import { n as s } from "./EngineIssues-xljoXM0E.js";
5
5
  import { n as c, r as l } from "./shared-BGBcSxBQ.js";
6
6
  import { n as u } from "./AssetConfig-DSEntE65.js";
7
7
  import { BackSide as d, BufferAttribute as f, Color as p, DoubleSide as m, FrontSide as h, Matrix3 as g, Matrix4 as _, RGBAFormat as v, Vector2 as y, Vector3 as b } from "three";
@@ -1594,7 +1594,7 @@ var vt = class {
1594
1594
  samples: this.samples.slice()
1595
1595
  };
1596
1596
  }
1597
- }, yt = "11.6.0", $ = 1e4, bt = 15e5;
1597
+ }, yt = "11.8.0", $ = 1e4, bt = 15e5;
1598
1598
  function xt(e, t, n = $) {
1599
1599
  return e >= n && t / bt < e / 3;
1600
1600
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rayzee",
3
- "version": "11.6.0",
3
+ "version": "11.8.0",
4
4
  "type": "module",
5
5
  "description": "Real-time WebGPU path tracing engine built on Three.js",
6
6
  "main": "dist/rayzee.umd.js",
@@ -6,6 +6,9 @@
6
6
  */
7
7
  export const ISSUE_CODES = Object.freeze( {
8
8
  ADAPTER_SOFTWARE: 'adapter.software',
9
+ ADAPTER_UNAVAILABLE: 'adapter.unavailable',
10
+ DEVICE_UNAVAILABLE: 'device.unavailable',
11
+ WEBGPU_UNAVAILABLE: 'webgpu.unavailable',
9
12
  ASSET_UNREACHABLE: 'asset.unreachable',
10
13
  ASSET_AMBIGUOUS_ENTRY: 'asset.ambiguous_entry',
11
14
  ASSET_ARCHIVE_TOO_LARGE: 'asset.archive_too_large',
@@ -42,9 +45,9 @@ export const ISSUE_SEVERITY = Object.freeze( { ERROR: 'error', WARNING: 'warning
42
45
 
43
46
  export class EngineIssueError extends Error {
44
47
 
45
- constructor( issue ) {
48
+ constructor( issue, options ) {
46
49
 
47
- super( `[${issue.code}] ${issue.message}` );
50
+ super( `[${issue.code}] ${issue.message}`, options );
48
51
  this.name = 'EngineIssueError';
49
52
  this.code = issue.code;
50
53
  this.detail = issue.detail;
@@ -67,13 +70,24 @@ export class IssueLog {
67
70
  /** @throws {EngineIssueError} when strict and severity is 'error' */
68
71
  record( code, message, detail = {}, severity = ISSUE_SEVERITY.ERROR ) {
69
72
 
70
- const issue = Object.freeze( { code, message, detail, severity, at: Date.now() } );
71
- this._entries.push( issue );
73
+ const issue = this._add( code, message, detail, severity );
74
+ if ( this.strict && severity === ISSUE_SEVERITY.ERROR ) throw new EngineIssueError( issue );
75
+ return issue;
72
76
 
73
- this._onIssue?.( issue );
77
+ }
74
78
 
75
- if ( this.strict && severity === ISSUE_SEVERITY.ERROR ) throw new EngineIssueError( issue );
79
+ /** For what nothing can continue past: records an error and throws it, strict or not. */
80
+ fail( code, message, detail = {}, cause ) {
76
81
 
82
+ throw new EngineIssueError( this._add( code, message, detail, ISSUE_SEVERITY.ERROR ), cause === undefined ? undefined : { cause } );
83
+
84
+ }
85
+
86
+ _add( code, message, detail, severity ) {
87
+
88
+ const issue = Object.freeze( { code, message, detail, severity, at: Date.now() } );
89
+ this._entries.push( issue );
90
+ this._onIssue?.( issue );
77
91
  return issue;
78
92
 
79
93
  }
@@ -78,6 +78,7 @@ export class AIUpscaler extends EventDispatcher {
78
78
  * @param {Function} [options.getGPUTextures] - Returns { color: GPUTexture } for HDR path
79
79
  * @param {Function} [options.getExposure] - Returns current exposure multiplier
80
80
  * @param {Function} [options.getToneMapping] - Returns Three.js ToneMapping constant
81
+ * @param {Function} [options.getTransparentBackground] - Whether the HDR path keeps the render's coverage as alpha
81
82
  * @param {number} [options.tileSize] - Override default tile size
82
83
  */
83
84
  constructor( output, renderer, options = {} ) {
@@ -101,6 +102,7 @@ export class AIUpscaler extends EventDispatcher {
101
102
  this.getToneMapping = options.getToneMapping || ( () => ACESFilmicToneMapping );
102
103
  this.getSaturation = options.getSaturation || ( () => 1.0 );
103
104
  this.getDisplayGain = options.getDisplayGain || ( () => null );
105
+ this.getTransparentBackground = options.getTransparentBackground || ( () => false );
104
106
 
105
107
  // Configuration
106
108
  this.enabled = false;
@@ -506,6 +508,8 @@ export class AIUpscaler extends EventDispatcher {
506
508
  gain: this.getDisplayGain(),
507
509
  } );
508
510
  this._toneMapper.release();
511
+ // The render's alpha is coverage; the canvas shows an opaque backdrop opaque, and so does the upscale.
512
+ if ( ! this.getTransparentBackground() ) planes.fill( 1, 3 * width * height );
509
513
 
510
514
  return { planes, width, height, isHDR: true };
511
515
 
@@ -55,8 +55,8 @@ const MODEL_CONFIG = {
55
55
  DEFAULT_OPTIONS: {
56
56
  enableOIDN: true,
57
57
  oidnQuality: 'fast',
58
- // A cap on the frame, not a tile size: a frame that fits is one tile, with no overlap.
59
- // It bounds the network's activation memory (~430 MB at 1024²).
58
+ // A cap on the frame, not a tile size: a frame no larger in area than this square is one
59
+ // tile, with no overlap. The area bounds the network's activation memory.
60
60
  tileSize: 1024
61
61
  }
62
62
  };
@@ -382,16 +382,14 @@ export class OIDNDenoiser extends EventDispatcher {
382
382
  */
383
383
  _resolveTileSize() {
384
384
 
385
- const longest = Math.max( this._renderWidth, this._renderHeight );
386
- if ( ! longest ) return this.maxTileSize;
385
+ if ( ! this._renderWidth || ! this._renderHeight ) return this.maxTileSize;
387
386
 
388
- // The cap is on the frame, so the border never splits a frame that fits one tile.
389
- if ( longest <= this.maxTileSize ) {
390
-
391
- const input = oidnInputSize( this._renderWidth, this._renderHeight );
392
- return Math.max( input.width, input.height );
393
-
394
- }
387
+ // One tile for any frame no larger in area than the square the cap allows: oidn-web's memory
388
+ // follows the tile's area, not its longest side, so a wide frame needs no split. The cap is on
389
+ // the frame, so the border never splits a frame that fits.
390
+ const input = oidnInputSize( this._renderWidth, this._renderHeight );
391
+ const largest = oidnInputSize( this.maxTileSize, this.maxTileSize );
392
+ if ( input.width * input.height <= largest.width * largest.height ) return Math.max( input.width, input.height );
395
393
 
396
394
  return Math.max( OIDN_TILE_ALIGNMENT, Math.floor( this.maxTileSize / OIDN_TILE_ALIGNMENT ) * OIDN_TILE_ALIGNMENT );
397
395
 
@@ -445,10 +443,10 @@ export class OIDNDenoiser extends EventDispatcher {
445
443
 
446
444
  } while ( this._reloadPending );
447
445
 
448
- // Fire a start() that arrived mid-load. Guard on unet+enabled so a failed load
449
- // or a disable during loading doesn't kick off a denoise. Outside the loop, so a
450
- // no-op reload still releases it — it used to be stranded by the early return below.
451
- if ( this._pendingStart && this.unet && this.enabled ) {
446
+ // Fire a start() that arrived mid-load, unless it was disabled meanwhile. After a failed
447
+ // load too: it denoises nothing but still sends 'end', which its caller waits for. Outside
448
+ // the loop, so a no-op reload still releases it — it used to be stranded by the early return below.
449
+ if ( this._pendingStart && this.enabled ) {
452
450
 
453
451
  const continuous = this._pendingStartContinuous;
454
452
  this._pendingStart = false;
@@ -619,8 +617,6 @@ export class OIDNDenoiser extends EventDispatcher {
619
617
 
620
618
  async execute( continuous = false ) {
621
619
 
622
- if ( ! this.enabled || ! this.unet ) return false;
623
-
624
620
  // Create abort controller for this execution
625
621
  const runId = ++ this._runId;
626
622
  this.state.abortController = new AbortController();
@@ -628,6 +624,10 @@ export class OIDNDenoiser extends EventDispatcher {
628
624
 
629
625
  try {
630
626
 
627
+ // Inside the try, so the finally ends what start() announced: with no weights (a failed
628
+ // load) the Denoising badge, the closing upscaler and a video export waited forever.
629
+ if ( ! this.enabled || ! this.unet ) return false;
630
+
631
631
  // The GPU path bails out early — no textures yet, no device — by returning false, and
632
632
  // a caller that read that as success published a picture nothing had written to.
633
633
  return await this._executeUNetGPU( continuous ) !== false;
@@ -2,13 +2,10 @@ import { Box3, Vector3 } from 'three';
2
2
  import { RayzeeRenderer, describeAdapter, RENDER_CHECKPOINT_VERSION } from './RayzeeRenderer.js';
3
3
  import { NormalDepth } from './Stages/NormalDepth.js';
4
4
  import { MotionVector } from './Stages/MotionVector.js';
5
- import { ASVGF } from './Stages/ASVGF.js';
6
5
  import { NRD } from './Stages/NRD.js';
7
- import { Variance } from './Stages/Variance.js';
8
- import { BilateralFilter } from './Stages/BilateralFilter.js';
9
- import { EdgeFilter } from './Stages/EdgeFilter.js';
10
6
  import { AutoExposure, AUTO_EXPOSURE_DEFAULTS } from './Stages/AutoExposure.js';
11
7
  import { LocalExposure, LOCAL_EXPOSURE_DEFAULTS } from './Stages/LocalExposure.js';
8
+ import { backdropGain } from './Processor/ToneMapCPU.js';
12
9
  import { PRODUCTION_RENDER_CONFIG, INTERACTIVE_RENDER_CONFIG, modePresetSettings } from './EngineDefaults.js';
13
10
  import { createLogger } from './utils/Logger.js';
14
11
  import { EngineEvents } from './EngineEvents.js';
@@ -151,17 +148,12 @@ export class PathTracerApp extends RayzeeRenderer {
151
148
  const { renderer, stages } = this;
152
149
  stages.normalDepth = new NormalDepth( renderer, { pathTracer: stages.pathTracer } );
153
150
  stages.motionVector = new MotionVector( renderer, this.camera, { pathTracer: stages.pathTracer } );
154
- stages.asvgf = new ASVGF( renderer, { enabled: false } );
155
151
  stages.nrd = new NRD( renderer, { enabled: false, pathTracer: stages.pathTracer } );
156
- stages.variance = new Variance( renderer, { enabled: false } );
157
- stages.bilateralFilter = new BilateralFilter( renderer, { enabled: false } );
158
- stages.edgeFilter = new EdgeFilter( renderer, { enabled: false } );
159
152
  stages.autoExposure = new AutoExposure( renderer, { enabled: AUTO_EXPOSURE_DEFAULTS.autoExposure } );
160
153
  stages.localExposure = new LocalExposure( renderer, { enabled: LOCAL_EXPOSURE_DEFAULTS.localExposure } );
161
154
 
162
155
  return [
163
- stages.normalDepth, stages.motionVector, stages.nrd, stages.asvgf,
164
- stages.variance, stages.bilateralFilter, stages.edgeFilter, stages.autoExposure, stages.localExposure,
156
+ stages.normalDepth, stages.motionVector, stages.nrd, stages.autoExposure, stages.localExposure,
165
157
  ];
166
158
 
167
159
  }
@@ -318,7 +310,7 @@ export class PathTracerApp extends RayzeeRenderer {
318
310
 
319
311
  _displaySources() {
320
312
 
321
- return [ 'oidn:output', 'edgeFiltering:output', 'bilateralFiltering:output', 'asvgf:output', 'nrd:output' ];
313
+ return [ 'oidn:output', 'nrd:output' ];
322
314
 
323
315
  }
324
316
 
@@ -332,14 +324,17 @@ export class PathTracerApp extends RayzeeRenderer {
332
324
 
333
325
  if ( this.stages.autoExposure ) this.stages.autoExposure.setCompensation( value );
334
326
  else core.applyExposure( value );
327
+ this.stages.compositor?.setBackdropExposure( value );
335
328
 
336
329
  },
337
330
  onCameraProjection: ( value ) => {
338
331
 
339
332
  this.cameraManager.applyProjection( value );
340
333
  // MotionVector unprojects through projectionMatrixInverse, which is meaningless once every pixel is its
341
- // own direction: fall back to the spatial-only denoiser rather than leaving no strategy.
342
- if ( value === 'equirectangular' && this.denoisingManager?.requiresMotionVectors ) this.denoisingManager.setDenoiserStrategy( 'edgeaware' );
334
+ // own direction: hand the view to OIDN, which needs none, rather than leaving no denoiser.
335
+ if ( value === 'equirectangular' && this.denoisingManager?.requiresMotionVectors ) this.denoisingManager.setDenoiserStrategy( 'oidn' );
336
+ // OIDN's motion history is off in a panorama and back on outside one.
337
+ else this.denoisingManager?._syncGBufferStages?.();
343
338
 
344
339
  },
345
340
  };
@@ -430,7 +425,12 @@ export class PathTracerApp extends RayzeeRenderer {
430
425
  const le = this.stages.localExposure;
431
426
  // A readback outside the loop (headless) can come before the loop would have built it from this image.
432
427
  if ( le?.wantsBuild ) le.build( this.pipeline.context );
433
- return le?.toneGain() ?? null;
428
+ const local = le?.toneGain() ?? null;
429
+ if ( this.pipeline?.context.getState( 'pathtracer:backdrop' ) !== 'color' ) return local;
430
+
431
+ // As the compositor shows it: a solid backdrop at the manual exposure, untouched by auto and local exposure.
432
+ const { toneMappingExposure, toneMapping } = this.renderer;
433
+ return { ...local, backdrop: backdropGain( this.settings.get( 'exposure' ) ?? 1, toneMappingExposure, toneMapping ) };
434
434
 
435
435
  }
436
436
 
@@ -1106,11 +1106,7 @@ export class PathTracerApp extends RayzeeRenderer {
1106
1106
  pathTracer: this.stages.pathTracer,
1107
1107
  normalDepth: this.stages.normalDepth,
1108
1108
  motionVector: this.stages.motionVector,
1109
- asvgf: this.stages.asvgf,
1110
1109
  nrd: this.stages.nrd,
1111
- variance: this.stages.variance,
1112
- bilateralFilter: this.stages.bilateralFilter,
1113
- edgeFilter: this.stages.edgeFilter,
1114
1110
  autoExposure: this.stages.autoExposure,
1115
1111
  compositor: this.stages.compositor,
1116
1112
  },
@@ -1141,6 +1137,8 @@ export class PathTracerApp extends RayzeeRenderer {
1141
1137
  if ( ! ae ) return;
1142
1138
 
1143
1139
  ae.setCompensation( this.settings.get( 'exposure' ) ?? 1 );
1140
+ // A solid backdrop stays at the manual exposure while auto exposure moves the picture.
1141
+ this.stages.compositor.setBackdropExposure( this.settings.get( 'exposure' ) ?? 1 );
1144
1142
  if ( this.stages.localExposure ) this.stages.localExposure.onChange = () => this._refreshFinished();
1145
1143
  ae.onChange = () => this._refreshFinished();
1146
1144
 
@@ -3,13 +3,12 @@
3
3
  *
4
4
  * Two TextureNodes still holding the default EmptyTexture when a stage's kernel is first
5
5
  * compiled can share one GPU binding, which then resolves to whichever is assigned last.
6
- * Nothing throws — the aliased node reads a real texture, just not its own. BilateralFilter
7
- * shipped this way, reading ASVGF's history counter as its variance.
6
+ * Nothing throws — the aliased node reads a real texture, just not its own.
8
7
  *
9
8
  * Rule enforced: every TextureNode a kernel reads must hold its real texture before that
10
9
  * kernel is first dispatched. StorageTexture-typed nodes are exempt — `textureLoad` codegen
11
10
  * only emits the required `level` parameter while the node still holds EmptyTexture, so those
12
- * are deliberately bound after compile (see ASVGF.render).
11
+ * are deliberately bound after compile.
13
12
  *
14
13
  * Off by default; the bench harness turns it on.
15
14
  */
@@ -43,7 +43,6 @@ export class PipelineContext {
43
43
 
44
44
  // Render modes
45
45
  renderMode: 0, // 0 = interactive, 1 = production (full-frame in both)
46
- interactionMode: false,
47
46
  isComplete: false,
48
47
 
49
48
  // Tile rendering
@@ -23,8 +23,7 @@ import { ISSUE_CODES } from '../EngineIssues.js';
23
23
  *
24
24
  * // Add stages in execution order
25
25
  * pipeline.addStage(new PathTracer(...));
26
- * pipeline.addStage(new ASVGF(...));
27
- * pipeline.addStage(new EdgeFilter(...));
26
+ * pipeline.addStage(new NRD(...));
28
27
  *
29
28
  * // Render all stages
30
29
  * pipeline.render(writeBuffer);
@@ -12,7 +12,7 @@ export const StageExecutionMode = {
12
12
 
13
13
  /**
14
14
  * PER_CYCLE - Execute only when tile rendering cycle completes
15
- * Use for: Post-processing, denoisers, filters (ASVGF, EdgeAwareFiltering, OIDN)
15
+ * Use for: Post-processing, denoisers, filters (NRD, OIDN)
16
16
  *
17
17
  * Complete cycle means:
18
18
  * - Progressive mode (renderMode=0): Every frame
@@ -26,9 +26,10 @@ import { loadPBRTScene, pickEntryPath, VirtualFS, PBRT_BUILD_REVISION } from './
26
26
  import { loadUSDScene, listUSDRootLayers, listUSDParts, USDFiles, USDStage, USD_LAYER } from './USD/index.js';
27
27
  import { pfmTexture } from './PBRT/PFM.js';
28
28
  import { extractSceneMetadata } from './SceneMetadata.js';
29
- import { ISSUE_CODES, ISSUE_SEVERITY } from '../EngineIssues.js';
29
+ import { ISSUE_CODES, ISSUE_SEVERITY, EngineIssueError } from '../EngineIssues.js';
30
30
  import { ARCHIVE_FORMATS } from './archiveFormats.js';
31
- import { withHostWorker } from '../Platform.js';
31
+ import { withHostWorker, getPlatform } from '../Platform.js';
32
+ import { platformImageFromBytes } from './PlatformImageLoader.js';
32
33
 
33
34
  const MTL_TEXTURE_TIMEOUT_MS = 30000;
34
35
  const MAIN_MODEL_FILES = [ 'scene.gltf', 'scene.glb', 'model.gltf', 'model.glb', 'main.gltf', 'main.glb', 'asset.gltf', 'asset.glb' ];
@@ -646,6 +647,7 @@ export class ArchiveImporter {
646
647
 
647
648
  const stored = graphKey ? await this._loadStoredGraph( graphKey, source, { imageFromBytes, envFromBytes } ) : null;
648
649
  const built = stored ?? await loadPBRTScene( { vfs: zip, source, entryPath, plyParser, imageFromBytes, envFromBytes, ...shape } );
650
+ this.loader._throwDeferred();
649
651
 
650
652
  const { group, environment, animations, report, warnings, meshCount, entryPath: loadedEntry, candidates,
651
653
  frames, parseMs, buildMs, triangleCount, placementCount, mergedShapes, skippedForBudget,
@@ -729,7 +731,20 @@ export class ArchiveImporter {
729
731
  /** A texture map from an archive, tagged with its path so a stored scene can read it back. @private */
730
732
  async _archiveImage( bytes, fname ) {
731
733
 
732
- const texture = await this._pbrtTextureFromBytes( bytes, fname );
734
+ let texture;
735
+ try {
736
+
737
+ texture = await this._pbrtTextureFromBytes( bytes, fname );
738
+
739
+ } catch ( error ) {
740
+
741
+ // As a glTF's image: its surfaces render untextured, and a strict host hears of it at the end of the load.
742
+ if ( error instanceof EngineIssueError ) throw error;
743
+ this.loader._reportImageFailure( fname, error );
744
+ return null;
745
+
746
+ }
747
+
733
748
  if ( texture ) texture.userData[ ARCHIVE_PATH ] = fname;
734
749
  return texture;
735
750
 
@@ -803,6 +818,7 @@ export class ArchiveImporter {
803
818
  maxTriangles: options.maxTriangles, maxPlacements: options.maxPlacements, mergeShapesAbove: options.mergeShapesAbove,
804
819
  curveSteps: options.curveSteps, curveSides: options.curveSides, curveTolerance: options.curveTolerance,
805
820
  } );
821
+ this.loader._throwDeferred();
806
822
 
807
823
  const { group, environment, warnings, triangleCount, placementCount, skippedForBudget, meshCount, parseMs, buildMs, fitNote } = built;
808
824
  this.lastUSDStats = { parseMs, buildMs, loaderMs: performance.now() - start, triangleCount, placementCount, skippedForBudget, meshCount, fitNote };
@@ -915,9 +931,10 @@ export class ArchiveImporter {
915
931
 
916
932
  } else {
917
933
 
918
- // png / jpg / webp / gif / bmp
919
- const bitmap = await createImageBitmap( new Blob( [ bytes ] ) );
920
- tex = new Texture( bitmap );
934
+ // png / jpg / webp / gif / bmp: the host's decoder where it has one (Node), else the browser's.
935
+ if ( getPlatform().decodeImage ) tex = await platformImageFromBytes( bytes, fname );
936
+ else if ( typeof createImageBitmap === 'function' ) tex = new Texture( await createImageBitmap( new Blob( [ bytes ] ) ) );
937
+ else throw new Error( 'no image decoder in this runtime: configurePlatform( nodePlatform( { decodeImage } ) ) — see "Running in Node"' );
921
938
  tex.colorSpace = SRGBColorSpace;
922
939
 
923
940
  }
@@ -52,6 +52,20 @@ function standInForSplit( source ) {
52
52
 
53
53
  }
54
54
 
55
+ // glTF's znear is a camera's near clipping plane (Blender writes its clip start there): the path tracer honours it.
56
+ export const cameraClipPlugin = {
57
+ name: 'RAYZEE_camera_clip',
58
+ afterRoot( result ) {
59
+
60
+ for ( const scene of result.scenes ) scene.traverse( ( object ) => {
61
+
62
+ if ( object.isCamera && object.near > 0 ) object.userData.clipStart = object.near;
63
+
64
+ } );
65
+
66
+ },
67
+ };
68
+
55
69
  // Luminous efficacy glTF, three.js and Blender's exporter all assume (PBR_WATTS_TO_LUMENS).
56
70
  const LUMENS_PER_WATT = 683;
57
71
 
@@ -768,6 +782,7 @@ export class AssetLoader extends EventDispatcher {
768
782
  if ( getPlatform().decodeImage ) loader.register( ( parser ) => platformImagesPlugin( parser, onImageFailure ) );
769
783
  else if ( ! hasImageDecoder() ) loader.register( ( parser ) => missingImageDecoderPlugin( parser, onImageFailure ) );
770
784
  loader.register( ( parser ) => diffuseTransmissionPlugin( parser ) );
785
+ loader.register( () => cameraClipPlugin );
771
786
 
772
787
  return loader;
773
788
 
@@ -32,6 +32,9 @@ function effectiveEmission( light ) {
32
32
 
33
33
  }
34
34
 
35
+ // A point or spot light's radius (Blender's Radius, USD's SphereLight radius): `userData.radius`, in scene units.
36
+ const lightRadius = ( light ) => Math.max( 0, Number( light.userData?.radius ) || 0 );
37
+
35
38
  export class LightSerializer {
36
39
 
37
40
  constructor() {
@@ -216,7 +219,8 @@ export class LightSerializer {
216
219
  em.r, em.g, em.b, // color (3) — incl. temperature tint
217
220
  em.intensity * INV_4PI, // radiant intensity W/sr = power(W)/4π, incl. exposure (1)
218
221
  light.distance || 0.0, // cutoff distance (0 = infinite) (1)
219
- light.decay !== undefined ? light.decay : 2.0 // decay exponent (1)
222
+ light.decay !== undefined ? light.decay : 2.0, // decay exponent (1)
223
+ lightRadius( light ), // radius: a disc this size facing the lit point, 0 = a point (1)
220
224
  ],
221
225
  importance: importance,
222
226
  light: light
@@ -266,7 +270,7 @@ export class LightSerializer {
266
270
  goboIntensity, // signed gobo strength (1)
267
271
  iesIndex, // IES profile index, -1 = none (1)
268
272
  iesIntensity, // IES blend [0,1] (1)
269
- 0.0, // reserved (1)
273
+ lightRadius( light ), // radius, as a point light's (1)
270
274
  0.0, // reserved (1) — keeps stride at 20 (vec4 aligned)
271
275
  ],
272
276
  importance: importance,
@@ -393,7 +393,8 @@ export async function buildMaterial( def, ctx ) {
393
393
  case 'metal': {
394
394
 
395
395
  await applyConductorColor( mat, params, ctx, '', applyAlbedo, setColor );
396
- await applyRoughness( mat, 'roughness', params, 0.1, ctx );
396
+ // pbrt's roughness defaults to 0, a mirror.
397
+ await applyRoughness( mat, 'roughness', params, 0, ctx );
397
398
  break;
398
399
 
399
400
  }
@@ -108,7 +108,7 @@ const DEFAULT_CURVE_SIDES = { flat: 1, ribbon: 1, cylinder: 2 };
108
108
  const DEFAULT_CURVE_TOLERANCE = 0.05;
109
109
 
110
110
  /** Bumped whenever the same scene files build a different graph, so a stored graph is not reused. */
111
- export const PBRT_BUILD_REVISION = 10;
111
+ export const PBRT_BUILD_REVISION = 11;
112
112
 
113
113
  function samePlacements( a, b ) {
114
114
 
@@ -424,7 +424,7 @@ export const writeMediumStack = ( buf, id, stackDepth, transTraversals, ior1, io
424
424
  ), ior1, ior2, ior3 ) );
425
425
 
426
426
  // Region 7: Beer-Lambert sigmaA (.xyz) of the active medium + DDFA feature-throughput (.w).
427
- // .xyz absorption is gated on stackDepth>0; .w carries the OIDN/ASVGF see-through aux tint (see below).
427
+ // .xyz absorption is gated on stackDepth>0; .w carries the OIDN/NRD see-through aux tint (see below).
428
428
  // Both writers RMW-preserve the other half so sigmaA (live in glass) and featTP never clobber each other.
429
429
  export const readMediumSigmaA = ( buf, id ) => buf.element( soa( id, RAY.MEDIUM_SIGMA_A ) ).xyz;
430
430
 
@@ -436,7 +436,7 @@ export const writeMediumSigmaA = ( buf, id, sigmaA ) => {
436
436
  };
437
437
 
438
438
  // DDFA (Deferred Denoising-Feature Aux) feature-throughput: a clean per-ray tint carried through smooth
439
- // glass/mirror, committed into the OIDN/ASVGF albedo guide at the first diffuse-enough surface. Rides the
439
+ // glass/mirror, committed into the OIDN/NRD albedo guide at the first diffuse-enough surface. Rides the
440
440
  // otherwise-dead MEDIUM_SIGMA_A.w, packed 10/10/10 into 30 bits (top 2 bits zero ⇒ the float bit-pattern is
441
441
  // always finite — never NaN/Inf). LDR [0,1] per channel; final albedo re-quantizes to unorm16 anyway.
442
442
  const pack30 = ( tp ) => {
@@ -97,6 +97,15 @@ export async function loadPlatformImage( url, mimeType = mimeTypeOf( { uri: url
97
97
 
98
98
  }
99
99
 
100
+ /** An image file's bytes as a texture, decoded by the platform: {@link loadPlatformImage} without the fetch. */
101
+ export async function platformImageFromBytes( bytes, filename ) {
102
+
103
+ const texture = pixelTexture( await decodeBytes( bytes, mimeTypeOf( { uri: filename } ) ), { shared: true } );
104
+ texture.flipY = true;
105
+ return texture;
106
+
107
+ }
108
+
100
109
  /**
101
110
  * A GLTFLoader plugin for a runtime with no way to decode an image (Node without `decodeImage`): each image fails with
102
111
  * what to configure, where three.js's own path threw `self is not defined` and took the whole load down.
@@ -7,7 +7,7 @@
7
7
  * - 1 MRT RenderTarget (3 attachments) used as the readable copy
8
8
  * - After each compute dispatch, copyTextureToTexture() transfers data
9
9
  * from StorageTextures → RenderTarget textures
10
- * - Downstream stages (ASVGF, display, OIDN) read from the RenderTarget
10
+ * - Downstream stages (NRD, display, OIDN) read from the RenderTarget
11
11
  * - Previous-frame reads in the path tracer sample from RenderTarget textures
12
12
  * via texture() (not storageTexture().toReadOnly())
13
13
  */
@@ -1,4 +1,4 @@
1
- import { DataArrayTexture, RGBAFormat, LinearFilter, UnsignedByteType, SRGBColorSpace, LinearSRGBColorSpace, RepeatWrapping, FloatType, HalfFloatType } from "three";
1
+ import { DataArrayTexture, RGBAFormat, RGFormat, RedFormat, LinearFilter, UnsignedByteType, UnsignedShortType, SRGBColorSpace, LinearSRGBColorSpace, RepeatWrapping, FloatType, HalfFloatType, DataUtils } from "three";
2
2
  import { MATERIAL_DATA_LAYOUT, BVH_LEAF_MARKERS, assertBVHIndexFits, bvhIndexView } from './BufferLayout.js';
3
3
  import { alignBucketWidth, TEXTURE_CONSTANTS } from './TextureBuckets.js';
4
4
  import { packMaterial } from './MaterialPacking.js';
@@ -1260,7 +1260,7 @@ export class TextureCreator {
1260
1260
 
1261
1261
  const image = texture?.image;
1262
1262
  const pixels = texture?.isCompressedTexture ? texture.mipmaps?.[ 0 ] : image;
1263
- const data = pixels?.data;
1263
+ const data = texture?.isCompressedTexture ? pixels?.data : rgba8Pixels( texture );
1264
1264
  if ( data && pixels.width > 0 && pixels.height > 0 && data.byteLength >= pixels.width * pixels.height * 4 ) {
1265
1265
 
1266
1266
  return { data: new Uint8Array( data.buffer, data.byteOffset, pixels.width * pixels.height * 4 ), width: pixels.width, height: pixels.height, flipY: texture.flipY !== false };
@@ -1817,7 +1817,8 @@ export class TextureCreator {
1817
1817
 
1818
1818
  const idx = normalized.length;
1819
1819
  normalized.push( null );
1820
- bitmapJobs.push( { index: idx, flipY: tex.flipY, promise: _rawPixelsToBitmap( tex.image.data, tex.image.width, tex.image.height ) } );
1820
+ const pixels = rgba8Pixels( tex );
1821
+ bitmapJobs.push( { index: idx, flipY: tex.flipY, promise: pixels ? _rawPixelsToBitmap( pixels, tex.image.width, tex.image.height ) : Promise.reject( new Error( 'pixels in a layout the texture arrays cannot take' ) ) } );
1821
1822
  continue;
1822
1823
 
1823
1824
  }
@@ -1900,10 +1901,49 @@ export class TextureCreator {
1900
1901
  // ── Helpers ──────────────────────────────────────────────────────────
1901
1902
 
1902
1903
  /** Convert raw RGBA pixel data to an ImageBitmap (zero-copy Uint8ClampedArray view). */
1903
- function _rawPixelsToBitmap( data, width, height ) {
1904
+ // Async, so a bad layer rejects into its placeholder instead of throwing through the whole bucket.
1905
+ async function _rawPixelsToBitmap( data, width, height ) {
1904
1906
 
1905
1907
  const clamped = new Uint8ClampedArray( data.buffer, data.byteOffset, data.byteLength );
1906
1908
  return createImageBitmap( new ImageData( clamped, width, height ) );
1907
1909
 
1908
1910
  }
1909
1911
 
1912
+ /**
1913
+ * A data texture's pixels as RGBA8 (the arrays are 8-bit), or null. Float and half-float maps — an archive's EXR, HDR or
1914
+ * PFM — clamp to [0, 1]; one channel fills grey. Read as bytes, a float buffer was noise in Node and failed the bucket in
1915
+ * the browser.
1916
+ */
1917
+ export function rgba8Pixels( texture ) {
1918
+
1919
+ const image = texture?.image;
1920
+ const data = image?.data;
1921
+ if ( ! data || ! ( image.width > 0 ) || ! ( image.height > 0 ) ) return null;
1922
+ const count = image.width * image.height;
1923
+ if ( data instanceof Uint8Array || data instanceof Uint8ClampedArray ) {
1924
+
1925
+ return data.byteLength >= count * 4 ? new Uint8Array( data.buffer, data.byteOffset, count * 4 ) : null;
1926
+
1927
+ }
1928
+
1929
+ const channels = { [ RGBAFormat ]: 4, [ RGFormat ]: 2, [ RedFormat ]: 1 }[ texture.format ] ?? Math.round( data.length / count );
1930
+ if ( ! ( channels >= 1 && channels <= 4 ) || data.length < count * channels ) return null;
1931
+ const half = texture.type === HalfFloatType;
1932
+ const scale = texture.type === UnsignedShortType ? 1 / 65535 : 1;
1933
+ const out = new Uint8Array( count * 4 );
1934
+ for ( let i = 0; i < count; i ++ ) {
1935
+
1936
+ for ( let c = 0; c < 4; c ++ ) {
1937
+
1938
+ const raw = c < channels ? data[ i * channels + c ] : null;
1939
+ const v = raw === null ? ( c === 3 ? 1 : out[ i * 4 ] / 255 ) : ( half ? DataUtils.fromHalfFloat( raw ) : raw * scale );
1940
+ out[ i * 4 + c ] = Math.max( 0, Math.min( 255, Math.round( v * 255 ) ) );
1941
+
1942
+ }
1943
+
1944
+ }
1945
+
1946
+ return out;
1947
+
1948
+ }
1949
+
@@ -98,6 +98,26 @@ export function effectiveExposure( exposure, toneMapping ) {
98
98
 
99
99
  }
100
100
 
101
+ /**
102
+ * The gain that shows a pixel of a solid backdrop at `heldAt` while the picture is shown at `exposure`: auto
103
+ * exposure does not move the backdrop. 1 under a view that applies no exposure.
104
+ */
105
+ export function backdropGain( heldAt, exposure, toneMapping ) {
106
+
107
+ return effectiveExposure( heldAt, toneMapping ) / effectiveExposure( exposure, toneMapping );
108
+
109
+ }
110
+
111
+ /**
112
+ * A pixel's gain once the backdrop is held: `backdrop` where the camera saw only the backdrop (coverage 0), the
113
+ * scene's own gain where it saw the scene, blended by coverage between. The GPU pass computes the same.
114
+ */
115
+ export function heldGain( gain, backdrop, coverage ) {
116
+
117
+ return gain + ( backdrop - gain ) * ( 1 - Math.min( Math.max( coverage, 0 ), 1 ) );
118
+
119
+ }
120
+
101
121
  /** Rec.709 luminance coefficients (same as Display / Common.js). */
102
122
  const LUM_R = 0.2126, LUM_G = 0.7152, LUM_B = 0.0722;
103
123
 
@@ -128,8 +148,9 @@ export function applySaturation( out, saturation ) {
128
148
  * @param {number} options.toneMapping - a registered view transform id
129
149
  * @param {number} [options.saturation=1]
130
150
  * @param {boolean} [options.preserveAlpha=false]
131
- * @param {{fn: function(number, number, number, number): number, width: number, height: number}} [options.pixelGain] -
132
- * the twin of the GPU pass's `gain`: `fn( u, v, luminance, log2 exposure )` per pixel, before the curve
151
+ * @param {{fn?: function(number, number, number, number): number, width: number, height: number, backdrop?: number}} [options.pixelGain] -
152
+ * the twin of the GPU pass's `gain`: `fn( u, v, luminance, log2 exposure )` per pixel, before the curve, and
153
+ * `backdrop` the gain a solid backdrop is held at (`heldGain`)
133
154
  * @returns {Uint8ClampedArray} RGBA bytes
134
155
  */
135
156
  export function toneMapToRGBA8( linear, { exposure, toneMapping, saturation = 1, preserveAlpha = false, pixelGain = null } ) {
@@ -146,9 +167,17 @@ export function toneMapToRGBA8( linear, { exposure, toneMapping, saturation = 1,
146
167
  let g = gain;
147
168
  if ( pixelGain ) {
148
169
 
149
- const p = i >> 2, x = p % pixelGain.width, y = ( p - x ) / pixelGain.width;
150
- const lum = linear[ i ] * 0.2126 + linear[ i + 1 ] * 0.7152 + linear[ i + 2 ] * 0.0722;
151
- g *= pixelGain.fn( ( x + 0.5 ) / pixelGain.width, ( y + 0.5 ) / pixelGain.height, lum, logExposure );
170
+ let pg = 1;
171
+ if ( pixelGain.fn ) {
172
+
173
+ const p = i >> 2, x = p % pixelGain.width, y = ( p - x ) / pixelGain.width;
174
+ const lum = linear[ i ] * 0.2126 + linear[ i + 1 ] * 0.7152 + linear[ i + 2 ] * 0.0722;
175
+ pg = pixelGain.fn( ( x + 0.5 ) / pixelGain.width, ( y + 0.5 ) / pixelGain.height, lum, logExposure );
176
+
177
+ }
178
+
179
+ if ( pixelGain.backdrop > 0 ) pg = heldGain( pg, pixelGain.backdrop, linear[ i + 3 ] );
180
+ g *= pg;
152
181
 
153
182
  }
154
183