@@ -44,6 +44,7 @@ const EXTRA_LOD_SIGMA = [ 0.125, 0.215, 0.35, 0.446, 0.526, 0.582 ];
44
44
const MAX_SAMPLES = 20 ;
45
45
46
46
const _flatCamera = /*@__PURE__ */ new OrthographicCamera ( - 1 , 1 , 1 , - 1 , 0 , 1 ) ;
47
+ const _cubeCamera = /*@__PURE__ */ new PerspectiveCamera ( 90 , 1 ) ;
47
48
const _clearColor = /*@__PURE__ */ new Color ( ) ;
48
49
let _oldTarget = null ;
49
50
let _oldActiveCubeFace = 0 ;
@@ -106,10 +107,12 @@ class PMREMGenerator {
106
107
this . _lodPlanes = [ ] ;
107
108
this . _sizeLods = [ ] ;
108
109
this . _sigmas = [ ] ;
110
+ this . _lodMeshes = [ ] ;
109
111
110
112
this . _blurMaterial = null ;
111
113
this . _cubemapMaterial = null ;
112
114
this . _equirectMaterial = null ;
115
+ this . _backgroundBox = null ;
113
116
114
117
}
115
118
@@ -210,6 +213,12 @@ class PMREMGenerator {
210
213
211
214
if ( this . _cubemapMaterial !== null ) this . _cubemapMaterial . dispose ( ) ;
212
215
if ( this . _equirectMaterial !== null ) this . _equirectMaterial . dispose ( ) ;
216
+ if ( this . _backgroundBox !== null ) {
217
+
218
+ this . _backgroundBox . geometry . dispose ( ) ;
219
+ this . _backgroundBox . material . dispose ( ) ;
220
+
221
+ }
213
222
214
223
}
215
224
@@ -297,7 +306,7 @@ class PMREMGenerator {
297
306
this . _pingPongRenderTarget = _createRenderTarget ( width , height , params ) ;
298
307
299
308
const { _lodMax } = this ;
300
- ( { sizeLods : this . _sizeLods , lodPlanes : this . _lodPlanes , sigmas : this . _sigmas } = _createPlanes ( _lodMax ) ) ;
309
+ ( { sizeLods : this . _sizeLods , lodPlanes : this . _lodPlanes , sigmas : this . _sigmas , lodMeshes : this . _lodMeshes } = _createPlanes ( _lodMax ) ) ;
301
310
302
311
this . _blurMaterial = _getBlurShader ( _lodMax , width , height ) ;
303
312
@@ -309,16 +318,18 @@ class PMREMGenerator {
309
318
310
319
_compileMaterial ( material ) {
311
320
312
- const tmpMesh = new Mesh ( this . _lodPlanes [ 0 ] , material ) ;
321
+ const tmpMesh = this . _lodMeshes [ 0 ] ;
322
+ tmpMesh . material = material ;
323
+
313
324
this . _renderer . compile ( tmpMesh , _flatCamera ) ;
314
325
315
326
}
316
327
317
328
_sceneToCubeUV ( scene , near , far , cubeUVRenderTarget ) {
318
329
319
- const fov = 90 ;
320
- const aspect = 1 ;
321
- const cubeCamera = new PerspectiveCamera ( fov , aspect , near , far ) ;
330
+ const cubeCamera = _cubeCamera ;
331
+ cubeCamera . near = near ;
332
+ cubeCamera . far = far ;
322
333
323
334
// px, py, pz, nx, ny, nz
324
335
const upSign = [ - 1 , 1 , - 1 , - 1 , - 1 , - 1 ] ;
@@ -333,14 +344,20 @@ class PMREMGenerator {
333
344
renderer . toneMapping = NoToneMapping ;
334
345
renderer . autoClear = false ;
335
346
336
- const backgroundMaterial = new MeshBasicMaterial ( {
337
- name : 'PMREM.Background' ,
338
- side : BackSide ,
339
- depthWrite : false ,
340
- depthTest : false
341
- } ) ;
347
+ let backgroundBox = this . _backgroundBox ;
342
348
343
- const backgroundBox = new Mesh ( new BoxGeometry ( ) , backgroundMaterial ) ;
349
+ if ( backgroundBox === null ) {
350
+
351
+ const backgroundMaterial = new MeshBasicMaterial ( {
352
+ name : 'PMREM.Background' ,
353
+ side : BackSide ,
354
+ depthWrite : false ,
355
+ depthTest : false
356
+ } ) ;
357
+
358
+ backgroundBox = new Mesh ( new BoxGeometry ( ) , backgroundMaterial ) ;
359
+
360
+ }
344
361
345
362
let useSolidColor = false ;
346
363
const background = scene . background ;
@@ -349,15 +366,15 @@ class PMREMGenerator {
349
366
350
367
if ( background . isColor ) {
351
368
352
- backgroundMaterial . color . copy ( background ) ;
369
+ backgroundBox . material . color . copy ( background ) ;
353
370
scene . background = null ;
354
371
useSolidColor = true ;
355
372
356
373
}
357
374
358
375
} else {
359
376
360
- backgroundMaterial . color . copy ( _clearColor ) ;
377
+ backgroundBox . material . color . copy ( _clearColor ) ;
361
378
useSolidColor = true ;
362
379
363
380
}
@@ -401,9 +418,6 @@ class PMREMGenerator {
401
418
402
419
}
403
420
404
- backgroundBox . geometry . dispose ( ) ;
405
- backgroundBox . material . dispose ( ) ;
406
-
407
421
renderer . toneMapping = toneMapping ;
408
422
renderer . autoClear = originalAutoClear ;
409
423
scene . background = background ;
@@ -435,10 +449,11 @@ class PMREMGenerator {
435
449
}
436
450
437
451
const material = isCubeTexture ? this . _cubemapMaterial : this . _equirectMaterial ;
438
- const mesh = new Mesh ( this . _lodPlanes [ 0 ] , material ) ;
439
-
440
452
material . fragmentNode . value = texture ;
441
453
454
+ const mesh = this . _lodMeshes [ 0 ] ;
455
+ mesh . material = material ;
456
+
442
457
const size = this . _cubeSize ;
443
458
444
459
_setViewport ( cubeUVRenderTarget , 0 , 0 , 3 * size , 2 * size ) ;
@@ -506,15 +521,16 @@ class PMREMGenerator {
506
521
507
522
if ( direction !== 'latitudinal' && direction !== 'longitudinal' ) {
508
523
509
- console . error (
510
- 'blur direction must be either latitudinal or longitudinal!' ) ;
524
+ console . error ( 'blur direction must be either latitudinal or longitudinal!' ) ;
511
525
512
526
}
513
527
514
528
// Number of standard deviations at which to cut off the discrete approximation.
515
529
const STANDARD_DEVIATIONS = 3 ;
516
530
517
- const blurMesh = new Mesh ( this . _lodPlanes [ lodOut ] , blurMaterial ) ;
531
+ const blurMesh = this . _lodMeshes [ lodOut ] ;
532
+ blurMesh . material = blurMaterial ;
533
+
518
534
const blurUniforms = blurMaterial . uniforms ;
519
535
520
536
const pixels = this . _sizeLods [ lodIn ] - 1 ;
@@ -557,6 +573,8 @@ class PMREMGenerator {
557
573
558
574
}
559
575
576
+ targetIn . texture . frame = ( targetIn . texture . frame || 0 ) + 1 ;
577
+
560
578
blurUniforms . envMap . value = targetIn . texture ;
561
579
blurUniforms . samples . value = samples ;
562
580
blurUniforms . weights . array = weights ;
@@ -589,6 +607,7 @@ function _createPlanes( lodMax ) {
589
607
const lodPlanes = [ ] ;
590
608
const sizeLods = [ ] ;
591
609
const sigmas = [ ] ;
610
+ const lodMeshes = [ ] ;
592
611
593
612
let lod = lodMax ;
594
613
@@ -653,6 +672,7 @@ function _createPlanes( lodMax ) {
653
672
planes . setAttribute ( 'uv' , new BufferAttribute ( uv , uvSize ) ) ;
654
673
planes . setAttribute ( 'faceIndex' , new BufferAttribute ( faceIndex , faceIndexSize ) ) ;
655
674
lodPlanes . push ( planes ) ;
675
+ lodMeshes . push ( new Mesh ( planes , null ) ) ;
656
676
657
677
if ( lod > LOD_MIN ) {
658
678
@@ -662,7 +682,7 @@ function _createPlanes( lodMax ) {
662
682
663
683
}
664
684
665
- return { lodPlanes, sizeLods, sigmas } ;
685
+ return { lodPlanes, sizeLods, sigmas, lodMeshes } ;
666
686
667
687
}
668
688
0 commit comments