瀏覽代碼

PrepareAttributesForInstances

David Catuhe 9 年之前
父節點
當前提交
030a1e648d

文件差異過大導致無法顯示
+ 1 - 1
dist/preview release/babylon.core.js


文件差異過大導致無法顯示
+ 2580 - 2579
dist/preview release/babylon.d.ts


文件差異過大導致無法顯示
+ 1 - 1
dist/preview release/babylon.js


+ 9 - 6
dist/preview release/babylon.max.js

@@ -19949,6 +19949,14 @@ var BABYLON;
                 }
             }
         };
+        StandardMaterial.PrepareAttributesForInstances = function (attribs, defines) {
+            if (defines["INSTANCES"]) {
+                attribs.push("world0");
+                attribs.push("world1");
+                attribs.push("world2");
+                attribs.push("world3");
+            }
+        };
         StandardMaterial.prototype.isReady = function (mesh, useInstances) {
             if (this.isFrozen) {
                 if (this._wasPreviouslyReady) {
@@ -20242,12 +20250,7 @@ var BABYLON;
                     attribs.push(BABYLON.VertexBuffer.ColorKind);
                 }
                 StandardMaterial.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
-                if (this._defines.INSTANCES) {
-                    attribs.push("world0");
-                    attribs.push("world1");
-                    attribs.push("world2");
-                    attribs.push("world3");
-                }
+                StandardMaterial.PrepareAttributesForInstances(attribs, this._defines);
                 // Legacy browser patch
                 var shaderName = "default";
                 if (!scene.getEngine().getCaps().standardDerivatives) {

文件差異過大導致無法顯示
+ 1 - 1
dist/preview release/babylon.noworker.js


+ 1 - 6
materialsLibrary/dist/babylon.pbrMaterial.js

@@ -551,12 +551,7 @@ var BABYLON;
                     attribs.push(BABYLON.VertexBuffer.ColorKind);
                 }
                 BABYLON.StandardMaterial.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
-                if (this._defines.INSTANCES) {
-                    attribs.push("world0");
-                    attribs.push("world1");
-                    attribs.push("world2");
-                    attribs.push("world3");
-                }
+                BABYLON.StandardMaterial.PrepareAttributesForInstances(attribs, this._defines);
                 // Legacy browser patch
                 var shaderName = "pbr";
                 if (!scene.getEngine().getCaps().standardDerivatives) {

文件差異過大導致無法顯示
+ 1 - 1
materialsLibrary/dist/babylon.pbrMaterial.min.js


+ 1 - 6
materialsLibrary/dist/babylon.simpleMaterial.js

@@ -196,12 +196,7 @@ var BABYLON;
                     attribs.push(BABYLON.VertexBuffer.ColorKind);
                 }
                 BABYLON.StandardMaterial.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
-                if (this._defines.INSTANCES) {
-                    attribs.push("world0");
-                    attribs.push("world1");
-                    attribs.push("world2");
-                    attribs.push("world3");
-                }
+                BABYLON.StandardMaterial.PrepareAttributesForInstances(attribs, this._defines);
                 // Legacy browser patch
                 var shaderName = "simple";
                 var join = this._defines.toString();

文件差異過大導致無法顯示
+ 1 - 1
materialsLibrary/dist/babylon.simpleMaterial.min.js


+ 1 - 7
materialsLibrary/materials/pbr/babylon.pbrMaterial.ts

@@ -657,13 +657,7 @@ module BABYLON {
                 }
 
                 StandardMaterial.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
-
-                if (this._defines.INSTANCES) {
-                    attribs.push("world0");
-                    attribs.push("world1");
-                    attribs.push("world2");
-                    attribs.push("world3");
-                }
+                StandardMaterial.PrepareAttributesForInstances(attribs, this._defines);
 
                 // Legacy browser patch
                 var shaderName = "pbr";

+ 1 - 7
materialsLibrary/materials/simple/babylon.simpleMaterial.ts

@@ -233,13 +233,7 @@ module BABYLON {
                 }
 
                 StandardMaterial.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
-
-                if (this._defines.INSTANCES) {
-                    attribs.push("world0");
-                    attribs.push("world1");
-                    attribs.push("world2");
-                    attribs.push("world3");
-                }
+                StandardMaterial.PrepareAttributesForInstances(attribs, this._defines);
 
                 // Legacy browser patch
                 var shaderName = "simple";

+ 9 - 6
materialsLibrary/test/refs/babylon.max.js

@@ -19949,6 +19949,14 @@ var BABYLON;
                 }
             }
         };
+        StandardMaterial.PrepareAttributesForInstances = function (attribs, defines) {
+            if (defines["INSTANCES"]) {
+                attribs.push("world0");
+                attribs.push("world1");
+                attribs.push("world2");
+                attribs.push("world3");
+            }
+        };
         StandardMaterial.prototype.isReady = function (mesh, useInstances) {
             if (this.isFrozen) {
                 if (this._wasPreviouslyReady) {
@@ -20242,12 +20250,7 @@ var BABYLON;
                     attribs.push(BABYLON.VertexBuffer.ColorKind);
                 }
                 StandardMaterial.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
-                if (this._defines.INSTANCES) {
-                    attribs.push("world0");
-                    attribs.push("world1");
-                    attribs.push("world2");
-                    attribs.push("world3");
-                }
+                StandardMaterial.PrepareAttributesForInstances(attribs, this._defines);
                 // Legacy browser patch
                 var shaderName = "default";
                 if (!scene.getEngine().getCaps().standardDerivatives) {

+ 13 - 2
src/Materials/babylon.effect.js

@@ -189,13 +189,24 @@ var BABYLON;
         };
         Effect.prototype._processIncludes = function (sourceCode, callback) {
             var _this = this;
-            var regex = /#include<(.+)>/g;
+            var regex = /#include<(.+)>(\((.*)\))*/g;
             var match = regex.exec(sourceCode);
             var returnValue = new String(sourceCode);
             while (match != null) {
                 var includeFile = match[1];
                 if (Effect.IncludesShadersStore[includeFile]) {
-                    returnValue = returnValue.replace(match[0], Effect.IncludesShadersStore[includeFile]);
+                    // Substitution
+                    var includeContent = Effect.IncludesShadersStore[includeFile];
+                    if (match[2]) {
+                        var splits = match[2].substr(1, match[2].length - 2).split(",");
+                        for (var index = 0; index < splits.length; index += 2) {
+                            var source = new RegExp(splits[index], "g");
+                            var dest = splits[index + 1];
+                            includeContent = includeContent.replace(source, dest);
+                        }
+                    }
+                    // Replace
+                    returnValue = returnValue.replace(match[0], includeContent);
                 }
                 else {
                     var includeShaderUrl = BABYLON.Engine.ShadersRepository + "ShadersInclude/" + includeFile + ".fx";

+ 16 - 2
src/Materials/babylon.effect.ts

@@ -237,7 +237,7 @@
         }
 
         private _processIncludes(sourceCode: string, callback: (data: any) => void): void {
-            var regex = /#include<(.+)>/g;
+            var regex = /#include<(.+)>(\((.*)\))*/g;
             var match = regex.exec(sourceCode);
 
             var returnValue = new String(sourceCode);
@@ -246,7 +246,21 @@
                 var includeFile = match[1];
 
                 if (Effect.IncludesShadersStore[includeFile]) {
-                    returnValue = returnValue.replace(match[0], Effect.IncludesShadersStore[includeFile]);
+                    // Substitution
+                    var includeContent = Effect.IncludesShadersStore[includeFile];
+                    if (match[2]) {
+                        var splits = match[2].substr(1, match[2].length - 2).split(",");
+
+                        for (var index = 0; index < splits.length; index += 2) {
+                            var source = new RegExp(splits[index], "g");
+                            var dest = splits[index + 1];
+
+                            includeContent = includeContent.replace(source, dest);
+                        }
+                    }
+
+                    // Replace
+                    returnValue = returnValue.replace(match[0], includeContent);
                 } else {
                     var includeShaderUrl = Engine.ShadersRepository + "ShadersInclude/" + includeFile + ".fx";
 

+ 73 - 56
src/Materials/babylon.standardMaterial.js

@@ -251,7 +251,7 @@ var BABYLON;
                 }
                 defines[type] = true;
                 // Specular
-                if (!light.specular.equalsFloats(0, 0, 0)) {
+                if (!light.specular.equalsFloats(0, 0, 0) && defines["SPECULARTERM"] !== undefined) {
                     defines["SPECULARTERM"] = true;
                 }
                 // Shadows
@@ -274,6 +274,23 @@ var BABYLON;
             }
             return needNormals;
         };
+        StandardMaterial.BindLightShadow = function (light, scene, mesh, lightIndex, effect, depthValuesAlreadySet) {
+            var shadowGenerator = light.getShadowGenerator();
+            if (mesh.receiveShadows && shadowGenerator) {
+                if (!light.needCube()) {
+                    effect.setMatrix("lightMatrix" + lightIndex, shadowGenerator.getTransformMatrix());
+                }
+                else {
+                    if (!depthValuesAlreadySet) {
+                        depthValuesAlreadySet = true;
+                        effect.setFloat2("depthValues", scene.activeCamera.minZ, scene.activeCamera.maxZ);
+                    }
+                }
+                effect.setTexture("shadowSampler" + lightIndex, shadowGenerator.getShadowMapForRendering());
+                effect.setFloat3("shadowsInfo" + lightIndex, shadowGenerator.getDarkness(), shadowGenerator.blurScale / shadowGenerator.getShadowMap().getSize().width, shadowGenerator.bias);
+            }
+            return depthValuesAlreadySet;
+        };
         StandardMaterial.BindLights = function (scene, mesh, effect, defines) {
             var lightIndex = 0;
             var depthValuesAlreadySet = false;
@@ -309,26 +326,51 @@ var BABYLON;
                 }
                 // Shadows
                 if (scene.shadowsEnabled) {
-                    var shadowGenerator = light.getShadowGenerator();
-                    if (mesh.receiveShadows && shadowGenerator) {
-                        if (!light.needCube()) {
-                            effect.setMatrix("lightMatrix" + lightIndex, shadowGenerator.getTransformMatrix());
-                        }
-                        else {
-                            if (!depthValuesAlreadySet) {
-                                depthValuesAlreadySet = true;
-                                effect.setFloat2("depthValues", scene.activeCamera.minZ, scene.activeCamera.maxZ);
-                            }
-                        }
-                        effect.setTexture("shadowSampler" + lightIndex, shadowGenerator.getShadowMapForRendering());
-                        effect.setFloat3("shadowsInfo" + lightIndex, shadowGenerator.getDarkness(), shadowGenerator.blurScale / shadowGenerator.getShadowMap().getSize().width, shadowGenerator.bias);
-                    }
+                    depthValuesAlreadySet = this.BindLightShadow(light, scene, mesh, lightIndex, effect, depthValuesAlreadySet);
                 }
                 lightIndex++;
                 if (lightIndex === maxSimultaneousLights)
                     break;
             }
         };
+        StandardMaterial.HandleFallbacksForShadows = function (defines, fallbacks) {
+            for (var lightIndex = 0; lightIndex < maxSimultaneousLights; lightIndex++) {
+                if (!defines["LIGHT" + lightIndex]) {
+                    continue;
+                }
+                if (lightIndex > 0) {
+                    fallbacks.addFallback(lightIndex, "LIGHT" + lightIndex);
+                }
+                if (defines["SHADOW" + lightIndex]) {
+                    fallbacks.addFallback(0, "SHADOW" + lightIndex);
+                }
+                if (defines["SHADOWPCF" + lightIndex]) {
+                    fallbacks.addFallback(0, "SHADOWPCF" + lightIndex);
+                }
+                if (defines["SHADOWVSM" + lightIndex]) {
+                    fallbacks.addFallback(0, "SHADOWVSM" + lightIndex);
+                }
+            }
+        };
+        StandardMaterial.PrepareAttributesForBones = function (attribs, mesh, defines, fallbacks) {
+            if (defines["NUM_BONE_INFLUENCERS"] > 0) {
+                fallbacks.addCPUSkinningFallback(0, mesh);
+                attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
+                attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
+                if (defines["NUM_BONE_INFLUENCERS"] > 4) {
+                    attribs.push(BABYLON.VertexBuffer.MatricesIndicesExtraKind);
+                    attribs.push(BABYLON.VertexBuffer.MatricesWeightsExtraKind);
+                }
+            }
+        };
+        StandardMaterial.PrepareAttributesForInstances = function (attribs, defines) {
+            if (defines["INSTANCES"]) {
+                attribs.push("world0");
+                attribs.push("world1");
+                attribs.push("world2");
+                attribs.push("world3");
+            }
+        };
         StandardMaterial.prototype.isReady = function (mesh, useInstances) {
             if (this.isFrozen) {
                 if (this._wasPreviouslyReady) {
@@ -588,23 +630,7 @@ var BABYLON;
                 if (this._defines.LOGARITHMICDEPTH) {
                     fallbacks.addFallback(0, "LOGARITHMICDEPTH");
                 }
-                for (var lightIndex = 0; lightIndex < maxSimultaneousLights; lightIndex++) {
-                    if (!this._defines["LIGHT" + lightIndex]) {
-                        continue;
-                    }
-                    if (lightIndex > 0) {
-                        fallbacks.addFallback(lightIndex, "LIGHT" + lightIndex);
-                    }
-                    if (this._defines["SHADOW" + lightIndex]) {
-                        fallbacks.addFallback(0, "SHADOW" + lightIndex);
-                    }
-                    if (this._defines["SHADOWPCF" + lightIndex]) {
-                        fallbacks.addFallback(0, "SHADOWPCF" + lightIndex);
-                    }
-                    if (this._defines["SHADOWVSM" + lightIndex]) {
-                        fallbacks.addFallback(0, "SHADOWVSM" + lightIndex);
-                    }
-                }
+                StandardMaterial.HandleFallbacksForShadows(this._defines, fallbacks);
                 if (this._defines.SPECULARTERM) {
                     fallbacks.addFallback(0, "SPECULARTERM");
                 }
@@ -623,9 +649,6 @@ var BABYLON;
                 if (this._defines.FRESNEL) {
                     fallbacks.addFallback(4, "FRESNEL");
                 }
-                if (this._defines.NUM_BONE_INFLUENCERS > 0) {
-                    fallbacks.addCPUSkinningFallback(0, mesh);
-                }
                 //Attributes
                 var attribs = [BABYLON.VertexBuffer.PositionKind];
                 if (this._defines.NORMAL) {
@@ -640,20 +663,8 @@ var BABYLON;
                 if (this._defines.VERTEXCOLOR) {
                     attribs.push(BABYLON.VertexBuffer.ColorKind);
                 }
-                if (this._defines.NUM_BONE_INFLUENCERS > 0) {
-                    attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
-                    attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
-                    if (this._defines.NUM_BONE_INFLUENCERS > 4) {
-                        attribs.push(BABYLON.VertexBuffer.MatricesIndicesExtraKind);
-                        attribs.push(BABYLON.VertexBuffer.MatricesWeightsExtraKind);
-                    }
-                }
-                if (this._defines.INSTANCES) {
-                    attribs.push("world0");
-                    attribs.push("world1");
-                    attribs.push("world2");
-                    attribs.push("world3");
-                }
+                StandardMaterial.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
+                StandardMaterial.PrepareAttributesForInstances(attribs, this._defines);
                 // Legacy browser patch
                 var shaderName = "default";
                 if (!scene.getEngine().getCaps().standardDerivatives) {
@@ -706,9 +717,7 @@ var BABYLON;
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             // Bones
-            if (mesh && mesh.useBones && mesh.computeBonesUsingShaders) {
-                this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
-            }
+            StandardMaterial.ApplyBonesParameters(mesh, this._effect);
             if (scene.getCachedMaterial() !== this) {
                 this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
                 if (StandardMaterial.FresnelEnabled) {
@@ -825,10 +834,7 @@ var BABYLON;
                     this._effect.setMatrix("view", scene.getViewMatrix());
                 }
                 // Fog
-                if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
-                    this._effect.setFloat4("vFogInfos", scene.fogMode, scene.fogStart, scene.fogEnd, scene.fogDensity);
-                    this._effect.setColor3("vFogColor", scene.fogColor);
-                }
+                StandardMaterial.ApplyFogParameters(scene, mesh, this._effect);
                 // Log. depth
                 if (this._defines.LOGARITHMICDEPTH) {
                     this._effect.setFloat("logarithmicDepthConstant", 2.0 / (Math.log(scene.activeCamera.maxZ + 1.0) / Math.LN2));
@@ -836,6 +842,17 @@ var BABYLON;
             }
             _super.prototype.bind.call(this, world, mesh);
         };
+        StandardMaterial.ApplyFogParameters = function (scene, mesh, effect) {
+            if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
+                effect.setFloat4("vFogInfos", scene.fogMode, scene.fogStart, scene.fogEnd, scene.fogDensity);
+                effect.setColor3("vFogColor", scene.fogColor);
+            }
+        };
+        StandardMaterial.ApplyBonesParameters = function (mesh, effect) {
+            if (mesh && mesh.useBones && mesh.computeBonesUsingShaders) {
+                effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
+            }
+        };
         StandardMaterial.prototype.getAnimatables = function () {
             var results = [];
             if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {

+ 85 - 62
src/Materials/babylon.standardMaterial.ts

@@ -296,7 +296,7 @@
                 defines[type] = true;
 
                 // Specular
-                if (!light.specular.equalsFloats(0, 0, 0)) {
+                if (!light.specular.equalsFloats(0, 0, 0) && defines["SPECULARTERM"] !== undefined) {
                     defines["SPECULARTERM"] = true;
                 }
 
@@ -328,6 +328,25 @@
 
         private static _scaledDiffuse = new Color3();
         private static _scaledSpecular = new Color3();
+
+        public static BindLightShadow(light: Light, scene: Scene, mesh: AbstractMesh, lightIndex: number, effect: Effect, depthValuesAlreadySet: boolean): boolean {
+            var shadowGenerator = light.getShadowGenerator();
+            if (mesh.receiveShadows && shadowGenerator) {
+                if (!(<any>light).needCube()) {
+                    effect.setMatrix("lightMatrix" + lightIndex, shadowGenerator.getTransformMatrix());
+                } else {
+                    if (!depthValuesAlreadySet) {
+                        depthValuesAlreadySet = true;
+                        effect.setFloat2("depthValues", scene.activeCamera.minZ, scene.activeCamera.maxZ);
+                    }
+                }
+                effect.setTexture("shadowSampler" + lightIndex, shadowGenerator.getShadowMapForRendering());
+                effect.setFloat3("shadowsInfo" + lightIndex, shadowGenerator.getDarkness(), shadowGenerator.blurScale / shadowGenerator.getShadowMap().getSize().width, shadowGenerator.bias);
+            }
+
+            return depthValuesAlreadySet;
+        }
+
         public static BindLights(scene: Scene, mesh: AbstractMesh, effect: Effect, defines: MaterialDefines) {
             var lightIndex = 0;
             var depthValuesAlreadySet = false;
@@ -365,19 +384,7 @@
 
                 // Shadows
                 if (scene.shadowsEnabled) {
-                    var shadowGenerator = light.getShadowGenerator();
-                    if (mesh.receiveShadows && shadowGenerator) {
-                        if (!(<any>light).needCube()) {
-                            effect.setMatrix("lightMatrix" + lightIndex, shadowGenerator.getTransformMatrix());
-                        } else {
-                            if (!depthValuesAlreadySet) {
-                                depthValuesAlreadySet = true;
-                                effect.setFloat2("depthValues", scene.activeCamera.minZ, scene.activeCamera.maxZ);
-                            }
-                        }
-                        effect.setTexture("shadowSampler" + lightIndex, shadowGenerator.getShadowMapForRendering());
-                        effect.setFloat3("shadowsInfo" + lightIndex, shadowGenerator.getDarkness(), shadowGenerator.blurScale / shadowGenerator.getShadowMap().getSize().width, shadowGenerator.bias);
-                    }
+                    depthValuesAlreadySet = this.BindLightShadow(light, scene, mesh, lightIndex, effect, depthValuesAlreadySet);
                 }
 
                 lightIndex++;
@@ -387,6 +394,52 @@
             }
         }
 
+        public static HandleFallbacksForShadows(defines: MaterialDefines, fallbacks: EffectFallbacks): void {
+            for (var lightIndex = 0; lightIndex < maxSimultaneousLights; lightIndex++) {
+                if (!defines["LIGHT" + lightIndex]) {
+                    continue;
+                }
+
+                if (lightIndex > 0) {
+                    fallbacks.addFallback(lightIndex, "LIGHT" + lightIndex);
+                }
+
+                if (defines["SHADOW" + lightIndex]) {
+                    fallbacks.addFallback(0, "SHADOW" + lightIndex);
+                }
+
+                if (defines["SHADOWPCF" + lightIndex]) {
+                    fallbacks.addFallback(0, "SHADOWPCF" + lightIndex);
+                }
+
+                if (defines["SHADOWVSM" + lightIndex]) {
+                    fallbacks.addFallback(0, "SHADOWVSM" + lightIndex);
+                }
+            }
+        }
+
+        public static PrepareAttributesForBones(attribs: string[], mesh: AbstractMesh, defines: MaterialDefines, fallbacks: EffectFallbacks): void {
+            if (defines["NUM_BONE_INFLUENCERS"] > 0) {
+                fallbacks.addCPUSkinningFallback(0, mesh);
+
+                attribs.push(VertexBuffer.MatricesIndicesKind);
+                attribs.push(VertexBuffer.MatricesWeightsKind);
+                if (defines["NUM_BONE_INFLUENCERS"] > 4) {
+                    attribs.push(VertexBuffer.MatricesIndicesExtraKind);
+                    attribs.push(VertexBuffer.MatricesWeightsExtraKind);
+                }
+            }
+        }
+
+        public static PrepareAttributesForInstances(attribs: string[], defines: MaterialDefines): void {
+            if (defines["INSTANCES"]) {
+                attribs.push("world0");
+                attribs.push("world1");
+                attribs.push("world2");
+                attribs.push("world3");
+            }
+        }
+
         public isReady(mesh?: AbstractMesh, useInstances?: boolean): boolean {
             if (this.isFrozen) {
                 if (this._wasPreviouslyReady) {
@@ -687,27 +740,7 @@
                     fallbacks.addFallback(0, "LOGARITHMICDEPTH");
                 }
 
-                for (var lightIndex = 0; lightIndex < maxSimultaneousLights; lightIndex++) {
-                    if (!this._defines["LIGHT" + lightIndex]) {
-                        continue;
-                    }
-
-                    if (lightIndex > 0) {
-                        fallbacks.addFallback(lightIndex, "LIGHT" + lightIndex);
-                    }
-
-                    if (this._defines["SHADOW" + lightIndex]) {
-                        fallbacks.addFallback(0, "SHADOW" + lightIndex);
-                    }
-
-                    if (this._defines["SHADOWPCF" + lightIndex]) {
-                        fallbacks.addFallback(0, "SHADOWPCF" + lightIndex);
-                    }
-
-                    if (this._defines["SHADOWVSM" + lightIndex]) {
-                        fallbacks.addFallback(0, "SHADOWVSM" + lightIndex);
-                    }
-                }
+                StandardMaterial.HandleFallbacksForShadows(this._defines, fallbacks);
 
                 if (this._defines.SPECULARTERM) {
                     fallbacks.addFallback(0, "SPECULARTERM");
@@ -733,10 +766,6 @@
                     fallbacks.addFallback(4, "FRESNEL");
                 }
 
-                if (this._defines.NUM_BONE_INFLUENCERS > 0) {
-                    fallbacks.addCPUSkinningFallback(0, mesh);
-                }
-
                 //Attributes
                 var attribs = [VertexBuffer.PositionKind];
 
@@ -756,22 +785,9 @@
                     attribs.push(VertexBuffer.ColorKind);
                 }
 
-                if (this._defines.NUM_BONE_INFLUENCERS > 0) {
-                    attribs.push(VertexBuffer.MatricesIndicesKind);
-                    attribs.push(VertexBuffer.MatricesWeightsKind);
-                    if (this._defines.NUM_BONE_INFLUENCERS > 4) {
-                        attribs.push(VertexBuffer.MatricesIndicesExtraKind);
-                        attribs.push(VertexBuffer.MatricesWeightsExtraKind);
-                    }
-                }
-
-                if (this._defines.INSTANCES) {
-                    attribs.push("world0");
-                    attribs.push("world1");
-                    attribs.push("world2");
-                    attribs.push("world3");
-                }
-
+                StandardMaterial.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
+                StandardMaterial.PrepareAttributesForInstances(attribs, this._defines);
+                
                 // Legacy browser patch
                 var shaderName = "default";
                 if (!scene.getEngine().getCaps().standardDerivatives) {
@@ -840,9 +856,7 @@
             this.bindOnlyWorldMatrix(world);
 
             // Bones
-            if (mesh && mesh.useBones && mesh.computeBonesUsingShaders) {
-                this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
-            }
+            StandardMaterial.ApplyBonesParameters(mesh, this._effect);
 
             if (scene.getCachedMaterial() !== this) {
                 this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
@@ -990,10 +1004,7 @@
                 }
 
                 // Fog
-                if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
-                    this._effect.setFloat4("vFogInfos", scene.fogMode, scene.fogStart, scene.fogEnd, scene.fogDensity);
-                    this._effect.setColor3("vFogColor", scene.fogColor);
-                }
+                StandardMaterial.ApplyFogParameters(scene, mesh, this._effect);
 
                 // Log. depth
                 if (this._defines.LOGARITHMICDEPTH) {
@@ -1004,6 +1015,18 @@
             super.bind(world, mesh);
         }
 
+        public static ApplyFogParameters(scene: Scene, mesh: AbstractMesh, effect: Effect): void {
+            if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
+                effect.setFloat4("vFogInfos", scene.fogMode, scene.fogStart, scene.fogEnd, scene.fogDensity);
+                effect.setColor3("vFogColor", scene.fogColor);
+            }
+        }
+        public static ApplyBonesParameters(mesh: AbstractMesh, effect: Effect): void {
+            if (mesh && mesh.useBones && mesh.computeBonesUsingShaders) {
+                effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
+            }
+        }
+
         public getAnimatables(): IAnimatable[] {
             var results = [];
 

+ 1 - 0
src/babylon.engine.ts

@@ -2534,3 +2534,4 @@
 }
 
 
+