@@ -26,8 +26,8 @@ const _props = {};
26
26
// special uniform functions on a standard material
27
27
const _uniforms = { } ;
28
28
29
- // temporary helper array
30
- const _propsSet = [ ] ;
29
+ // temporary set of params
30
+ let _params = new Set ( ) ;
31
31
32
32
/**
33
33
* @class
@@ -358,6 +358,9 @@ class StandardMaterial extends Material {
358
358
this . _assetReferences = { } ;
359
359
this . _validator = null ;
360
360
361
+ this . _activeParams = new Set ( ) ;
362
+ this . _activeLightingParams = new Set ( ) ;
363
+
361
364
this . shaderOptBuilder = new StandardMaterialOptionsBuilder ( ) ;
362
365
363
366
this . reset ( ) ;
@@ -400,8 +403,7 @@ class StandardMaterial extends Material {
400
403
}
401
404
402
405
_setParameter ( name , value ) {
403
- if ( ! this . parameters [ name ] )
404
- _propsSet . push ( name ) ;
406
+ _params . add ( name ) ;
405
407
this . setParameter ( name , value ) ;
406
408
}
407
409
@@ -411,11 +413,17 @@ class StandardMaterial extends Material {
411
413
} ) ;
412
414
}
413
415
414
- _clearParameters ( ) {
415
- _propsSet . forEach ( ( p ) => {
416
- delete this . parameters [ p ] ;
417
- } ) ;
418
- _propsSet . length = 0 ;
416
+ _processParameters ( paramsName ) {
417
+ const prevParams = this [ paramsName ] ;
418
+ for ( const param of prevParams ) {
419
+ if ( ! _params . has ( param ) ) {
420
+ delete this . parameters [ param ] ;
421
+ }
422
+ }
423
+
424
+ this [ paramsName ] = _params ;
425
+ _params = prevParams ;
426
+ _params . clear ( ) ;
419
427
}
420
428
421
429
_updateMap ( p ) {
@@ -447,13 +455,10 @@ class StandardMaterial extends Material {
447
455
}
448
456
449
457
updateUniforms ( device , scene ) {
450
-
451
458
const getUniform = ( name ) => {
452
459
return this . getUniform ( name , device , scene ) ;
453
460
} ;
454
461
455
- this . _clearParameters ( ) ;
456
-
457
462
this . _setParameter ( 'material_ambient' , getUniform ( 'ambient' ) ) ;
458
463
459
464
if ( ! this . diffuseMap || this . diffuseTint ) {
@@ -541,6 +546,9 @@ class StandardMaterial extends Material {
541
546
}
542
547
this . _setParameter ( 'material_reflectivity' , this . reflectivity ) ;
543
548
549
+ // remove unused params
550
+ this . _processParameters ( '_activeParams' ) ;
551
+
544
552
if ( this . _dirtyShader ) {
545
553
this . shader = null ;
546
554
this . clearVariants ( ) ;
@@ -620,6 +628,9 @@ class StandardMaterial extends Material {
620
628
this . _setParameter ( 'cubeMapRotationMatrix' , scene . _skyboxRotationMat3 . data ) ;
621
629
}
622
630
}
631
+
632
+ // remove unused lighting params
633
+ this . _processParameters ( '_activeLightingParams' ) ;
623
634
}
624
635
625
636
updateShader ( device , scene , objDefs , staticLightList , pass , sortedLights ) {
0 commit comments