rayzee 7.7.0 → 7.9.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 (39) hide show
  1. package/README.md +1 -1
  2. package/dist/assets/{BVHSubtreeWorker-D9GImjGj.js → BVHSubtreeWorker-sNzvxn66.js} +2 -2
  3. package/dist/assets/{BVHSubtreeWorker-D9GImjGj.js.map → BVHSubtreeWorker-sNzvxn66.js.map} +1 -1
  4. package/dist/assets/{BVHWorker-CNJ0UBQz.js → BVHWorker-CiVdFrwe.js} +2 -2
  5. package/dist/assets/{BVHWorker-CNJ0UBQz.js.map → BVHWorker-CiVdFrwe.js.map} +1 -1
  6. package/dist/rayzee.es.js +2057 -2035
  7. package/dist/rayzee.es.js.map +1 -1
  8. package/dist/rayzee.umd.js +55 -55
  9. package/dist/rayzee.umd.js.map +1 -1
  10. package/package.json +1 -1
  11. package/src/EngineDefaults.js +45 -1
  12. package/src/EngineEvents.js +1 -0
  13. package/src/Passes/OIDNDenoiser.js +25 -1
  14. package/src/PathTracerApp.js +36 -0
  15. package/src/Processor/AssetLoader.js +3 -0
  16. package/src/Processor/GeometryExtractor.js +35 -9
  17. package/src/Processor/PackedRayBuffer.js +15 -1
  18. package/src/Processor/QueueManager.js +13 -1
  19. package/src/Processor/SceneProcessor.js +176 -113
  20. package/src/Processor/ShaderBuilder.js +6 -24
  21. package/src/Processor/TextureCreator.js +16 -32
  22. package/src/Processor/Workers/BVHWorker.js +6 -1
  23. package/src/Stages/EdgeFilter.js +4 -3
  24. package/src/Stages/MotionVector.js +4 -4
  25. package/src/Stages/NormalDepth.js +20 -30
  26. package/src/Stages/PathTracer.js +20 -40
  27. package/src/TSL/DebugKernel.js +0 -2
  28. package/src/TSL/Debugger.js +1 -8
  29. package/src/TSL/Displacement.js +10 -10
  30. package/src/TSL/GenerateKernel.js +5 -1
  31. package/src/TSL/LightsDirect.js +8 -9
  32. package/src/TSL/LightsIndirect.js +15 -9
  33. package/src/TSL/LightsSampling.js +9 -19
  34. package/src/TSL/Random.js +11 -1
  35. package/src/TSL/ShadeKernel.js +1 -6
  36. package/src/TSL/TextureSampling.js +155 -34
  37. package/src/managers/EnvironmentManager.js +11 -0
  38. package/src/managers/MaterialDataManager.js +71 -39
  39. package/src/managers/RenderTargetManager.js +0 -522
@@ -1,522 +0,0 @@
1
- /**
2
- * RenderTargetManager.js
3
- * Manages render targets, MRT textures, and efficient copying operations
4
- */
5
-
6
- import {
7
- WebGLRenderTarget,
8
- FloatType,
9
- NearestFilter,
10
- LinearSRGBColorSpace,
11
- ShaderMaterial,
12
- GLSL3
13
- } from 'three';
14
- import { FullScreenQuad } from 'three/addons/postprocessing/Pass.js';
15
-
16
- export class RenderTargetManager {
17
-
18
- constructor( width, height, renderer ) {
19
-
20
- this.width = width;
21
- this.height = height;
22
- this.renderer = renderer;
23
-
24
- // Initialize targets to null first
25
- this.currentTarget = null;
26
- this.previousTarget = null;
27
-
28
- // Copy material for efficient final output
29
- this.copyMaterial = null;
30
- this.copyQuad = null;
31
-
32
- // Performance cache for MRT textures
33
- this.mrtTexturesCache = { color: null, normalDepth: null, albedo: null };
34
-
35
- // Create ping-pong MRT targets immediately
36
- this.createTargets( width, height );
37
-
38
- // Verify targets were created successfully
39
- if ( ! this.currentTarget || ! this.previousTarget ) {
40
-
41
- console.error( 'RenderTargetManager: Failed to create render targets!' );
42
- // Create simple fallback targets without MRT
43
- this.createFallbackTargets( width, height );
44
-
45
- }
46
-
47
- }
48
-
49
- /**
50
- * Create unified render targets with MRT support
51
- * @param {number} width - Target width
52
- * @param {number} height - Target height
53
- */
54
- createTargets( width, height ) {
55
-
56
- try {
57
-
58
- const targetOptions = {
59
- minFilter: NearestFilter,
60
- magFilter: NearestFilter,
61
- type: FloatType,
62
- colorSpace: LinearSRGBColorSpace,
63
- depthBuffer: false,
64
- count: 3, // MRT: Color + NormalDepth + Albedo (for OIDN)
65
- samples: 0 // IMPORTANT: No multisampling to avoid blitFramebuffer issues
66
- };
67
-
68
- // Dispose existing targets if they exist
69
- if ( this.currentTarget ) {
70
-
71
- this.currentTarget.dispose();
72
-
73
- }
74
-
75
- if ( this.previousTarget ) {
76
-
77
- this.previousTarget.dispose();
78
-
79
- }
80
-
81
- // Create new targets
82
- this.currentTarget = new WebGLRenderTarget( width, height, targetOptions );
83
- this.previousTarget = new WebGLRenderTarget( width, height, targetOptions );
84
-
85
- // Verify targets have textures
86
- if ( ! this.currentTarget.textures || this.currentTarget.textures.length !== 3 ) {
87
-
88
- throw new Error( 'Current target missing MRT textures' );
89
-
90
- }
91
-
92
- if ( ! this.previousTarget.textures || this.previousTarget.textures.length !== 3 ) {
93
-
94
- throw new Error( 'Previous target missing MRT textures' );
95
-
96
- }
97
-
98
- // Set texture names for debugging
99
- this.currentTarget.textures[ 0 ].name = 'CurrentColor';
100
- this.currentTarget.textures[ 1 ].name = 'CurrentNormalDepth';
101
- this.currentTarget.textures[ 2 ].name = 'CurrentAlbedo';
102
- this.previousTarget.textures[ 0 ].name = 'PreviousColor';
103
- this.previousTarget.textures[ 1 ].name = 'PreviousNormalDepth';
104
- this.previousTarget.textures[ 2 ].name = 'PreviousAlbedo';
105
-
106
- } catch ( error ) {
107
-
108
- console.error( 'RenderTargetManager: Error creating MRT targets:', error );
109
- this.currentTarget = null;
110
- this.previousTarget = null;
111
-
112
- }
113
-
114
- }
115
-
116
- /**
117
- * Create fallback render targets without MRT if main creation fails
118
- * @param {number} width - Target width
119
- * @param {number} height - Target height
120
- */
121
- createFallbackTargets( width, height ) {
122
-
123
- try {
124
-
125
- console.warn( 'RenderTargetManager: Creating fallback targets without MRT' );
126
-
127
- const fallbackOptions = {
128
- minFilter: NearestFilter,
129
- magFilter: NearestFilter,
130
- type: FloatType,
131
- colorSpace: LinearSRGBColorSpace,
132
- depthBuffer: false,
133
- samples: 0
134
- };
135
-
136
- this.currentTarget = new WebGLRenderTarget( width, height, fallbackOptions );
137
- this.previousTarget = new WebGLRenderTarget( width, height, fallbackOptions );
138
-
139
- // Create dummy textures for MRT compatibility
140
- this.currentTarget.textures = [ this.currentTarget.texture, this.currentTarget.texture, this.currentTarget.texture ];
141
- this.previousTarget.textures = [ this.previousTarget.texture, this.previousTarget.texture, this.previousTarget.texture ];
142
-
143
- this.currentTarget.textures[ 0 ].name = 'CurrentColor';
144
- this.currentTarget.textures[ 1 ].name = 'CurrentNormalDepth';
145
- this.currentTarget.textures[ 2 ].name = 'CurrentAlbedo';
146
- this.previousTarget.textures[ 0 ].name = 'PreviousColor';
147
- this.previousTarget.textures[ 1 ].name = 'PreviousNormalDepth';
148
- this.previousTarget.textures[ 2 ].name = 'PreviousAlbedo';
149
-
150
- console.log( 'RenderTargetManager: Fallback targets created successfully' );
151
-
152
- } catch ( error ) {
153
-
154
- console.error( 'RenderTargetManager: Failed to create even fallback targets:', error );
155
-
156
- }
157
-
158
- }
159
-
160
- /**
161
- * Get current accumulated render target
162
- * @returns {WebGLRenderTarget} - Current accumulation target
163
- */
164
- getCurrentAccumulation() {
165
-
166
- this.ensureTargetsReady();
167
- return this.currentTarget;
168
-
169
- }
170
-
171
- /**
172
- * Get current raw sample render target
173
- * @returns {WebGLRenderTarget} - Current raw sample target
174
- */
175
- getCurrentRawSample() {
176
-
177
- this.ensureTargetsReady();
178
- return this.currentTarget;
179
-
180
- }
181
-
182
- /**
183
- * Get MRT textures (color, normal/depth, and albedo)
184
- * @returns {Object} - Object containing color, normalDepth, and albedo textures
185
- */
186
- getMRTTextures() {
187
-
188
- if ( ! this.ensureTargetsReady() ) {
189
-
190
- return {
191
- color: null,
192
- normalDepth: null,
193
- albedo: null
194
- };
195
-
196
- }
197
-
198
- // Reuse cached object to avoid allocation
199
- this.mrtTexturesCache.color = this.currentTarget.textures[ 0 ];
200
- this.mrtTexturesCache.normalDepth = this.currentTarget.textures[ 1 ];
201
- this.mrtTexturesCache.albedo = this.currentTarget.textures[ 2 ];
202
- return this.mrtTexturesCache;
203
-
204
- }
205
-
206
- /**
207
- * Get previous frame textures
208
- * @returns {Object} - Object containing previous frame textures
209
- */
210
- getPreviousTextures() {
211
-
212
- if ( ! this.ensureTargetsReady() ) {
213
-
214
- return {
215
- color: null,
216
- normalDepth: null,
217
- albedo: null
218
- };
219
-
220
- }
221
-
222
- return {
223
- color: this.previousTarget.textures[ 0 ],
224
- normalDepth: this.previousTarget.textures[ 1 ],
225
- albedo: this.previousTarget.textures[ 2 ]
226
- };
227
-
228
- }
229
-
230
- /**
231
- * Swap current and previous targets
232
- */
233
- swapTargets() {
234
-
235
- if ( ! this.ensureTargetsReady() ) {
236
-
237
- return;
238
-
239
- }
240
-
241
- [ this.currentTarget, this.previousTarget ] = [ this.previousTarget, this.currentTarget ];
242
-
243
- }
244
-
245
- /**
246
- * Clear both render targets
247
- */
248
- clearTargets() {
249
-
250
- if ( ! this.ensureTargetsReady() ) {
251
-
252
- return;
253
-
254
- }
255
-
256
- const currentRenderTarget = this.renderer.getRenderTarget();
257
-
258
- this.renderer.setRenderTarget( this.currentTarget );
259
- this.renderer.clear();
260
- this.renderer.setRenderTarget( this.previousTarget );
261
- this.renderer.clear();
262
-
263
- this.renderer.setRenderTarget( currentRenderTarget );
264
-
265
- }
266
-
267
- /**
268
- * Efficiently copy color output to destination target
269
- * @param {WebGLRenderer} renderer - Three.js renderer
270
- * @param {WebGLRenderTarget|null} writeBuffer - Destination target (null for screen)
271
- * @param {boolean} renderToScreen - Whether to render to screen
272
- */
273
- efficientCopyColorOutput( renderer, writeBuffer, renderToScreen = false ) {
274
-
275
- if ( ! this.ensureTargetsReady() ) {
276
-
277
- return;
278
-
279
- }
280
-
281
- // Lazy create copy material and quad
282
- if ( ! this.copyMaterial ) {
283
-
284
- this.copyMaterial = new ShaderMaterial( {
285
- glslVersion: GLSL3,
286
- uniforms: {
287
- tDiffuse: { value: null }
288
- },
289
-
290
- vertexShader: `
291
- // in vec3 position;
292
- // in vec2 uv;
293
- out vec2 vUv;
294
- // uniform mat4 modelViewMatrix;
295
- // uniform mat4 projectionMatrix;
296
-
297
- void main() {
298
- vUv = uv;
299
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
300
- }
301
- `,
302
-
303
- fragmentShader: `
304
- precision highp float;
305
- uniform sampler2D tDiffuse;
306
- in vec2 vUv;
307
- out vec4 pc_fragColor;
308
-
309
- void main() {
310
- pc_fragColor = textureLod( tDiffuse, vUv, 0.0 );
311
- }
312
- `,
313
-
314
- depthTest: false,
315
- depthWrite: false,
316
- transparent: false,
317
- } );
318
-
319
- this.copyQuad = new FullScreenQuad( this.copyMaterial );
320
-
321
- }
322
-
323
- // Set source texture (color output from our MRT)
324
- this.copyMaterial.uniforms.tDiffuse.value = this.currentTarget.textures[ 0 ];
325
-
326
- // Render to destination
327
- renderer.setRenderTarget( renderToScreen ? null : writeBuffer );
328
- this.copyQuad.render( renderer );
329
-
330
- }
331
-
332
- /**
333
- * Copy specific MRT texture to destination
334
- * @param {WebGLRenderer} renderer - Three.js renderer
335
- * @param {number} textureIndex - Index of texture to copy (0 = color, 1 = normal/depth)
336
- * @param {WebGLRenderTarget|null} writeBuffer - Destination target
337
- */
338
- copyMRTTexture( renderer, textureIndex, writeBuffer ) {
339
-
340
- if ( ! this.ensureTargetsReady() ) {
341
-
342
- return;
343
-
344
- }
345
-
346
- if ( ! this.copyMaterial ) {
347
-
348
- this.efficientCopyColorOutput( renderer, null, false ); // Initialize copy material
349
-
350
- }
351
-
352
- this.copyMaterial.uniforms.tDiffuse.value = this.currentTarget.textures[ textureIndex ];
353
- renderer.setRenderTarget( writeBuffer );
354
- this.copyQuad.render( renderer );
355
-
356
- }
357
-
358
- /**
359
- * Resize render targets
360
- * @param {number} width - New width
361
- * @param {number} height - New height
362
- */
363
- setSize( width, height ) {
364
-
365
- this.width = width;
366
- this.height = height;
367
-
368
- // Recreate targets with new size
369
- this.createTargets( width, height );
370
-
371
- // Verify creation was successful
372
- if ( ! this.isValid() ) {
373
-
374
- console.warn( 'RenderTargetManager: Failed to resize targets, creating fallback...' );
375
- this.createFallbackTargets( width, height );
376
-
377
- }
378
-
379
- }
380
-
381
- /**
382
- * Get target dimensions
383
- * @returns {Object} - Object containing width and height
384
- */
385
- getSize() {
386
-
387
- return {
388
- width: this.width,
389
- height: this.height
390
- };
391
-
392
- }
393
-
394
- /**
395
- * Check if targets are valid and properly sized
396
- * @returns {boolean} - True if targets are valid
397
- */
398
- isValid() {
399
-
400
- return this.currentTarget &&
401
- this.previousTarget &&
402
- this.currentTarget.textures &&
403
- this.previousTarget.textures &&
404
- this.currentTarget.width === this.width &&
405
- this.currentTarget.height === this.height &&
406
- this.previousTarget.width === this.width &&
407
- this.previousTarget.height === this.height;
408
-
409
- }
410
-
411
- /**
412
- * Ensure targets are ready before operations
413
- * @returns {boolean} - True if targets are ready
414
- */
415
- ensureTargetsReady() {
416
-
417
- if ( ! this.isValid() ) {
418
-
419
- console.warn( 'RenderTargetManager: Targets not ready, attempting to recreate...' );
420
- this.createTargets( this.width, this.height );
421
-
422
- if ( ! this.isValid() ) {
423
-
424
- this.createFallbackTargets( this.width, this.height );
425
-
426
- }
427
-
428
- }
429
-
430
- return this.isValid();
431
-
432
- }
433
-
434
- /**
435
- * Get memory usage information
436
- * @returns {Object} - Memory usage statistics
437
- */
438
- getMemoryUsage() {
439
-
440
- const bytesPerPixel = 16; // 4 channels * 4 bytes (Float32) per channel
441
- const pixelsPerTarget = this.width * this.height;
442
- const texturesPerTarget = 3; // MRT: color + normal/depth + albedo
443
- const targetCount = 2; // current + previous
444
-
445
- const totalBytes = pixelsPerTarget * bytesPerPixel * texturesPerTarget * targetCount;
446
-
447
- return {
448
- totalBytes,
449
- totalMB: totalBytes / ( 1024 * 1024 ),
450
- perTargetMB: ( totalBytes / targetCount ) / ( 1024 * 1024 ),
451
- width: this.width,
452
- height: this.height,
453
- textureCount: texturesPerTarget * targetCount
454
- };
455
-
456
- }
457
-
458
- /**
459
- * Create debug info for render targets
460
- * @returns {Object} - Debug information
461
- */
462
- getDebugInfo() {
463
-
464
- return {
465
- currentTarget: {
466
- width: this.currentTarget.width,
467
- height: this.currentTarget.height,
468
- textureCount: this.currentTarget.textures.length,
469
- textureNames: this.currentTarget.textures.map( tex => tex.name )
470
- },
471
- previousTarget: {
472
- width: this.previousTarget.width,
473
- height: this.previousTarget.height,
474
- textureCount: this.previousTarget.textures.length,
475
- textureNames: this.previousTarget.textures.map( tex => tex.name )
476
- },
477
- memoryUsage: this.getMemoryUsage()
478
- };
479
-
480
- }
481
-
482
- /**
483
- * Dispose of all resources
484
- */
485
- dispose() {
486
-
487
- // Dispose render targets
488
- if ( this.currentTarget ) {
489
-
490
- this.currentTarget.dispose();
491
- this.currentTarget = null;
492
-
493
- }
494
-
495
- if ( this.previousTarget ) {
496
-
497
- this.previousTarget.dispose();
498
- this.previousTarget = null;
499
-
500
- }
501
-
502
- // Dispose copy materials
503
- if ( this.copyMaterial ) {
504
-
505
- this.copyMaterial.dispose();
506
- this.copyMaterial = null;
507
-
508
- }
509
-
510
- if ( this.copyQuad ) {
511
-
512
- this.copyQuad.dispose();
513
- this.copyQuad = null;
514
-
515
- }
516
-
517
- // Clear caches
518
- this.mrtTexturesCache = { color: null, normalDepth: null, albedo: null };
519
-
520
- }
521
-
522
- }