Skip to content

Commit ad24fe9

Browse files
authored
Track active StandardMaterial parameters correctly (playcanvas#3455)
* track parameters better * changes based on feedback
1 parent ebf64d5 commit ad24fe9

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

src/scene/materials/standard-material.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ const _props = {};
2626
// special uniform functions on a standard material
2727
const _uniforms = {};
2828

29-
// temporary helper array
30-
const _propsSet = [];
29+
// temporary set of params
30+
let _params = new Set();
3131

3232
/**
3333
* @class
@@ -358,6 +358,9 @@ class StandardMaterial extends Material {
358358
this._assetReferences = {};
359359
this._validator = null;
360360

361+
this._activeParams = new Set();
362+
this._activeLightingParams = new Set();
363+
361364
this.shaderOptBuilder = new StandardMaterialOptionsBuilder();
362365

363366
this.reset();
@@ -400,8 +403,7 @@ class StandardMaterial extends Material {
400403
}
401404

402405
_setParameter(name, value) {
403-
if (!this.parameters[name])
404-
_propsSet.push(name);
406+
_params.add(name);
405407
this.setParameter(name, value);
406408
}
407409

@@ -411,11 +413,17 @@ class StandardMaterial extends Material {
411413
});
412414
}
413415

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();
419427
}
420428

421429
_updateMap(p) {
@@ -447,13 +455,10 @@ class StandardMaterial extends Material {
447455
}
448456

449457
updateUniforms(device, scene) {
450-
451458
const getUniform = (name) => {
452459
return this.getUniform(name, device, scene);
453460
};
454461

455-
this._clearParameters();
456-
457462
this._setParameter('material_ambient', getUniform('ambient'));
458463

459464
if (!this.diffuseMap || this.diffuseTint) {
@@ -541,6 +546,9 @@ class StandardMaterial extends Material {
541546
}
542547
this._setParameter('material_reflectivity', this.reflectivity);
543548

549+
// remove unused params
550+
this._processParameters('_activeParams');
551+
544552
if (this._dirtyShader) {
545553
this.shader = null;
546554
this.clearVariants();
@@ -620,6 +628,9 @@ class StandardMaterial extends Material {
620628
this._setParameter('cubeMapRotationMatrix', scene._skyboxRotationMat3.data);
621629
}
622630
}
631+
632+
// remove unused lighting params
633+
this._processParameters('_activeLightingParams');
623634
}
624635

625636
updateShader(device, scene, objDefs, staticLightList, pass, sortedLights) {

0 commit comments

Comments
 (0)