Browse Source

removing cachedDefines and using a isDirty based approach

David Catuhe 8 years ago
parent
commit
589df67fbc

+ 1 - 0
src/Materials/babylon.material.ts

@@ -1,6 +1,7 @@
 module BABYLON {
     export class MaterialDefines {
         _keys: string[];
+        _isDirty = true;
 
         public rebuild() {
             if (this._keys) {

+ 13 - 1
src/Materials/babylon.materialHelper.ts

@@ -11,6 +11,9 @@
                 var light = scene.lights[index];
 
                 if (!light.isEnabled()) {
+                    if (defines["LIGHT" + lightIndex] !== undefined) {
+                        defines["LIGHT" + lightIndex] = undefined;
+                    }
                     continue;
                 }
 
@@ -41,6 +44,9 @@
                 }
 
                 if (!light.canAffectMesh(mesh)) {
+                    if (defines["LIGHT" + lightIndex] !== undefined) {
+                        defines["LIGHT" + lightIndex] = undefined;
+                    }
                     continue;
                 }
                 needNormals = true;
@@ -48,7 +54,6 @@
                 if (defines["LIGHT" + lightIndex] === undefined) {
                     needRebuild = true;
                 }
-
                 defines["LIGHT" + lightIndex] = true;
 
                 var type;
@@ -122,6 +127,13 @@
                     break;
             }
 
+            // Resetting all other lights if any
+            for (var index = scene.lights.length; index < maxSimultaneousLights; index++) {
+                if (defines["LIGHT" + lightIndex] !== undefined) {
+                    defines["LIGHT" + lightIndex] = undefined;
+                }
+            }
+
             let caps = scene.getEngine().getCaps();
             if (needShadows && caps.textureFloat && caps.textureFloatLinearFiltering && caps.textureFloatRender) {
                 if (defines["SHADOWFULLFLOAT"] === undefined) {

+ 1 - 8
src/Materials/babylon.standardMaterial.ts

@@ -212,15 +212,12 @@ module BABYLON {
         protected _renderId: number;
 
         protected _defines = new StandardMaterialDefines();
-        protected _cachedDefines = new StandardMaterialDefines();
 
         protected _useLogarithmicDepth: boolean;
 
         constructor(name: string, scene: Scene) {
             super(name, scene);
 
-            this._cachedDefines.BonesPerMesh = -1;
-
             this.getRenderTargetTextures = (): SmartArray<RenderTargetTexture> => {
                 this._renderTargets.reset();
 
@@ -294,8 +291,6 @@ module BABYLON {
             var needUVs = false;
             var needNormals = false;
 
-            this._defines.reset();
-
             // Lights
             if (scene.lightsEnabled && !this.disableLighting) {
                 needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, this.maxSimultaneousLights);
@@ -590,9 +585,7 @@ module BABYLON {
             }
 
             // Get correct effect      
-            if (!this._defines.isEqual(this._cachedDefines)) {
-                this._defines.cloneTo(this._cachedDefines);
-
+            if (this._defines._isDirty) {
                 scene.resetCachedMaterial();
 
                 // Fallbacks