David Catuhe 7 years ago
parent
commit
ab9cb1af81
62 changed files with 10306 additions and 10404 deletions
  1. 2848 2843
      Playground/babylon.d.txt
  2. 3390 3385
      dist/preview release/babylon.d.ts
  3. 41 41
      dist/preview release/babylon.js
  4. 18 32
      dist/preview release/babylon.max.js
  5. 41 41
      dist/preview release/babylon.worker.js
  6. 3383 3378
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts
  7. 41 41
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js
  8. 18 32
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js
  9. 18 32
      dist/preview release/customConfigurations/minimalGLTFViewer/es6.js
  10. 18 32
      dist/preview release/es6.js
  11. 1 1
      dist/preview release/materialsLibrary/babylon.cellMaterial.js
  12. 1 1
      dist/preview release/materialsLibrary/babylon.cellMaterial.min.js
  13. 1 0
      dist/preview release/materialsLibrary/babylon.customMaterial.d.ts
  14. 4 1
      dist/preview release/materialsLibrary/babylon.customMaterial.js
  15. 2 2
      dist/preview release/materialsLibrary/babylon.customMaterial.min.js
  16. 1 1
      dist/preview release/materialsLibrary/babylon.fireMaterial.js
  17. 1 1
      dist/preview release/materialsLibrary/babylon.fireMaterial.min.js
  18. 1 1
      dist/preview release/materialsLibrary/babylon.furMaterial.js
  19. 1 1
      dist/preview release/materialsLibrary/babylon.furMaterial.min.js
  20. 1 1
      dist/preview release/materialsLibrary/babylon.gradientMaterial.js
  21. 1 1
      dist/preview release/materialsLibrary/babylon.gradientMaterial.min.js
  22. 1 1
      dist/preview release/materialsLibrary/babylon.lavaMaterial.js
  23. 1 1
      dist/preview release/materialsLibrary/babylon.lavaMaterial.min.js
  24. 1 1
      dist/preview release/materialsLibrary/babylon.normalMaterial.js
  25. 1 1
      dist/preview release/materialsLibrary/babylon.normalMaterial.min.js
  26. 1 1
      dist/preview release/materialsLibrary/babylon.shadowOnlyMaterial.js
  27. 1 1
      dist/preview release/materialsLibrary/babylon.shadowOnlyMaterial.min.js
  28. 1 1
      dist/preview release/materialsLibrary/babylon.simpleMaterial.js
  29. 1 1
      dist/preview release/materialsLibrary/babylon.simpleMaterial.min.js
  30. 1 1
      dist/preview release/materialsLibrary/babylon.terrainMaterial.js
  31. 1 1
      dist/preview release/materialsLibrary/babylon.terrainMaterial.min.js
  32. 1 1
      dist/preview release/materialsLibrary/babylon.triPlanarMaterial.js
  33. 1 1
      dist/preview release/materialsLibrary/babylon.triPlanarMaterial.min.js
  34. 1 1
      dist/preview release/materialsLibrary/babylon.waterMaterial.js
  35. 1 1
      dist/preview release/materialsLibrary/babylon.waterMaterial.min.js
  36. 15 12
      dist/preview release/materialsLibrary/babylonjs.materials.js
  37. 7 7
      dist/preview release/materialsLibrary/babylonjs.materials.min.js
  38. 1 0
      dist/preview release/materialsLibrary/babylonjs.materials.module.d.ts
  39. 2 51
      dist/preview release/typedocValidationBaseline.json
  40. 39 39
      dist/preview release/viewer/babylon.viewer.js
  41. 22 22
      materialsLibrary/src/cell/babylon.cellMaterial.ts
  42. 5 1
      materialsLibrary/src/custom/babylon.customMaterial.ts
  43. 54 54
      materialsLibrary/src/fire/babylon.fireMaterial.ts
  44. 73 73
      materialsLibrary/src/fur/babylon.furMaterial.ts
  45. 19 19
      materialsLibrary/src/gradient/babylon.gradientMaterial.ts
  46. 29 29
      materialsLibrary/src/lava/babylon.lavaMaterial.ts
  47. 23 23
      materialsLibrary/src/normal/babylon.normalMaterial.ts
  48. 18 18
      materialsLibrary/src/shadowOnly/babylon.shadowOnlyMaterial.ts
  49. 27 27
      materialsLibrary/src/simple/babylon.simpleMaterial.ts
  50. 39 39
      materialsLibrary/src/terrain/babylon.terrainMaterial.ts
  51. 49 49
      materialsLibrary/src/triPlanar/babylon.triPlanarMaterial.ts
  52. 6 6
      materialsLibrary/src/water/babylon.waterMaterial.ts
  53. 0 9
      src/Engine/babylon.engine.ts
  54. 1 1
      src/Materials/Background/babylon.backgroundMaterial.ts
  55. 1 1
      src/Materials/PBR/babylon.pbrBaseMaterial.ts
  56. 5 8
      src/Materials/babylon.material.ts
  57. 10 2
      src/Materials/babylon.materialHelper.ts
  58. 1 1
      src/Materials/babylon.shaderMaterial.ts
  59. 1 1
      src/Materials/babylon.standardMaterial.ts
  60. 0 8
      src/Mesh/babylon.mesh.ts
  61. 0 2
      src/PostProcess/babylon.volumetricLightScatteringPostProcess.ts
  62. 14 20
      src/Rendering/babylon.renderingGroup.ts

File diff suppressed because it is too large
+ 2848 - 2843
Playground/babylon.d.txt


File diff suppressed because it is too large
+ 3390 - 3385
dist/preview release/babylon.d.ts


File diff suppressed because it is too large
+ 41 - 41
dist/preview release/babylon.js


+ 18 - 32
dist/preview release/babylon.max.js

@@ -11317,12 +11317,6 @@ var BABYLON;
         Engine.prototype.getAlphaMode = function () {
         Engine.prototype.getAlphaMode = function () {
             return this._alphaMode;
             return this._alphaMode;
         };
         };
-        Engine.prototype.setAlphaTesting = function (enable) {
-            this._alphaTest = enable;
-        };
-        Engine.prototype.getAlphaTesting = function () {
-            return !!this._alphaTest;
-        };
         // Textures
         // Textures
         Engine.prototype.wipeCaches = function (bruteForce) {
         Engine.prototype.wipeCaches = function (bruteForce) {
             if (this.preventCacheWipeBetweenFrames && !bruteForce) {
             if (this.preventCacheWipeBetweenFrames && !bruteForce) {
@@ -18919,10 +18913,8 @@ var BABYLON;
             var engine = this._scene.getEngine();
             var engine = this._scene.getEngine();
             // Depth only
             // Depth only
             if (this._depthOnlySubMeshes.length !== 0) {
             if (this._depthOnlySubMeshes.length !== 0) {
-                engine.setAlphaTesting(true);
                 engine.setColorWrite(false);
                 engine.setColorWrite(false);
                 this._renderAlphaTest(this._depthOnlySubMeshes);
                 this._renderAlphaTest(this._depthOnlySubMeshes);
-                engine.setAlphaTesting(false);
                 engine.setColorWrite(true);
                 engine.setColorWrite(true);
             }
             }
             // Opaque
             // Opaque
@@ -18931,9 +18923,7 @@ var BABYLON;
             }
             }
             // Alpha test
             // Alpha test
             if (this._alphaTestSubMeshes.length !== 0) {
             if (this._alphaTestSubMeshes.length !== 0) {
-                engine.setAlphaTesting(true);
                 this._renderAlphaTest(this._alphaTestSubMeshes);
                 this._renderAlphaTest(this._alphaTestSubMeshes);
-                engine.setAlphaTesting(false);
             }
             }
             var stencilState = engine.getStencilBuffer();
             var stencilState = engine.getStencilBuffer();
             engine.setStencilBuffer(false);
             engine.setStencilBuffer(false);
@@ -19010,10 +19000,8 @@ var BABYLON;
                     if (material && material.needDepthPrePass) {
                     if (material && material.needDepthPrePass) {
                         var engine = material.getScene().getEngine();
                         var engine = material.getScene().getEngine();
                         engine.setColorWrite(false);
                         engine.setColorWrite(false);
-                        engine.setAlphaTesting(true);
                         engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
                         engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
                         subMesh.render(false);
                         subMesh.render(false);
-                        engine.setAlphaTesting(false);
                         engine.setColorWrite(true);
                         engine.setColorWrite(true);
                     }
                     }
                 }
                 }
@@ -25405,28 +25393,22 @@ var BABYLON;
             this.computeWorldMatrix();
             this.computeWorldMatrix();
             var mat = this.material || scene.defaultMaterial;
             var mat = this.material || scene.defaultMaterial;
             if (mat) {
             if (mat) {
-                var currentAlphaTestingState = engine.getAlphaTesting();
                 if (mat.storeEffectOnSubMeshes) {
                 if (mat.storeEffectOnSubMeshes) {
                     for (var _i = 0, _a = this.subMeshes; _i < _a.length; _i++) {
                     for (var _i = 0, _a = this.subMeshes; _i < _a.length; _i++) {
                         var subMesh = _a[_i];
                         var subMesh = _a[_i];
                         var effectiveMaterial = subMesh.getMaterial();
                         var effectiveMaterial = subMesh.getMaterial();
                         if (effectiveMaterial) {
                         if (effectiveMaterial) {
-                            engine.setAlphaTesting(effectiveMaterial.needAlphaTesting() && !effectiveMaterial.needAlphaBlendingForMesh(this));
                             if (!effectiveMaterial.isReadyForSubMesh(this, subMesh, hardwareInstancedRendering)) {
                             if (!effectiveMaterial.isReadyForSubMesh(this, subMesh, hardwareInstancedRendering)) {
-                                engine.setAlphaTesting(currentAlphaTestingState);
                                 return false;
                                 return false;
                             }
                             }
                         }
                         }
                     }
                     }
                 }
                 }
                 else {
                 else {
-                    engine.setAlphaTesting(mat.needAlphaTesting() && !mat.needAlphaBlendingForMesh(this));
                     if (!mat.isReady(this, hardwareInstancedRendering)) {
                     if (!mat.isReady(this, hardwareInstancedRendering)) {
-                        engine.setAlphaTesting(currentAlphaTestingState);
                         return false;
                         return false;
                     }
                     }
                 }
                 }
-                engine.setAlphaTesting(currentAlphaTestingState);
             }
             }
             // Shadows
             // Shadows
             for (var _b = 0, _c = this._lightSources; _b < _c.length; _b++) {
             for (var _b = 0, _c = this._lightSources; _b < _c.length; _b++) {
@@ -28698,6 +28680,9 @@ var BABYLON;
                 this.bindSceneUniformBuffer(effect, this.getScene().getSceneUniformBuffer());
                 this.bindSceneUniformBuffer(effect, this.getScene().getSceneUniformBuffer());
             }
             }
         };
         };
+        Material.prototype._shouldTurnAlphaTestOn = function (mesh) {
+            return (!this.needAlphaBlendingForMesh(mesh) && this.needAlphaTesting());
+        };
         Material.prototype._afterBind = function (mesh) {
         Material.prototype._afterBind = function (mesh) {
             this._scene._cachedMaterial = this;
             this._scene._cachedMaterial = this;
             if (mesh) {
             if (mesh) {
@@ -28746,10 +28731,9 @@ var BABYLON;
          */
          */
         Material.prototype.forceCompilation = function (mesh, onCompiled, options) {
         Material.prototype.forceCompilation = function (mesh, onCompiled, options) {
             var _this = this;
             var _this = this;
-            var localOptions = __assign({ alphaTest: null, clipPlane: false }, options);
+            var localOptions = __assign({ clipPlane: false }, options);
             var subMesh = new BABYLON.BaseSubMesh();
             var subMesh = new BABYLON.BaseSubMesh();
             var scene = this.getScene();
             var scene = this.getScene();
-            var engine = scene.getEngine();
             var checkReady = function () {
             var checkReady = function () {
                 if (!_this._scene || !_this._scene.getEngine()) {
                 if (!_this._scene || !_this._scene.getEngine()) {
                     return;
                     return;
@@ -28757,9 +28741,7 @@ var BABYLON;
                 if (subMesh._materialDefines) {
                 if (subMesh._materialDefines) {
                     subMesh._materialDefines._renderId = -1;
                     subMesh._materialDefines._renderId = -1;
                 }
                 }
-                var alphaTestState = engine.getAlphaTesting();
                 var clipPlaneState = scene.clipPlane;
                 var clipPlaneState = scene.clipPlane;
-                engine.setAlphaTesting(localOptions.alphaTest || (!_this.needAlphaBlendingForMesh(mesh) && _this.needAlphaTesting()));
                 if (localOptions.clipPlane) {
                 if (localOptions.clipPlane) {
                     scene.clipPlane = new BABYLON.Plane(0, 0, 0, 1);
                     scene.clipPlane = new BABYLON.Plane(0, 0, 0, 1);
                 }
                 }
@@ -28783,7 +28765,6 @@ var BABYLON;
                         setTimeout(checkReady, 16);
                         setTimeout(checkReady, 16);
                     }
                     }
                 }
                 }
-                engine.setAlphaTesting(alphaTestState);
                 if (options && options.clipPlane) {
                 if (options && options.clipPlane) {
                     scene.clipPlane = clipPlaneState;
                     scene.clipPlane = clipPlaneState;
                 }
                 }
@@ -34785,14 +34766,21 @@ var BABYLON;
                 defines["NONUNIFORMSCALING"] = mesh.nonUniformScaling;
                 defines["NONUNIFORMSCALING"] = mesh.nonUniformScaling;
             }
             }
         };
         };
-        MaterialHelper.PrepareDefinesForFrameBoundValues = function (scene, engine, defines, useInstances, forceAlphaTest) {
-            if (forceAlphaTest === void 0) { forceAlphaTest = false; }
+        /**
+         * Helper used to prepare the list of defines for shader compilation
+         * @param scene defines the current scene
+         * @param engine defines the current engine
+         * @param defines specifies the list of active defines
+         * @param useInstances defines if instances have to be turned on
+         * @param alphaTest defines if alpha testing has to be turned on
+         */
+        MaterialHelper.PrepareDefinesForFrameBoundValues = function (scene, engine, defines, useInstances, alphaTest) {
             var changed = false;
             var changed = false;
             if (defines["CLIPPLANE"] !== (scene.clipPlane !== undefined && scene.clipPlane !== null)) {
             if (defines["CLIPPLANE"] !== (scene.clipPlane !== undefined && scene.clipPlane !== null)) {
                 defines["CLIPPLANE"] = !defines["CLIPPLANE"];
                 defines["CLIPPLANE"] = !defines["CLIPPLANE"];
                 changed = true;
                 changed = true;
             }
             }
-            if (defines["ALPHATEST"] !== (engine.getAlphaTesting() || forceAlphaTest)) {
+            if (defines["ALPHATEST"] !== alphaTest) {
                 defines["ALPHATEST"] = !defines["ALPHATEST"];
                 defines["ALPHATEST"] = !defines["ALPHATEST"];
                 changed = true;
                 changed = true;
             }
             }
@@ -35775,7 +35763,7 @@ var BABYLON;
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances, this._shouldTurnAlphaTestOn(mesh));
             // Get correct effect      
             // Get correct effect      
             if (defines.isDirty) {
             if (defines.isDirty) {
                 defines.markAsProcessed();
                 defines.markAsProcessed();
@@ -37370,7 +37358,7 @@ var BABYLON;
             // Misc.
             // Misc.
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._forceAlphaTest);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh) || this._forceAlphaTest);
             // Attribs
             // Attribs
             if (BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true, this._transparencyMode !== BABYLON.PBRMaterial.PBRMATERIAL_OPAQUE) && mesh) {
             if (BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true, this._transparencyMode !== BABYLON.PBRMaterial.PBRMATERIAL_OPAQUE) && mesh) {
                 var bufferMesh = null;
                 var bufferMesh = null;
@@ -48812,7 +48800,7 @@ var BABYLON;
                 }
                 }
             }
             }
             // Alpha test
             // Alpha test
-            if (engine.getAlphaTesting()) {
+            if (mesh && this._shouldTurnAlphaTestOn(mesh)) {
                 defines.push("#define ALPHATEST");
                 defines.push("#define ALPHATEST");
             }
             }
             var previousEffect = this._effect;
             var previousEffect = this._effect;
@@ -63090,11 +63078,9 @@ var BABYLON;
                 for (index = 0; index < opaqueSubMeshes.length; index++) {
                 for (index = 0; index < opaqueSubMeshes.length; index++) {
                     renderSubMesh(opaqueSubMeshes.data[index]);
                     renderSubMesh(opaqueSubMeshes.data[index]);
                 }
                 }
-                engine.setAlphaTesting(true);
                 for (index = 0; index < alphaTestSubMeshes.length; index++) {
                 for (index = 0; index < alphaTestSubMeshes.length; index++) {
                     renderSubMesh(alphaTestSubMeshes.data[index]);
                     renderSubMesh(alphaTestSubMeshes.data[index]);
                 }
                 }
-                engine.setAlphaTesting(false);
                 if (transparentSubMeshes.length) {
                 if (transparentSubMeshes.length) {
                     // Sort sub meshes
                     // Sort sub meshes
                     for (index = 0; index < transparentSubMeshes.length; index++) {
                     for (index = 0; index < transparentSubMeshes.length; index++) {
@@ -82006,7 +81992,7 @@ var BABYLON;
             // Misc.
             // Misc.
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances, false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances, this._shouldTurnAlphaTestOn(mesh));
             // Attribs
             // Attribs
             if (BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true, false)) {
             if (BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true, false)) {
                 if (mesh) {
                 if (mesh) {

File diff suppressed because it is too large
+ 41 - 41
dist/preview release/babylon.worker.js


File diff suppressed because it is too large
+ 3383 - 3378
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


File diff suppressed because it is too large
+ 41 - 41
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js


+ 18 - 32
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js

@@ -11317,12 +11317,6 @@ var BABYLON;
         Engine.prototype.getAlphaMode = function () {
         Engine.prototype.getAlphaMode = function () {
             return this._alphaMode;
             return this._alphaMode;
         };
         };
-        Engine.prototype.setAlphaTesting = function (enable) {
-            this._alphaTest = enable;
-        };
-        Engine.prototype.getAlphaTesting = function () {
-            return !!this._alphaTest;
-        };
         // Textures
         // Textures
         Engine.prototype.wipeCaches = function (bruteForce) {
         Engine.prototype.wipeCaches = function (bruteForce) {
             if (this.preventCacheWipeBetweenFrames && !bruteForce) {
             if (this.preventCacheWipeBetweenFrames && !bruteForce) {
@@ -18919,10 +18913,8 @@ var BABYLON;
             var engine = this._scene.getEngine();
             var engine = this._scene.getEngine();
             // Depth only
             // Depth only
             if (this._depthOnlySubMeshes.length !== 0) {
             if (this._depthOnlySubMeshes.length !== 0) {
-                engine.setAlphaTesting(true);
                 engine.setColorWrite(false);
                 engine.setColorWrite(false);
                 this._renderAlphaTest(this._depthOnlySubMeshes);
                 this._renderAlphaTest(this._depthOnlySubMeshes);
-                engine.setAlphaTesting(false);
                 engine.setColorWrite(true);
                 engine.setColorWrite(true);
             }
             }
             // Opaque
             // Opaque
@@ -18931,9 +18923,7 @@ var BABYLON;
             }
             }
             // Alpha test
             // Alpha test
             if (this._alphaTestSubMeshes.length !== 0) {
             if (this._alphaTestSubMeshes.length !== 0) {
-                engine.setAlphaTesting(true);
                 this._renderAlphaTest(this._alphaTestSubMeshes);
                 this._renderAlphaTest(this._alphaTestSubMeshes);
-                engine.setAlphaTesting(false);
             }
             }
             var stencilState = engine.getStencilBuffer();
             var stencilState = engine.getStencilBuffer();
             engine.setStencilBuffer(false);
             engine.setStencilBuffer(false);
@@ -19010,10 +19000,8 @@ var BABYLON;
                     if (material && material.needDepthPrePass) {
                     if (material && material.needDepthPrePass) {
                         var engine = material.getScene().getEngine();
                         var engine = material.getScene().getEngine();
                         engine.setColorWrite(false);
                         engine.setColorWrite(false);
-                        engine.setAlphaTesting(true);
                         engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
                         engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
                         subMesh.render(false);
                         subMesh.render(false);
-                        engine.setAlphaTesting(false);
                         engine.setColorWrite(true);
                         engine.setColorWrite(true);
                     }
                     }
                 }
                 }
@@ -25405,28 +25393,22 @@ var BABYLON;
             this.computeWorldMatrix();
             this.computeWorldMatrix();
             var mat = this.material || scene.defaultMaterial;
             var mat = this.material || scene.defaultMaterial;
             if (mat) {
             if (mat) {
-                var currentAlphaTestingState = engine.getAlphaTesting();
                 if (mat.storeEffectOnSubMeshes) {
                 if (mat.storeEffectOnSubMeshes) {
                     for (var _i = 0, _a = this.subMeshes; _i < _a.length; _i++) {
                     for (var _i = 0, _a = this.subMeshes; _i < _a.length; _i++) {
                         var subMesh = _a[_i];
                         var subMesh = _a[_i];
                         var effectiveMaterial = subMesh.getMaterial();
                         var effectiveMaterial = subMesh.getMaterial();
                         if (effectiveMaterial) {
                         if (effectiveMaterial) {
-                            engine.setAlphaTesting(effectiveMaterial.needAlphaTesting() && !effectiveMaterial.needAlphaBlendingForMesh(this));
                             if (!effectiveMaterial.isReadyForSubMesh(this, subMesh, hardwareInstancedRendering)) {
                             if (!effectiveMaterial.isReadyForSubMesh(this, subMesh, hardwareInstancedRendering)) {
-                                engine.setAlphaTesting(currentAlphaTestingState);
                                 return false;
                                 return false;
                             }
                             }
                         }
                         }
                     }
                     }
                 }
                 }
                 else {
                 else {
-                    engine.setAlphaTesting(mat.needAlphaTesting() && !mat.needAlphaBlendingForMesh(this));
                     if (!mat.isReady(this, hardwareInstancedRendering)) {
                     if (!mat.isReady(this, hardwareInstancedRendering)) {
-                        engine.setAlphaTesting(currentAlphaTestingState);
                         return false;
                         return false;
                     }
                     }
                 }
                 }
-                engine.setAlphaTesting(currentAlphaTestingState);
             }
             }
             // Shadows
             // Shadows
             for (var _b = 0, _c = this._lightSources; _b < _c.length; _b++) {
             for (var _b = 0, _c = this._lightSources; _b < _c.length; _b++) {
@@ -28698,6 +28680,9 @@ var BABYLON;
                 this.bindSceneUniformBuffer(effect, this.getScene().getSceneUniformBuffer());
                 this.bindSceneUniformBuffer(effect, this.getScene().getSceneUniformBuffer());
             }
             }
         };
         };
+        Material.prototype._shouldTurnAlphaTestOn = function (mesh) {
+            return (!this.needAlphaBlendingForMesh(mesh) && this.needAlphaTesting());
+        };
         Material.prototype._afterBind = function (mesh) {
         Material.prototype._afterBind = function (mesh) {
             this._scene._cachedMaterial = this;
             this._scene._cachedMaterial = this;
             if (mesh) {
             if (mesh) {
@@ -28746,10 +28731,9 @@ var BABYLON;
          */
          */
         Material.prototype.forceCompilation = function (mesh, onCompiled, options) {
         Material.prototype.forceCompilation = function (mesh, onCompiled, options) {
             var _this = this;
             var _this = this;
-            var localOptions = __assign({ alphaTest: null, clipPlane: false }, options);
+            var localOptions = __assign({ clipPlane: false }, options);
             var subMesh = new BABYLON.BaseSubMesh();
             var subMesh = new BABYLON.BaseSubMesh();
             var scene = this.getScene();
             var scene = this.getScene();
-            var engine = scene.getEngine();
             var checkReady = function () {
             var checkReady = function () {
                 if (!_this._scene || !_this._scene.getEngine()) {
                 if (!_this._scene || !_this._scene.getEngine()) {
                     return;
                     return;
@@ -28757,9 +28741,7 @@ var BABYLON;
                 if (subMesh._materialDefines) {
                 if (subMesh._materialDefines) {
                     subMesh._materialDefines._renderId = -1;
                     subMesh._materialDefines._renderId = -1;
                 }
                 }
-                var alphaTestState = engine.getAlphaTesting();
                 var clipPlaneState = scene.clipPlane;
                 var clipPlaneState = scene.clipPlane;
-                engine.setAlphaTesting(localOptions.alphaTest || (!_this.needAlphaBlendingForMesh(mesh) && _this.needAlphaTesting()));
                 if (localOptions.clipPlane) {
                 if (localOptions.clipPlane) {
                     scene.clipPlane = new BABYLON.Plane(0, 0, 0, 1);
                     scene.clipPlane = new BABYLON.Plane(0, 0, 0, 1);
                 }
                 }
@@ -28783,7 +28765,6 @@ var BABYLON;
                         setTimeout(checkReady, 16);
                         setTimeout(checkReady, 16);
                     }
                     }
                 }
                 }
-                engine.setAlphaTesting(alphaTestState);
                 if (options && options.clipPlane) {
                 if (options && options.clipPlane) {
                     scene.clipPlane = clipPlaneState;
                     scene.clipPlane = clipPlaneState;
                 }
                 }
@@ -34785,14 +34766,21 @@ var BABYLON;
                 defines["NONUNIFORMSCALING"] = mesh.nonUniformScaling;
                 defines["NONUNIFORMSCALING"] = mesh.nonUniformScaling;
             }
             }
         };
         };
-        MaterialHelper.PrepareDefinesForFrameBoundValues = function (scene, engine, defines, useInstances, forceAlphaTest) {
-            if (forceAlphaTest === void 0) { forceAlphaTest = false; }
+        /**
+         * Helper used to prepare the list of defines for shader compilation
+         * @param scene defines the current scene
+         * @param engine defines the current engine
+         * @param defines specifies the list of active defines
+         * @param useInstances defines if instances have to be turned on
+         * @param alphaTest defines if alpha testing has to be turned on
+         */
+        MaterialHelper.PrepareDefinesForFrameBoundValues = function (scene, engine, defines, useInstances, alphaTest) {
             var changed = false;
             var changed = false;
             if (defines["CLIPPLANE"] !== (scene.clipPlane !== undefined && scene.clipPlane !== null)) {
             if (defines["CLIPPLANE"] !== (scene.clipPlane !== undefined && scene.clipPlane !== null)) {
                 defines["CLIPPLANE"] = !defines["CLIPPLANE"];
                 defines["CLIPPLANE"] = !defines["CLIPPLANE"];
                 changed = true;
                 changed = true;
             }
             }
-            if (defines["ALPHATEST"] !== (engine.getAlphaTesting() || forceAlphaTest)) {
+            if (defines["ALPHATEST"] !== alphaTest) {
                 defines["ALPHATEST"] = !defines["ALPHATEST"];
                 defines["ALPHATEST"] = !defines["ALPHATEST"];
                 changed = true;
                 changed = true;
             }
             }
@@ -35775,7 +35763,7 @@ var BABYLON;
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances, this._shouldTurnAlphaTestOn(mesh));
             // Get correct effect      
             // Get correct effect      
             if (defines.isDirty) {
             if (defines.isDirty) {
                 defines.markAsProcessed();
                 defines.markAsProcessed();
@@ -37370,7 +37358,7 @@ var BABYLON;
             // Misc.
             // Misc.
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._forceAlphaTest);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh) || this._forceAlphaTest);
             // Attribs
             // Attribs
             if (BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true, this._transparencyMode !== BABYLON.PBRMaterial.PBRMATERIAL_OPAQUE) && mesh) {
             if (BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true, this._transparencyMode !== BABYLON.PBRMaterial.PBRMATERIAL_OPAQUE) && mesh) {
                 var bufferMesh = null;
                 var bufferMesh = null;
@@ -48658,7 +48646,7 @@ var BABYLON;
                 }
                 }
             }
             }
             // Alpha test
             // Alpha test
-            if (engine.getAlphaTesting()) {
+            if (mesh && this._shouldTurnAlphaTestOn(mesh)) {
                 defines.push("#define ALPHATEST");
                 defines.push("#define ALPHATEST");
             }
             }
             var previousEffect = this._effect;
             var previousEffect = this._effect;
@@ -62936,11 +62924,9 @@ var BABYLON;
                 for (index = 0; index < opaqueSubMeshes.length; index++) {
                 for (index = 0; index < opaqueSubMeshes.length; index++) {
                     renderSubMesh(opaqueSubMeshes.data[index]);
                     renderSubMesh(opaqueSubMeshes.data[index]);
                 }
                 }
-                engine.setAlphaTesting(true);
                 for (index = 0; index < alphaTestSubMeshes.length; index++) {
                 for (index = 0; index < alphaTestSubMeshes.length; index++) {
                     renderSubMesh(alphaTestSubMeshes.data[index]);
                     renderSubMesh(alphaTestSubMeshes.data[index]);
                 }
                 }
-                engine.setAlphaTesting(false);
                 if (transparentSubMeshes.length) {
                 if (transparentSubMeshes.length) {
                     // Sort sub meshes
                     // Sort sub meshes
                     for (index = 0; index < transparentSubMeshes.length; index++) {
                     for (index = 0; index < transparentSubMeshes.length; index++) {
@@ -81502,7 +81488,7 @@ var BABYLON;
             // Misc.
             // Misc.
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances, false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances, this._shouldTurnAlphaTestOn(mesh));
             // Attribs
             // Attribs
             if (BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true, false)) {
             if (BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true, false)) {
                 if (mesh) {
                 if (mesh) {

+ 18 - 32
dist/preview release/customConfigurations/minimalGLTFViewer/es6.js

@@ -11303,12 +11303,6 @@ var BABYLON;
         Engine.prototype.getAlphaMode = function () {
         Engine.prototype.getAlphaMode = function () {
             return this._alphaMode;
             return this._alphaMode;
         };
         };
-        Engine.prototype.setAlphaTesting = function (enable) {
-            this._alphaTest = enable;
-        };
-        Engine.prototype.getAlphaTesting = function () {
-            return !!this._alphaTest;
-        };
         // Textures
         // Textures
         Engine.prototype.wipeCaches = function (bruteForce) {
         Engine.prototype.wipeCaches = function (bruteForce) {
             if (this.preventCacheWipeBetweenFrames && !bruteForce) {
             if (this.preventCacheWipeBetweenFrames && !bruteForce) {
@@ -18905,10 +18899,8 @@ var BABYLON;
             var engine = this._scene.getEngine();
             var engine = this._scene.getEngine();
             // Depth only
             // Depth only
             if (this._depthOnlySubMeshes.length !== 0) {
             if (this._depthOnlySubMeshes.length !== 0) {
-                engine.setAlphaTesting(true);
                 engine.setColorWrite(false);
                 engine.setColorWrite(false);
                 this._renderAlphaTest(this._depthOnlySubMeshes);
                 this._renderAlphaTest(this._depthOnlySubMeshes);
-                engine.setAlphaTesting(false);
                 engine.setColorWrite(true);
                 engine.setColorWrite(true);
             }
             }
             // Opaque
             // Opaque
@@ -18917,9 +18909,7 @@ var BABYLON;
             }
             }
             // Alpha test
             // Alpha test
             if (this._alphaTestSubMeshes.length !== 0) {
             if (this._alphaTestSubMeshes.length !== 0) {
-                engine.setAlphaTesting(true);
                 this._renderAlphaTest(this._alphaTestSubMeshes);
                 this._renderAlphaTest(this._alphaTestSubMeshes);
-                engine.setAlphaTesting(false);
             }
             }
             var stencilState = engine.getStencilBuffer();
             var stencilState = engine.getStencilBuffer();
             engine.setStencilBuffer(false);
             engine.setStencilBuffer(false);
@@ -18996,10 +18986,8 @@ var BABYLON;
                     if (material && material.needDepthPrePass) {
                     if (material && material.needDepthPrePass) {
                         var engine = material.getScene().getEngine();
                         var engine = material.getScene().getEngine();
                         engine.setColorWrite(false);
                         engine.setColorWrite(false);
-                        engine.setAlphaTesting(true);
                         engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
                         engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
                         subMesh.render(false);
                         subMesh.render(false);
-                        engine.setAlphaTesting(false);
                         engine.setColorWrite(true);
                         engine.setColorWrite(true);
                     }
                     }
                 }
                 }
@@ -25391,28 +25379,22 @@ var BABYLON;
             this.computeWorldMatrix();
             this.computeWorldMatrix();
             var mat = this.material || scene.defaultMaterial;
             var mat = this.material || scene.defaultMaterial;
             if (mat) {
             if (mat) {
-                var currentAlphaTestingState = engine.getAlphaTesting();
                 if (mat.storeEffectOnSubMeshes) {
                 if (mat.storeEffectOnSubMeshes) {
                     for (var _i = 0, _a = this.subMeshes; _i < _a.length; _i++) {
                     for (var _i = 0, _a = this.subMeshes; _i < _a.length; _i++) {
                         var subMesh = _a[_i];
                         var subMesh = _a[_i];
                         var effectiveMaterial = subMesh.getMaterial();
                         var effectiveMaterial = subMesh.getMaterial();
                         if (effectiveMaterial) {
                         if (effectiveMaterial) {
-                            engine.setAlphaTesting(effectiveMaterial.needAlphaTesting() && !effectiveMaterial.needAlphaBlendingForMesh(this));
                             if (!effectiveMaterial.isReadyForSubMesh(this, subMesh, hardwareInstancedRendering)) {
                             if (!effectiveMaterial.isReadyForSubMesh(this, subMesh, hardwareInstancedRendering)) {
-                                engine.setAlphaTesting(currentAlphaTestingState);
                                 return false;
                                 return false;
                             }
                             }
                         }
                         }
                     }
                     }
                 }
                 }
                 else {
                 else {
-                    engine.setAlphaTesting(mat.needAlphaTesting() && !mat.needAlphaBlendingForMesh(this));
                     if (!mat.isReady(this, hardwareInstancedRendering)) {
                     if (!mat.isReady(this, hardwareInstancedRendering)) {
-                        engine.setAlphaTesting(currentAlphaTestingState);
                         return false;
                         return false;
                     }
                     }
                 }
                 }
-                engine.setAlphaTesting(currentAlphaTestingState);
             }
             }
             // Shadows
             // Shadows
             for (var _b = 0, _c = this._lightSources; _b < _c.length; _b++) {
             for (var _b = 0, _c = this._lightSources; _b < _c.length; _b++) {
@@ -28684,6 +28666,9 @@ var BABYLON;
                 this.bindSceneUniformBuffer(effect, this.getScene().getSceneUniformBuffer());
                 this.bindSceneUniformBuffer(effect, this.getScene().getSceneUniformBuffer());
             }
             }
         };
         };
+        Material.prototype._shouldTurnAlphaTestOn = function (mesh) {
+            return (!this.needAlphaBlendingForMesh(mesh) && this.needAlphaTesting());
+        };
         Material.prototype._afterBind = function (mesh) {
         Material.prototype._afterBind = function (mesh) {
             this._scene._cachedMaterial = this;
             this._scene._cachedMaterial = this;
             if (mesh) {
             if (mesh) {
@@ -28732,10 +28717,9 @@ var BABYLON;
          */
          */
         Material.prototype.forceCompilation = function (mesh, onCompiled, options) {
         Material.prototype.forceCompilation = function (mesh, onCompiled, options) {
             var _this = this;
             var _this = this;
-            var localOptions = __assign({ alphaTest: null, clipPlane: false }, options);
+            var localOptions = __assign({ clipPlane: false }, options);
             var subMesh = new BABYLON.BaseSubMesh();
             var subMesh = new BABYLON.BaseSubMesh();
             var scene = this.getScene();
             var scene = this.getScene();
-            var engine = scene.getEngine();
             var checkReady = function () {
             var checkReady = function () {
                 if (!_this._scene || !_this._scene.getEngine()) {
                 if (!_this._scene || !_this._scene.getEngine()) {
                     return;
                     return;
@@ -28743,9 +28727,7 @@ var BABYLON;
                 if (subMesh._materialDefines) {
                 if (subMesh._materialDefines) {
                     subMesh._materialDefines._renderId = -1;
                     subMesh._materialDefines._renderId = -1;
                 }
                 }
-                var alphaTestState = engine.getAlphaTesting();
                 var clipPlaneState = scene.clipPlane;
                 var clipPlaneState = scene.clipPlane;
-                engine.setAlphaTesting(localOptions.alphaTest || (!_this.needAlphaBlendingForMesh(mesh) && _this.needAlphaTesting()));
                 if (localOptions.clipPlane) {
                 if (localOptions.clipPlane) {
                     scene.clipPlane = new BABYLON.Plane(0, 0, 0, 1);
                     scene.clipPlane = new BABYLON.Plane(0, 0, 0, 1);
                 }
                 }
@@ -28769,7 +28751,6 @@ var BABYLON;
                         setTimeout(checkReady, 16);
                         setTimeout(checkReady, 16);
                     }
                     }
                 }
                 }
-                engine.setAlphaTesting(alphaTestState);
                 if (options && options.clipPlane) {
                 if (options && options.clipPlane) {
                     scene.clipPlane = clipPlaneState;
                     scene.clipPlane = clipPlaneState;
                 }
                 }
@@ -34771,14 +34752,21 @@ var BABYLON;
                 defines["NONUNIFORMSCALING"] = mesh.nonUniformScaling;
                 defines["NONUNIFORMSCALING"] = mesh.nonUniformScaling;
             }
             }
         };
         };
-        MaterialHelper.PrepareDefinesForFrameBoundValues = function (scene, engine, defines, useInstances, forceAlphaTest) {
-            if (forceAlphaTest === void 0) { forceAlphaTest = false; }
+        /**
+         * Helper used to prepare the list of defines for shader compilation
+         * @param scene defines the current scene
+         * @param engine defines the current engine
+         * @param defines specifies the list of active defines
+         * @param useInstances defines if instances have to be turned on
+         * @param alphaTest defines if alpha testing has to be turned on
+         */
+        MaterialHelper.PrepareDefinesForFrameBoundValues = function (scene, engine, defines, useInstances, alphaTest) {
             var changed = false;
             var changed = false;
             if (defines["CLIPPLANE"] !== (scene.clipPlane !== undefined && scene.clipPlane !== null)) {
             if (defines["CLIPPLANE"] !== (scene.clipPlane !== undefined && scene.clipPlane !== null)) {
                 defines["CLIPPLANE"] = !defines["CLIPPLANE"];
                 defines["CLIPPLANE"] = !defines["CLIPPLANE"];
                 changed = true;
                 changed = true;
             }
             }
-            if (defines["ALPHATEST"] !== (engine.getAlphaTesting() || forceAlphaTest)) {
+            if (defines["ALPHATEST"] !== alphaTest) {
                 defines["ALPHATEST"] = !defines["ALPHATEST"];
                 defines["ALPHATEST"] = !defines["ALPHATEST"];
                 changed = true;
                 changed = true;
             }
             }
@@ -35761,7 +35749,7 @@ var BABYLON;
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances, this._shouldTurnAlphaTestOn(mesh));
             // Get correct effect      
             // Get correct effect      
             if (defines.isDirty) {
             if (defines.isDirty) {
                 defines.markAsProcessed();
                 defines.markAsProcessed();
@@ -37356,7 +37344,7 @@ var BABYLON;
             // Misc.
             // Misc.
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._forceAlphaTest);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh) || this._forceAlphaTest);
             // Attribs
             // Attribs
             if (BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true, this._transparencyMode !== BABYLON.PBRMaterial.PBRMATERIAL_OPAQUE) && mesh) {
             if (BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true, this._transparencyMode !== BABYLON.PBRMaterial.PBRMATERIAL_OPAQUE) && mesh) {
                 var bufferMesh = null;
                 var bufferMesh = null;
@@ -48644,7 +48632,7 @@ var BABYLON;
                 }
                 }
             }
             }
             // Alpha test
             // Alpha test
-            if (engine.getAlphaTesting()) {
+            if (mesh && this._shouldTurnAlphaTestOn(mesh)) {
                 defines.push("#define ALPHATEST");
                 defines.push("#define ALPHATEST");
             }
             }
             var previousEffect = this._effect;
             var previousEffect = this._effect;
@@ -62922,11 +62910,9 @@ var BABYLON;
                 for (index = 0; index < opaqueSubMeshes.length; index++) {
                 for (index = 0; index < opaqueSubMeshes.length; index++) {
                     renderSubMesh(opaqueSubMeshes.data[index]);
                     renderSubMesh(opaqueSubMeshes.data[index]);
                 }
                 }
-                engine.setAlphaTesting(true);
                 for (index = 0; index < alphaTestSubMeshes.length; index++) {
                 for (index = 0; index < alphaTestSubMeshes.length; index++) {
                     renderSubMesh(alphaTestSubMeshes.data[index]);
                     renderSubMesh(alphaTestSubMeshes.data[index]);
                 }
                 }
-                engine.setAlphaTesting(false);
                 if (transparentSubMeshes.length) {
                 if (transparentSubMeshes.length) {
                     // Sort sub meshes
                     // Sort sub meshes
                     for (index = 0; index < transparentSubMeshes.length; index++) {
                     for (index = 0; index < transparentSubMeshes.length; index++) {
@@ -81488,7 +81474,7 @@ var BABYLON;
             // Misc.
             // Misc.
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances, false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances, this._shouldTurnAlphaTestOn(mesh));
             // Attribs
             // Attribs
             if (BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true, false)) {
             if (BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true, false)) {
                 if (mesh) {
                 if (mesh) {

+ 18 - 32
dist/preview release/es6.js

@@ -11303,12 +11303,6 @@ var BABYLON;
         Engine.prototype.getAlphaMode = function () {
         Engine.prototype.getAlphaMode = function () {
             return this._alphaMode;
             return this._alphaMode;
         };
         };
-        Engine.prototype.setAlphaTesting = function (enable) {
-            this._alphaTest = enable;
-        };
-        Engine.prototype.getAlphaTesting = function () {
-            return !!this._alphaTest;
-        };
         // Textures
         // Textures
         Engine.prototype.wipeCaches = function (bruteForce) {
         Engine.prototype.wipeCaches = function (bruteForce) {
             if (this.preventCacheWipeBetweenFrames && !bruteForce) {
             if (this.preventCacheWipeBetweenFrames && !bruteForce) {
@@ -18905,10 +18899,8 @@ var BABYLON;
             var engine = this._scene.getEngine();
             var engine = this._scene.getEngine();
             // Depth only
             // Depth only
             if (this._depthOnlySubMeshes.length !== 0) {
             if (this._depthOnlySubMeshes.length !== 0) {
-                engine.setAlphaTesting(true);
                 engine.setColorWrite(false);
                 engine.setColorWrite(false);
                 this._renderAlphaTest(this._depthOnlySubMeshes);
                 this._renderAlphaTest(this._depthOnlySubMeshes);
-                engine.setAlphaTesting(false);
                 engine.setColorWrite(true);
                 engine.setColorWrite(true);
             }
             }
             // Opaque
             // Opaque
@@ -18917,9 +18909,7 @@ var BABYLON;
             }
             }
             // Alpha test
             // Alpha test
             if (this._alphaTestSubMeshes.length !== 0) {
             if (this._alphaTestSubMeshes.length !== 0) {
-                engine.setAlphaTesting(true);
                 this._renderAlphaTest(this._alphaTestSubMeshes);
                 this._renderAlphaTest(this._alphaTestSubMeshes);
-                engine.setAlphaTesting(false);
             }
             }
             var stencilState = engine.getStencilBuffer();
             var stencilState = engine.getStencilBuffer();
             engine.setStencilBuffer(false);
             engine.setStencilBuffer(false);
@@ -18996,10 +18986,8 @@ var BABYLON;
                     if (material && material.needDepthPrePass) {
                     if (material && material.needDepthPrePass) {
                         var engine = material.getScene().getEngine();
                         var engine = material.getScene().getEngine();
                         engine.setColorWrite(false);
                         engine.setColorWrite(false);
-                        engine.setAlphaTesting(true);
                         engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
                         engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
                         subMesh.render(false);
                         subMesh.render(false);
-                        engine.setAlphaTesting(false);
                         engine.setColorWrite(true);
                         engine.setColorWrite(true);
                     }
                     }
                 }
                 }
@@ -25391,28 +25379,22 @@ var BABYLON;
             this.computeWorldMatrix();
             this.computeWorldMatrix();
             var mat = this.material || scene.defaultMaterial;
             var mat = this.material || scene.defaultMaterial;
             if (mat) {
             if (mat) {
-                var currentAlphaTestingState = engine.getAlphaTesting();
                 if (mat.storeEffectOnSubMeshes) {
                 if (mat.storeEffectOnSubMeshes) {
                     for (var _i = 0, _a = this.subMeshes; _i < _a.length; _i++) {
                     for (var _i = 0, _a = this.subMeshes; _i < _a.length; _i++) {
                         var subMesh = _a[_i];
                         var subMesh = _a[_i];
                         var effectiveMaterial = subMesh.getMaterial();
                         var effectiveMaterial = subMesh.getMaterial();
                         if (effectiveMaterial) {
                         if (effectiveMaterial) {
-                            engine.setAlphaTesting(effectiveMaterial.needAlphaTesting() && !effectiveMaterial.needAlphaBlendingForMesh(this));
                             if (!effectiveMaterial.isReadyForSubMesh(this, subMesh, hardwareInstancedRendering)) {
                             if (!effectiveMaterial.isReadyForSubMesh(this, subMesh, hardwareInstancedRendering)) {
-                                engine.setAlphaTesting(currentAlphaTestingState);
                                 return false;
                                 return false;
                             }
                             }
                         }
                         }
                     }
                     }
                 }
                 }
                 else {
                 else {
-                    engine.setAlphaTesting(mat.needAlphaTesting() && !mat.needAlphaBlendingForMesh(this));
                     if (!mat.isReady(this, hardwareInstancedRendering)) {
                     if (!mat.isReady(this, hardwareInstancedRendering)) {
-                        engine.setAlphaTesting(currentAlphaTestingState);
                         return false;
                         return false;
                     }
                     }
                 }
                 }
-                engine.setAlphaTesting(currentAlphaTestingState);
             }
             }
             // Shadows
             // Shadows
             for (var _b = 0, _c = this._lightSources; _b < _c.length; _b++) {
             for (var _b = 0, _c = this._lightSources; _b < _c.length; _b++) {
@@ -28684,6 +28666,9 @@ var BABYLON;
                 this.bindSceneUniformBuffer(effect, this.getScene().getSceneUniformBuffer());
                 this.bindSceneUniformBuffer(effect, this.getScene().getSceneUniformBuffer());
             }
             }
         };
         };
+        Material.prototype._shouldTurnAlphaTestOn = function (mesh) {
+            return (!this.needAlphaBlendingForMesh(mesh) && this.needAlphaTesting());
+        };
         Material.prototype._afterBind = function (mesh) {
         Material.prototype._afterBind = function (mesh) {
             this._scene._cachedMaterial = this;
             this._scene._cachedMaterial = this;
             if (mesh) {
             if (mesh) {
@@ -28732,10 +28717,9 @@ var BABYLON;
          */
          */
         Material.prototype.forceCompilation = function (mesh, onCompiled, options) {
         Material.prototype.forceCompilation = function (mesh, onCompiled, options) {
             var _this = this;
             var _this = this;
-            var localOptions = __assign({ alphaTest: null, clipPlane: false }, options);
+            var localOptions = __assign({ clipPlane: false }, options);
             var subMesh = new BABYLON.BaseSubMesh();
             var subMesh = new BABYLON.BaseSubMesh();
             var scene = this.getScene();
             var scene = this.getScene();
-            var engine = scene.getEngine();
             var checkReady = function () {
             var checkReady = function () {
                 if (!_this._scene || !_this._scene.getEngine()) {
                 if (!_this._scene || !_this._scene.getEngine()) {
                     return;
                     return;
@@ -28743,9 +28727,7 @@ var BABYLON;
                 if (subMesh._materialDefines) {
                 if (subMesh._materialDefines) {
                     subMesh._materialDefines._renderId = -1;
                     subMesh._materialDefines._renderId = -1;
                 }
                 }
-                var alphaTestState = engine.getAlphaTesting();
                 var clipPlaneState = scene.clipPlane;
                 var clipPlaneState = scene.clipPlane;
-                engine.setAlphaTesting(localOptions.alphaTest || (!_this.needAlphaBlendingForMesh(mesh) && _this.needAlphaTesting()));
                 if (localOptions.clipPlane) {
                 if (localOptions.clipPlane) {
                     scene.clipPlane = new BABYLON.Plane(0, 0, 0, 1);
                     scene.clipPlane = new BABYLON.Plane(0, 0, 0, 1);
                 }
                 }
@@ -28769,7 +28751,6 @@ var BABYLON;
                         setTimeout(checkReady, 16);
                         setTimeout(checkReady, 16);
                     }
                     }
                 }
                 }
-                engine.setAlphaTesting(alphaTestState);
                 if (options && options.clipPlane) {
                 if (options && options.clipPlane) {
                     scene.clipPlane = clipPlaneState;
                     scene.clipPlane = clipPlaneState;
                 }
                 }
@@ -34771,14 +34752,21 @@ var BABYLON;
                 defines["NONUNIFORMSCALING"] = mesh.nonUniformScaling;
                 defines["NONUNIFORMSCALING"] = mesh.nonUniformScaling;
             }
             }
         };
         };
-        MaterialHelper.PrepareDefinesForFrameBoundValues = function (scene, engine, defines, useInstances, forceAlphaTest) {
-            if (forceAlphaTest === void 0) { forceAlphaTest = false; }
+        /**
+         * Helper used to prepare the list of defines for shader compilation
+         * @param scene defines the current scene
+         * @param engine defines the current engine
+         * @param defines specifies the list of active defines
+         * @param useInstances defines if instances have to be turned on
+         * @param alphaTest defines if alpha testing has to be turned on
+         */
+        MaterialHelper.PrepareDefinesForFrameBoundValues = function (scene, engine, defines, useInstances, alphaTest) {
             var changed = false;
             var changed = false;
             if (defines["CLIPPLANE"] !== (scene.clipPlane !== undefined && scene.clipPlane !== null)) {
             if (defines["CLIPPLANE"] !== (scene.clipPlane !== undefined && scene.clipPlane !== null)) {
                 defines["CLIPPLANE"] = !defines["CLIPPLANE"];
                 defines["CLIPPLANE"] = !defines["CLIPPLANE"];
                 changed = true;
                 changed = true;
             }
             }
-            if (defines["ALPHATEST"] !== (engine.getAlphaTesting() || forceAlphaTest)) {
+            if (defines["ALPHATEST"] !== alphaTest) {
                 defines["ALPHATEST"] = !defines["ALPHATEST"];
                 defines["ALPHATEST"] = !defines["ALPHATEST"];
                 changed = true;
                 changed = true;
             }
             }
@@ -35761,7 +35749,7 @@ var BABYLON;
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances, this._shouldTurnAlphaTestOn(mesh));
             // Get correct effect      
             // Get correct effect      
             if (defines.isDirty) {
             if (defines.isDirty) {
                 defines.markAsProcessed();
                 defines.markAsProcessed();
@@ -37356,7 +37344,7 @@ var BABYLON;
             // Misc.
             // Misc.
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._forceAlphaTest);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh) || this._forceAlphaTest);
             // Attribs
             // Attribs
             if (BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true, this._transparencyMode !== BABYLON.PBRMaterial.PBRMATERIAL_OPAQUE) && mesh) {
             if (BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true, this._transparencyMode !== BABYLON.PBRMaterial.PBRMATERIAL_OPAQUE) && mesh) {
                 var bufferMesh = null;
                 var bufferMesh = null;
@@ -48798,7 +48786,7 @@ var BABYLON;
                 }
                 }
             }
             }
             // Alpha test
             // Alpha test
-            if (engine.getAlphaTesting()) {
+            if (mesh && this._shouldTurnAlphaTestOn(mesh)) {
                 defines.push("#define ALPHATEST");
                 defines.push("#define ALPHATEST");
             }
             }
             var previousEffect = this._effect;
             var previousEffect = this._effect;
@@ -63076,11 +63064,9 @@ var BABYLON;
                 for (index = 0; index < opaqueSubMeshes.length; index++) {
                 for (index = 0; index < opaqueSubMeshes.length; index++) {
                     renderSubMesh(opaqueSubMeshes.data[index]);
                     renderSubMesh(opaqueSubMeshes.data[index]);
                 }
                 }
-                engine.setAlphaTesting(true);
                 for (index = 0; index < alphaTestSubMeshes.length; index++) {
                 for (index = 0; index < alphaTestSubMeshes.length; index++) {
                     renderSubMesh(alphaTestSubMeshes.data[index]);
                     renderSubMesh(alphaTestSubMeshes.data[index]);
                 }
                 }
-                engine.setAlphaTesting(false);
                 if (transparentSubMeshes.length) {
                 if (transparentSubMeshes.length) {
                     // Sort sub meshes
                     // Sort sub meshes
                     for (index = 0; index < transparentSubMeshes.length; index++) {
                     for (index = 0; index < transparentSubMeshes.length; index++) {
@@ -81992,7 +81978,7 @@ var BABYLON;
             // Misc.
             // Misc.
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances, false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances, this._shouldTurnAlphaTestOn(mesh));
             // Attribs
             // Attribs
             if (BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true, false)) {
             if (BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true, false)) {
                 if (mesh) {
                 if (mesh) {

+ 1 - 1
dist/preview release/materialsLibrary/babylon.cellMaterial.js

@@ -102,7 +102,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.cellMaterial.min.js


+ 1 - 0
dist/preview release/materialsLibrary/babylon.customMaterial.d.ts

@@ -222,6 +222,7 @@ declare module BABYLON {
          * Sets the Color Grading 2D Lookup Texture.
          * Sets the Color Grading 2D Lookup Texture.
          */
          */
         cameraColorGradingTexture: Nullable<BaseTexture>;
         cameraColorGradingTexture: Nullable<BaseTexture>;
+        protected _shouldTurnAlphaTestOn(mesh: AbstractMesh): boolean;
         customShaderNameResolve: (shaderName: string, uniforms: string[], uniformBuffers: string[], samplers: string[], defines: StandardMaterialDefines_OldVer) => string;
         customShaderNameResolve: (shaderName: string, uniforms: string[], uniformBuffers: string[], samplers: string[], defines: StandardMaterialDefines_OldVer) => string;
         protected _renderTargets: SmartArray<RenderTargetTexture>;
         protected _renderTargets: SmartArray<RenderTargetTexture>;
         protected _worldViewProjectionMatrix: Matrix;
         protected _worldViewProjectionMatrix: Matrix;

+ 4 - 1
dist/preview release/materialsLibrary/babylon.customMaterial.js

@@ -315,6 +315,9 @@ var BABYLON;
             enumerable: true,
             enumerable: true,
             configurable: true
             configurable: true
         });
         });
+        StandardMaterial_OldVer.prototype._shouldTurnAlphaTestOn = function (mesh) {
+            return (!this.needAlphaBlendingForMesh(mesh) && this.needAlphaTesting());
+        };
         StandardMaterial_OldVer.prototype.getClassName = function () {
         StandardMaterial_OldVer.prototype.getClassName = function () {
             return "StandardMaterial_OldVer";
             return "StandardMaterial_OldVer";
         };
         };
@@ -564,7 +567,7 @@ var BABYLON;
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             // Get correct effect      
             // Get correct effect      
             if (defines.isDirty) {
             if (defines.isDirty) {
                 defines.markAsProcessed();
                 defines.markAsProcessed();

File diff suppressed because it is too large
+ 2 - 2
dist/preview release/materialsLibrary/babylon.customMaterial.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylon.fireMaterial.js

@@ -94,7 +94,7 @@ var BABYLON;
                 defines.FOG = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled);
                 defines.FOG = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled);
             }
             }
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
             // Get correct effect      
             // Get correct effect      

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.fireMaterial.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylon.furMaterial.js

@@ -147,7 +147,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.furMaterial.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylon.gradientMaterial.js

@@ -118,7 +118,7 @@ var BABYLON;
                 }
                 }
             }
             }
             var engine = scene.getEngine();
             var engine = scene.getEngine();
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights);
             // Attribs
             // Attribs

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.gradientMaterial.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylon.lavaMaterial.js

@@ -135,7 +135,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.lavaMaterial.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylon.normalMaterial.js

@@ -129,7 +129,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.normalMaterial.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylon.shadowOnlyMaterial.js

@@ -86,7 +86,7 @@ var BABYLON;
                     }
                     }
                 }
                 }
             }
             }
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 1);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 1);
             // Attribs
             // Attribs

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.shadowOnlyMaterial.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylon.simpleMaterial.js

@@ -96,7 +96,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.simpleMaterial.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylon.terrainMaterial.js

@@ -102,7 +102,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.terrainMaterial.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylon.triPlanarMaterial.js

@@ -121,7 +121,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.triPlanarMaterial.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylon.waterMaterial.js

@@ -228,7 +228,7 @@ var BABYLON;
                     }
                     }
                 }
                 }
             }
             }
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
             if (defines._areMiscDirty) {
             if (defines._areMiscDirty) {
                 if (this._fresnelSeparate) {
                 if (this._fresnelSeparate) {

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.waterMaterial.min.js


+ 15 - 12
dist/preview release/materialsLibrary/babylonjs.materials.js

@@ -96,7 +96,7 @@ var BABYLON;
                     }
                     }
                 }
                 }
             }
             }
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 1);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 1);
             // Attribs
             // Attribs
@@ -326,7 +326,7 @@ var BABYLON;
                 }
                 }
             }
             }
             var engine = scene.getEngine();
             var engine = scene.getEngine();
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights);
             // Attribs
             // Attribs
@@ -615,7 +615,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      
@@ -926,7 +926,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      
@@ -1238,7 +1238,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      
@@ -1642,7 +1642,7 @@ var BABYLON;
                     }
                     }
                 }
                 }
             }
             }
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
             if (defines._areMiscDirty) {
             if (defines._areMiscDirty) {
                 if (this._fresnelSeparate) {
                 if (this._fresnelSeparate) {
@@ -2124,7 +2124,7 @@ var BABYLON;
                 defines.FOG = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled);
                 defines.FOG = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled);
             }
             }
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
             // Get correct effect      
             // Get correct effect      
@@ -2498,7 +2498,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      
@@ -2915,7 +2915,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      
@@ -3321,7 +3321,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      
@@ -4311,6 +4311,9 @@ var BABYLON;
             enumerable: true,
             enumerable: true,
             configurable: true
             configurable: true
         });
         });
+        StandardMaterial_OldVer.prototype._shouldTurnAlphaTestOn = function (mesh) {
+            return (!this.needAlphaBlendingForMesh(mesh) && this.needAlphaTesting());
+        };
         StandardMaterial_OldVer.prototype.getClassName = function () {
         StandardMaterial_OldVer.prototype.getClassName = function () {
             return "StandardMaterial_OldVer";
             return "StandardMaterial_OldVer";
         };
         };
@@ -4560,7 +4563,7 @@ var BABYLON;
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             // Get correct effect      
             // Get correct effect      
             if (defines.isDirty) {
             if (defines.isDirty) {
                 defines.markAsProcessed();
                 defines.markAsProcessed();
@@ -6150,7 +6153,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      

File diff suppressed because it is too large
+ 7 - 7
dist/preview release/materialsLibrary/babylonjs.materials.min.js


+ 1 - 0
dist/preview release/materialsLibrary/babylonjs.materials.module.d.ts

@@ -728,6 +728,7 @@ declare module BABYLON {
          * Sets the Color Grading 2D Lookup Texture.
          * Sets the Color Grading 2D Lookup Texture.
          */
          */
         cameraColorGradingTexture: Nullable<BaseTexture>;
         cameraColorGradingTexture: Nullable<BaseTexture>;
+        protected _shouldTurnAlphaTestOn(mesh: AbstractMesh): boolean;
         customShaderNameResolve: (shaderName: string, uniforms: string[], uniformBuffers: string[], samplers: string[], defines: StandardMaterialDefines_OldVer) => string;
         customShaderNameResolve: (shaderName: string, uniforms: string[], uniformBuffers: string[], samplers: string[], defines: StandardMaterialDefines_OldVer) => string;
         protected _renderTargets: SmartArray<RenderTargetTexture>;
         protected _renderTargets: SmartArray<RenderTargetTexture>;
         protected _worldViewProjectionMatrix: Matrix;
         protected _worldViewProjectionMatrix: Matrix;

+ 2 - 51
dist/preview release/typedocValidationBaseline.json

@@ -1,7 +1,7 @@
 {
 {
-  "errors": 10955,
+  "errors": 10946,
   "babylon.typedoc.json": {
   "babylon.typedoc.json": {
-    "errors": 10955,
+    "errors": 10946,
     "AnimationKeyInterpolation": {
     "AnimationKeyInterpolation": {
       "Enumeration": {
       "Enumeration": {
         "Comments": {
         "Comments": {
@@ -15730,11 +15730,6 @@
             "MissingText": true
             "MissingText": true
           }
           }
         },
         },
-        "getAlphaTesting": {
-          "Comments": {
-            "MissingText": true
-          }
-        },
         "getAspectRatio": {
         "getAspectRatio": {
           "Comments": {
           "Comments": {
             "MissingText": true
             "MissingText": true
@@ -16145,18 +16140,6 @@
             }
             }
           }
           }
         },
         },
-        "setAlphaTesting": {
-          "Comments": {
-            "MissingText": true
-          },
-          "Parameter": {
-            "enable": {
-              "Comments": {
-                "MissingText": true
-              }
-            }
-          }
-        },
         "setArray": {
         "setArray": {
           "Comments": {
           "Comments": {
             "MissingText": true
             "MissingText": true
@@ -24276,38 +24259,6 @@
             }
             }
           }
           }
         },
         },
-        "PrepareDefinesForFrameBoundValues": {
-          "Comments": {
-            "MissingText": true
-          },
-          "Parameter": {
-            "scene": {
-              "Comments": {
-                "MissingText": true
-              }
-            },
-            "engine": {
-              "Comments": {
-                "MissingText": true
-              }
-            },
-            "defines": {
-              "Comments": {
-                "MissingText": true
-              }
-            },
-            "useInstances": {
-              "Comments": {
-                "MissingText": true
-              }
-            },
-            "forceAlphaTest": {
-              "Comments": {
-                "MissingText": true
-              }
-            }
-          }
-        },
         "PrepareDefinesForLights": {
         "PrepareDefinesForLights": {
           "Comments": {
           "Comments": {
             "MissingText": true
             "MissingText": true

File diff suppressed because it is too large
+ 39 - 39
dist/preview release/viewer/babylon.viewer.js


+ 22 - 22
materialsLibrary/src/cell/babylon.cellMaterial.ts

@@ -39,16 +39,16 @@ module BABYLON {
         public _computeHighLevel: boolean = false;
         public _computeHighLevel: boolean = false;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         public computeHighLevel: boolean;
         public computeHighLevel: boolean;
-        
+
         @serialize("disableLighting")
         @serialize("disableLighting")
         private _disableLighting = false;
         private _disableLighting = false;
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
-        public disableLighting: boolean;   
-        
+        public disableLighting: boolean;
+
         @serialize("maxSimultaneousLights")
         @serialize("maxSimultaneousLights")
         private _maxSimultaneousLights = 4;
         private _maxSimultaneousLights = 4;
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
-        public maxSimultaneousLights: number; 
+        public maxSimultaneousLights: number;
 
 
         private _renderId: number;
         private _renderId: number;
 
 
@@ -69,7 +69,7 @@ module BABYLON {
         }
         }
 
 
         // Methods   
         // Methods   
-        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {   
+        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {
             if (this.isFrozen) {
             if (this.isFrozen) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                     return true;
                     return true;
@@ -102,7 +102,7 @@ module BABYLON {
                             defines._needUVs = true;
                             defines._needUVs = true;
                             defines.DIFFUSE = true;
                             defines.DIFFUSE = true;
                         }
                         }
-                    }                
+                    }
                 }
                 }
             }
             }
 
 
@@ -116,8 +116,8 @@ module BABYLON {
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
 
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
-            
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
+
             // Attribs
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
 
 
@@ -127,13 +127,13 @@ module BABYLON {
                 scene.resetCachedMaterial();
                 scene.resetCachedMaterial();
 
 
                 // Fallbacks
                 // Fallbacks
-                var fallbacks = new EffectFallbacks();             
+                var fallbacks = new EffectFallbacks();
                 if (defines.FOG) {
                 if (defines.FOG) {
                     fallbacks.addFallback(1, "FOG");
                     fallbacks.addFallback(1, "FOG");
                 }
                 }
 
 
                 MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
                 MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
-                
+
                 if (defines.NUM_BONE_INFLUENCERS > 0) {
                 if (defines.NUM_BONE_INFLUENCERS > 0) {
                     fallbacks.addCPUSkinningFallback(0, mesh);
                     fallbacks.addCPUSkinningFallback(0, mesh);
                 }
                 }
@@ -163,19 +163,19 @@ module BABYLON {
                 var shaderName = "cell";
                 var shaderName = "cell";
                 var join = defines.toString();
                 var join = defines.toString();
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
-                                "vFogInfos", "vFogColor", "pointSize",
-                                "vDiffuseInfos", 
-                                "mBones",
-                                "vClipPlane", "diffuseMatrix"
+                    "vFogInfos", "vFogColor", "pointSize",
+                    "vDiffuseInfos",
+                    "mBones",
+                    "vClipPlane", "diffuseMatrix"
                 ];
                 ];
                 var samplers = ["diffuseSampler"];
                 var samplers = ["diffuseSampler"];
                 var uniformBuffers = new Array<string>()
                 var uniformBuffers = new Array<string>()
 
 
                 MaterialHelper.PrepareUniformsAndSamplersList(<EffectCreationOptions>{
                 MaterialHelper.PrepareUniformsAndSamplersList(<EffectCreationOptions>{
-                    uniformsNames: uniforms, 
+                    uniformsNames: uniforms,
                     uniformBuffersNames: uniformBuffers,
                     uniformBuffersNames: uniformBuffers,
-                    samplers: samplers, 
-                    defines: defines, 
+                    samplers: samplers,
+                    defines: defines,
                     maxSimultaneousLights: this.maxSimultaneousLights
                     maxSimultaneousLights: this.maxSimultaneousLights
                 });
                 });
                 subMesh.setEffect(scene.getEngine().createEffect(shaderName,
                 subMesh.setEffect(scene.getEngine().createEffect(shaderName,
@@ -231,7 +231,7 @@ module BABYLON {
                     this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
                     this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
                     this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
                     this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
                 }
                 }
-                
+
                 // Clip plane
                 // Clip plane
                 MaterialHelper.BindClipPlane(this._activeEffect, scene);
                 MaterialHelper.BindClipPlane(this._activeEffect, scene);
 
 
@@ -240,14 +240,14 @@ module BABYLON {
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                 }
                 }
 
 
-                MaterialHelper.BindEyePosition(effect, scene);               
+                MaterialHelper.BindEyePosition(effect, scene);
             }
             }
 
 
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
 
 
             // Lights
             // Lights
             if (scene.lightsEnabled && !this.disableLighting) {
             if (scene.lightsEnabled && !this.disableLighting) {
-                MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this._maxSimultaneousLights);          
+                MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this._maxSimultaneousLights);
             }
             }
 
 
             // View
             // View
@@ -304,7 +304,7 @@ module BABYLON {
         public clone(name: string): CellMaterial {
         public clone(name: string): CellMaterial {
             return SerializationHelper.Clone<CellMaterial>(() => new CellMaterial(name, this.getScene()), this);
             return SerializationHelper.Clone<CellMaterial>(() => new CellMaterial(name, this.getScene()), this);
         }
         }
-        
+
         public serialize(): any {
         public serialize(): any {
             var serializationObject = SerializationHelper.Serialize(this);
             var serializationObject = SerializationHelper.Serialize(this);
             serializationObject.customType = "BABYLON.CellMaterial";
             serializationObject.customType = "BABYLON.CellMaterial";
@@ -316,5 +316,5 @@ module BABYLON {
             return SerializationHelper.Parse(() => new CellMaterial(source.name, scene), source, scene, rootUrl);
             return SerializationHelper.Parse(() => new CellMaterial(source.name, scene), source, scene, rootUrl);
         }
         }
     }
     }
-} 
+}
 
 

+ 5 - 1
materialsLibrary/src/custom/babylon.customMaterial.ts

@@ -423,6 +423,10 @@ module BABYLON {
             this._imageProcessingConfiguration.colorGradingTexture = value;
             this._imageProcessingConfiguration.colorGradingTexture = value;
         }
         }
 
 
+        protected _shouldTurnAlphaTestOn(mesh: AbstractMesh): boolean {
+            return (!this.needAlphaBlendingForMesh(mesh) && this.needAlphaTesting());
+        }
+
         public customShaderNameResolve: (shaderName: string, uniforms: string[], uniformBuffers: string[], samplers: string[], defines: StandardMaterialDefines_OldVer) => string;
         public customShaderNameResolve: (shaderName: string, uniforms: string[], uniformBuffers: string[], samplers: string[], defines: StandardMaterialDefines_OldVer) => string;
 
 
         protected _renderTargets = new SmartArray<RenderTargetTexture>(16);
         protected _renderTargets = new SmartArray<RenderTargetTexture>(16);
@@ -721,7 +725,7 @@ module BABYLON {
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
 
 
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
 
 
             // Get correct effect      
             // Get correct effect      
             if (defines.isDirty) {
             if (defines.isDirty) {

+ 54 - 54
materialsLibrary/src/fire/babylon.fireMaterial.ts

@@ -26,24 +26,24 @@ module BABYLON {
         @serializeAsTexture("diffuseTexture")
         @serializeAsTexture("diffuseTexture")
         private _diffuseTexture: Nullable<BaseTexture>;
         private _diffuseTexture: Nullable<BaseTexture>;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public diffuseTexture: Nullable<BaseTexture>;        
-        
+        public diffuseTexture: Nullable<BaseTexture>;
+
         @serializeAsTexture("distortionTexture")
         @serializeAsTexture("distortionTexture")
         private _distortionTexture: Nullable<BaseTexture>;
         private _distortionTexture: Nullable<BaseTexture>;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public distortionTexture: Nullable<BaseTexture>;       
-        
+        public distortionTexture: Nullable<BaseTexture>;
+
         @serializeAsTexture("opacityTexture")
         @serializeAsTexture("opacityTexture")
         private _opacityTexture: Nullable<BaseTexture>;
         private _opacityTexture: Nullable<BaseTexture>;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         public opacityTexture: Nullable<BaseTexture>;
         public opacityTexture: Nullable<BaseTexture>;
-        
+
         @serializeAsColor3("diffuse")
         @serializeAsColor3("diffuse")
         public diffuseColor = new Color3(1, 1, 1);
         public diffuseColor = new Color3(1, 1, 1);
-        
+
         @serialize()
         @serialize()
         public speed = 1.0;
         public speed = 1.0;
-        
+
         private _scaledDiffuse = new Color3();
         private _scaledDiffuse = new Color3();
         private _renderId: number;
         private _renderId: number;
         private _lastTime: number = 0;
         private _lastTime: number = 0;
@@ -65,7 +65,7 @@ module BABYLON {
         }
         }
 
 
         // Methods   
         // Methods   
-        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {   
+        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {
             if (this.isFrozen) {
             if (this.isFrozen) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                     return true;
                     return true;
@@ -97,7 +97,7 @@ module BABYLON {
                         defines._needUVs = true;
                         defines._needUVs = true;
                         defines.DIFFUSE = true;
                         defines.DIFFUSE = true;
                     }
                     }
-                }              
+                }
             }
             }
 
 
             // Misc.
             // Misc.
@@ -105,10 +105,10 @@ module BABYLON {
                 defines.POINTSIZE = (this.pointsCloud || scene.forcePointsCloud);
                 defines.POINTSIZE = (this.pointsCloud || scene.forcePointsCloud);
                 defines.FOG = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE && this.fogEnabled);
                 defines.FOG = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE && this.fogEnabled);
             }
             }
-            
+
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
-            
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
+
             // Attribs
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
 
 
@@ -119,11 +119,11 @@ module BABYLON {
                 scene.resetCachedMaterial();
                 scene.resetCachedMaterial();
 
 
                 // Fallbacks
                 // Fallbacks
-                var fallbacks = new EffectFallbacks();             
+                var fallbacks = new EffectFallbacks();
                 if (defines.FOG) {
                 if (defines.FOG) {
                     fallbacks.addFallback(1, "FOG");
                     fallbacks.addFallback(1, "FOG");
                 }
                 }
-                
+
                 if (defines.NUM_BONE_INFLUENCERS > 0) {
                 if (defines.NUM_BONE_INFLUENCERS > 0) {
                     fallbacks.addCPUSkinningFallback(0, mesh);
                     fallbacks.addCPUSkinningFallback(0, mesh);
                 }
                 }
@@ -144,24 +144,24 @@ module BABYLON {
 
 
                 // Legacy browser patch
                 // Legacy browser patch
                 var shaderName = "fire";
                 var shaderName = "fire";
-                
+
                 var join = defines.toString();
                 var join = defines.toString();
                 subMesh.setEffect(scene.getEngine().createEffect(shaderName,
                 subMesh.setEffect(scene.getEngine().createEffect(shaderName,
                     {
                     {
                         attributes: attribs,
                         attributes: attribs,
                         uniformsNames: ["world", "view", "viewProjection", "vEyePosition",
                         uniformsNames: ["world", "view", "viewProjection", "vEyePosition",
-                                "vFogInfos", "vFogColor", "pointSize",
-                                "vDiffuseInfos", 
-                                "mBones",
-                                "vClipPlane", "diffuseMatrix",
-                                // Fire
-                                "time", "speed"
-                            ],
+                            "vFogInfos", "vFogColor", "pointSize",
+                            "vDiffuseInfos",
+                            "mBones",
+                            "vClipPlane", "diffuseMatrix",
+                            // Fire
+                            "time", "speed"
+                        ],
                         uniformBuffersNames: [],
                         uniformBuffersNames: [],
                         samplers: ["diffuseSampler",
                         samplers: ["diffuseSampler",
-                                // Fire
-                                "distortionSampler", "opacitySampler"
-                            ],
+                            // Fire
+                            "distortionSampler", "opacitySampler"
+                        ],
                         defines: join,
                         defines: join,
                         fallbacks: fallbacks,
                         fallbacks: fallbacks,
                         onCompiled: this.onCompiled,
                         onCompiled: this.onCompiled,
@@ -171,7 +171,7 @@ module BABYLON {
                         transformFeedbackVaryings: null
                         transformFeedbackVaryings: null
                     }, engine), defines);
                     }, engine), defines);
             }
             }
-            
+
             if (!subMesh.effect || !subMesh.effect.isReady()) {
             if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
@@ -210,11 +210,11 @@ module BABYLON {
 
 
                     this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
                     this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
                     this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
                     this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
-                    
+
                     this._activeEffect.setTexture("distortionSampler", this._distortionTexture);
                     this._activeEffect.setTexture("distortionSampler", this._distortionTexture);
                     this._activeEffect.setTexture("opacitySampler", this._opacityTexture);
                     this._activeEffect.setTexture("opacitySampler", this._opacityTexture);
                 }
                 }
-                
+
                 // Clip plane
                 // Clip plane
                 if (scene.clipPlane) {
                 if (scene.clipPlane) {
                     var clipPlane = scene.clipPlane;
                     var clipPlane = scene.clipPlane;
@@ -226,7 +226,7 @@ module BABYLON {
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                 }
                 }
 
 
-                MaterialHelper.BindEyePosition(effect, scene);               
+                MaterialHelper.BindEyePosition(effect, scene);
             }
             }
 
 
             this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
             this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
@@ -235,14 +235,14 @@ module BABYLON {
             if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
             if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
                 this._activeEffect.setMatrix("view", scene.getViewMatrix());
                 this._activeEffect.setMatrix("view", scene.getViewMatrix());
             }
             }
-            
+
             // Fog
             // Fog
             MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
             MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
-            
+
             // Time
             // Time
             this._lastTime += scene.getEngine().getDeltaTime();
             this._lastTime += scene.getEngine().getDeltaTime();
             this._activeEffect.setFloat("time", this._lastTime);
             this._activeEffect.setFloat("time", this._lastTime);
-            
+
             // Speed
             // Speed
             this._activeEffect.setFloat("speed", this.speed);
             this._activeEffect.setFloat("speed", this.speed);
 
 
@@ -294,18 +294,18 @@ module BABYLON {
 
 
             if (this._distortionTexture === texture) {
             if (this._distortionTexture === texture) {
                 return true;
                 return true;
-            }    
+            }
 
 
             if (this._opacityTexture === texture) {
             if (this._opacityTexture === texture) {
                 return true;
                 return true;
-            }            
+            }
 
 
-            return false;    
-        }         
+            return false;
+        }
 
 
         public getClassName(): string {
         public getClassName(): string {
             return "FireMaterial";
             return "FireMaterial";
-        }        
+        }
 
 
         public dispose(forceDisposeEffect?: boolean): void {
         public dispose(forceDisposeEffect?: boolean): void {
             if (this._diffuseTexture) {
             if (this._diffuseTexture) {
@@ -321,23 +321,23 @@ module BABYLON {
         public clone(name: string): FireMaterial {
         public clone(name: string): FireMaterial {
             return SerializationHelper.Clone<FireMaterial>(() => new FireMaterial(name, this.getScene()), this);
             return SerializationHelper.Clone<FireMaterial>(() => new FireMaterial(name, this.getScene()), this);
         }
         }
-		
-		public serialize(): any {
-		
+
+        public serialize(): any {
+
             var serializationObject = super.serialize();
             var serializationObject = super.serialize();
-            serializationObject.customType      = "BABYLON.FireMaterial";
-            serializationObject.diffuseColor    = this.diffuseColor.asArray();
-            serializationObject.speed           = this.speed;
+            serializationObject.customType = "BABYLON.FireMaterial";
+            serializationObject.diffuseColor = this.diffuseColor.asArray();
+            serializationObject.speed = this.speed;
 
 
             if (this._diffuseTexture) {
             if (this._diffuseTexture) {
                 serializationObject._diffuseTexture = this._diffuseTexture.serialize();
                 serializationObject._diffuseTexture = this._diffuseTexture.serialize();
             }
             }
-            
-			if (this._distortionTexture) {
+
+            if (this._distortionTexture) {
                 serializationObject._distortionTexture = this._distortionTexture.serialize();
                 serializationObject._distortionTexture = this._distortionTexture.serialize();
             }
             }
-			
-			if (this._opacityTexture) {
+
+            if (this._opacityTexture) {
                 serializationObject._opacityTexture = this._opacityTexture.serialize();
                 serializationObject._opacityTexture = this._opacityTexture.serialize();
             }
             }
 
 
@@ -347,12 +347,12 @@ module BABYLON {
         public static Parse(source: any, scene: Scene, rootUrl: string): FireMaterial {
         public static Parse(source: any, scene: Scene, rootUrl: string): FireMaterial {
             var material = new FireMaterial(source.name, scene);
             var material = new FireMaterial(source.name, scene);
 
 
-            material.diffuseColor   = Color3.FromArray(source.diffuseColor);
-            material.speed          = source.speed;
+            material.diffuseColor = Color3.FromArray(source.diffuseColor);
+            material.speed = source.speed;
 
 
-            material.alpha          = source.alpha;
+            material.alpha = source.alpha;
 
 
-            material.id             = source.id;
+            material.id = source.id;
 
 
             Tags.AddTagsTo(material, source.tags);
             Tags.AddTagsTo(material, source.tags);
             material.backFaceCulling = source.backFaceCulling;
             material.backFaceCulling = source.backFaceCulling;
@@ -365,8 +365,8 @@ module BABYLON {
             if (source._distortionTexture) {
             if (source._distortionTexture) {
                 material._distortionTexture = Texture.Parse(source._distortionTexture, scene, rootUrl);
                 material._distortionTexture = Texture.Parse(source._distortionTexture, scene, rootUrl);
             }
             }
-			
-			if (source._opacityTexture) {
+
+            if (source._opacityTexture) {
                 material._opacityTexture = Texture.Parse(source._opacityTexture, scene, rootUrl);
                 material._opacityTexture = Texture.Parse(source._opacityTexture, scene, rootUrl);
             }
             }
 
 
@@ -377,5 +377,5 @@ module BABYLON {
             return material;
             return material;
         }
         }
     }
     }
-} 
+}
 
 

+ 73 - 73
materialsLibrary/src/fur/babylon.furMaterial.ts

@@ -26,75 +26,75 @@ module BABYLON {
     }
     }
 
 
     export class FurMaterial extends PushMaterial {
     export class FurMaterial extends PushMaterial {
-        
+
         @serializeAsTexture("diffuseTexture")
         @serializeAsTexture("diffuseTexture")
         private _diffuseTexture: BaseTexture;
         private _diffuseTexture: BaseTexture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         public diffuseTexture: BaseTexture;
         public diffuseTexture: BaseTexture;
-        
+
         @serializeAsTexture("heightTexture")
         @serializeAsTexture("heightTexture")
         private _heightTexture: BaseTexture;
         private _heightTexture: BaseTexture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public heightTexture: BaseTexture;        
-        
+        public heightTexture: BaseTexture;
+
         @serializeAsColor3()
         @serializeAsColor3()
         public diffuseColor = new Color3(1, 1, 1);
         public diffuseColor = new Color3(1, 1, 1);
-        
+
         @serialize()
         @serialize()
         public furLength: number = 1;
         public furLength: number = 1;
-        
+
         @serialize()
         @serialize()
         public furAngle: number = 0;
         public furAngle: number = 0;
-        
+
         @serializeAsColor3()
         @serializeAsColor3()
-        public furColor = new Color3(0.44,0.21,0.02);
-        
+        public furColor = new Color3(0.44, 0.21, 0.02);
+
         @serialize()
         @serialize()
         public furOffset: number = 0.0;
         public furOffset: number = 0.0;
-        
+
         @serialize()
         @serialize()
         public furSpacing: number = 12;
         public furSpacing: number = 12;
-        
+
         @serializeAsVector3()
         @serializeAsVector3()
         public furGravity = new Vector3(0, 0, 0);
         public furGravity = new Vector3(0, 0, 0);
-        
+
         @serialize()
         @serialize()
         public furSpeed: number = 100;
         public furSpeed: number = 100;
-        
+
         @serialize()
         @serialize()
         public furDensity: number = 20;
         public furDensity: number = 20;
-        
+
         public furTexture: DynamicTexture;
         public furTexture: DynamicTexture;
-        
-        
+
+
         @serialize("disableLighting")
         @serialize("disableLighting")
         private _disableLighting = false;
         private _disableLighting = false;
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
-        public disableLighting: boolean;   
-        
+        public disableLighting: boolean;
+
         @serialize("maxSimultaneousLights")
         @serialize("maxSimultaneousLights")
         private _maxSimultaneousLights = 4;
         private _maxSimultaneousLights = 4;
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
-        public maxSimultaneousLights: number; 
-        
+        public maxSimultaneousLights: number;
+
         @serialize()
         @serialize()
         public highLevelFur: boolean = true;
         public highLevelFur: boolean = true;
-               
+
         public _meshes: AbstractMesh[];
         public _meshes: AbstractMesh[];
 
 
         private _renderId: number;
         private _renderId: number;
-        
+
         private _furTime: number = 0;
         private _furTime: number = 0;
 
 
         constructor(name: string, scene: Scene) {
         constructor(name: string, scene: Scene) {
             super(name, scene);
             super(name, scene);
         }
         }
-        
+
         @serialize()
         @serialize()
         public get furTime() {
         public get furTime() {
             return this._furTime;
             return this._furTime;
         }
         }
-        
+
         public set furTime(furTime: number) {
         public set furTime(furTime: number) {
             this._furTime = furTime;
             this._furTime = furTime;
         }
         }
@@ -110,11 +110,11 @@ module BABYLON {
         public getAlphaTestTexture(): Nullable<BaseTexture> {
         public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
             return null;
         }
         }
-        
+
         public updateFur(): void {
         public updateFur(): void {
             for (var i = 1; i < this._meshes.length; i++) {
             for (var i = 1; i < this._meshes.length; i++) {
                 var offsetFur = <FurMaterial>this._meshes[i].material;
                 var offsetFur = <FurMaterial>this._meshes[i].material;
-                
+
                 offsetFur.furLength = this.furLength;
                 offsetFur.furLength = this.furLength;
                 offsetFur.furAngle = this.furAngle;
                 offsetFur.furAngle = this.furAngle;
                 offsetFur.furGravity = this.furGravity;
                 offsetFur.furGravity = this.furGravity;
@@ -130,7 +130,7 @@ module BABYLON {
         }
         }
 
 
         // Methods   
         // Methods   
-        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {   
+        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {
             if (this.isFrozen) {
             if (this.isFrozen) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                     return true;
                     return true;
@@ -162,7 +162,7 @@ module BABYLON {
                             defines._needUVs = true;
                             defines._needUVs = true;
                             defines.DIFFUSE = true;
                             defines.DIFFUSE = true;
                         }
                         }
-                    } 
+                    }
                     if (this.heightTexture && engine.getCaps().maxVertexTextureImageUnits) {
                     if (this.heightTexture && engine.getCaps().maxVertexTextureImageUnits) {
                         if (!this.heightTexture.isReady()) {
                         if (!this.heightTexture.isReady()) {
                             return false;
                             return false;
@@ -170,7 +170,7 @@ module BABYLON {
                             defines._needUVs = true;
                             defines._needUVs = true;
                             defines.HEIGHTMAP = true;
                             defines.HEIGHTMAP = true;
                         }
                         }
-                    }               
+                    }
                 }
                 }
             }
             }
 
 
@@ -187,8 +187,8 @@ module BABYLON {
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
 
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
-            
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
+
             // Attribs
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
 
 
@@ -199,13 +199,13 @@ module BABYLON {
                 scene.resetCachedMaterial();
                 scene.resetCachedMaterial();
 
 
                 // Fallbacks
                 // Fallbacks
-                var fallbacks = new EffectFallbacks();             
+                var fallbacks = new EffectFallbacks();
                 if (defines.FOG) {
                 if (defines.FOG) {
                     fallbacks.addFallback(1, "FOG");
                     fallbacks.addFallback(1, "FOG");
                 }
                 }
 
 
                 MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
                 MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
-             
+
                 if (defines.NUM_BONE_INFLUENCERS > 0) {
                 if (defines.NUM_BONE_INFLUENCERS > 0) {
                     fallbacks.addCPUSkinningFallback(0, mesh);
                     fallbacks.addCPUSkinningFallback(0, mesh);
                 }
                 }
@@ -237,7 +237,7 @@ module BABYLON {
                 var join = defines.toString();
                 var join = defines.toString();
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
                     "vFogInfos", "vFogColor", "pointSize",
                     "vFogInfos", "vFogColor", "pointSize",
-                    "vDiffuseInfos", 
+                    "vDiffuseInfos",
                     "mBones",
                     "mBones",
                     "vClipPlane", "diffuseMatrix",
                     "vClipPlane", "diffuseMatrix",
                     "furLength", "furAngle", "furColor", "furOffset", "furGravity", "furTime", "furSpacing", "furDensity"
                     "furLength", "furAngle", "furColor", "furOffset", "furGravity", "furTime", "furSpacing", "furDensity"
@@ -245,17 +245,17 @@ module BABYLON {
                 var samplers = ["diffuseSampler",
                 var samplers = ["diffuseSampler",
                     "heightTexture", "furTexture"
                     "heightTexture", "furTexture"
                 ];
                 ];
-                
+
                 var uniformBuffers = new Array<string>()
                 var uniformBuffers = new Array<string>()
 
 
                 MaterialHelper.PrepareUniformsAndSamplersList(<EffectCreationOptions>{
                 MaterialHelper.PrepareUniformsAndSamplersList(<EffectCreationOptions>{
-                    uniformsNames: uniforms, 
+                    uniformsNames: uniforms,
                     uniformBuffersNames: uniformBuffers,
                     uniformBuffersNames: uniformBuffers,
-                    samplers: samplers, 
-                    defines: defines, 
+                    samplers: samplers,
+                    defines: defines,
                     maxSimultaneousLights: this.maxSimultaneousLights
                     maxSimultaneousLights: this.maxSimultaneousLights
                 });
                 });
-                
+
                 subMesh.setEffect(scene.getEngine().createEffect(shaderName,
                 subMesh.setEffect(scene.getEngine().createEffect(shaderName,
                     <EffectCreationOptions>{
                     <EffectCreationOptions>{
                         attributes: attribs,
                         attributes: attribs,
@@ -308,11 +308,11 @@ module BABYLON {
                     this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
                     this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
                     this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
                     this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
                 }
                 }
-                
+
                 if (this._heightTexture) {
                 if (this._heightTexture) {
                     this._activeEffect.setTexture("heightTexture", this._heightTexture);
                     this._activeEffect.setTexture("heightTexture", this._heightTexture);
                 }
                 }
-                
+
                 // Clip plane
                 // Clip plane
                 MaterialHelper.BindClipPlane(this._activeEffect, scene);
                 MaterialHelper.BindClipPlane(this._activeEffect, scene);
 
 
@@ -321,7 +321,7 @@ module BABYLON {
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                 }
                 }
 
 
-                MaterialHelper.BindEyePosition(effect, scene);               
+                MaterialHelper.BindEyePosition(effect, scene);
             }
             }
 
 
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
@@ -337,23 +337,23 @@ module BABYLON {
 
 
             // Fog
             // Fog
             MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
             MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
-            
+
             this._activeEffect.setFloat("furLength", this.furLength);
             this._activeEffect.setFloat("furLength", this.furLength);
             this._activeEffect.setFloat("furAngle", this.furAngle);
             this._activeEffect.setFloat("furAngle", this.furAngle);
             this._activeEffect.setColor4("furColor", this.furColor, 1.0);
             this._activeEffect.setColor4("furColor", this.furColor, 1.0);
-            
+
             if (this.highLevelFur) {
             if (this.highLevelFur) {
                 this._activeEffect.setVector3("furGravity", this.furGravity);
                 this._activeEffect.setVector3("furGravity", this.furGravity);
                 this._activeEffect.setFloat("furOffset", this.furOffset);
                 this._activeEffect.setFloat("furOffset", this.furOffset);
                 this._activeEffect.setFloat("furSpacing", this.furSpacing);
                 this._activeEffect.setFloat("furSpacing", this.furSpacing);
                 this._activeEffect.setFloat("furDensity", this.furDensity);
                 this._activeEffect.setFloat("furDensity", this.furDensity);
-                
+
                 this._furTime += this.getScene().getEngine().getDeltaTime() / this.furSpeed;
                 this._furTime += this.getScene().getEngine().getDeltaTime() / this.furSpeed;
                 this._activeEffect.setFloat("furTime", this._furTime);
                 this._activeEffect.setFloat("furTime", this._furTime);
-                
+
                 this._activeEffect.setTexture("furTexture", this.furTexture);
                 this._activeEffect.setTexture("furTexture", this.furTexture);
             }
             }
- 
+
             this._afterBind(mesh, this._activeEffect);
             this._afterBind(mesh, this._activeEffect);
         }
         }
 
 
@@ -363,7 +363,7 @@ module BABYLON {
             if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
             if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
                 results.push(this.diffuseTexture);
                 results.push(this.diffuseTexture);
             }
             }
-            
+
             if (this.heightTexture && this.heightTexture.animations && this.heightTexture.animations.length > 0) {
             if (this.heightTexture && this.heightTexture.animations && this.heightTexture.animations.length > 0) {
                 results.push(this.heightTexture);
                 results.push(this.heightTexture);
             }
             }
@@ -396,16 +396,16 @@ module BABYLON {
 
 
             if (this._heightTexture === texture) {
             if (this._heightTexture === texture) {
                 return true;
                 return true;
-            }        
+            }
 
 
-            return false;    
-        }        
+            return false;
+        }
 
 
         public dispose(forceDisposeEffect?: boolean): void {
         public dispose(forceDisposeEffect?: boolean): void {
             if (this.diffuseTexture) {
             if (this.diffuseTexture) {
                 this.diffuseTexture.dispose();
                 this.diffuseTexture.dispose();
             }
             }
-            
+
             if (this._meshes) {
             if (this._meshes) {
                 for (var i = 1; i < this._meshes.length; i++) {
                 for (var i = 1; i < this._meshes.length; i++) {
                     let mat = this._meshes[i].material;
                     let mat = this._meshes[i].material;
@@ -419,7 +419,7 @@ module BABYLON {
 
 
             super.dispose(forceDisposeEffect);
             super.dispose(forceDisposeEffect);
         }
         }
-        
+
         public clone(name: string): FurMaterial {
         public clone(name: string): FurMaterial {
             return SerializationHelper.Clone(() => new FurMaterial(name, this.getScene()), this);
             return SerializationHelper.Clone(() => new FurMaterial(name, this.getScene()), this);
         }
         }
@@ -427,23 +427,23 @@ module BABYLON {
         public serialize(): any {
         public serialize(): any {
             var serializationObject = SerializationHelper.Serialize(this);
             var serializationObject = SerializationHelper.Serialize(this);
             serializationObject.customType = "BABYLON.FurMaterial";
             serializationObject.customType = "BABYLON.FurMaterial";
-            
+
             if (this._meshes) {
             if (this._meshes) {
                 serializationObject.sourceMeshName = this._meshes[0].name;
                 serializationObject.sourceMeshName = this._meshes[0].name;
                 serializationObject.quality = this._meshes.length;
                 serializationObject.quality = this._meshes.length;
             }
             }
-            
+
             return serializationObject;
             return serializationObject;
         }
         }
 
 
         public getClassName(): string {
         public getClassName(): string {
             return "FurMaterial";
             return "FurMaterial";
-        }          
+        }
 
 
         // Statics
         // Statics
         public static Parse(source: any, scene: Scene, rootUrl: string): FurMaterial {
         public static Parse(source: any, scene: Scene, rootUrl: string): FurMaterial {
             var material = SerializationHelper.Parse(() => new FurMaterial(source.name, scene), source, scene, rootUrl);
             var material = SerializationHelper.Parse(() => new FurMaterial(source.name, scene), source, scene, rootUrl);
-            
+
             if (source.sourceMeshName && material.highLevelFur) {
             if (source.sourceMeshName && material.highLevelFur) {
                 scene.executeWhenReady(() => {
                 scene.executeWhenReady(() => {
                     var sourceMesh = <Mesh>scene.getMeshByName(source.sourceMeshName);
                     var sourceMesh = <Mesh>scene.getMeshByName(source.sourceMeshName);
@@ -454,27 +454,27 @@ module BABYLON {
                     }
                     }
                 });
                 });
             }
             }
-            
+
             return material;
             return material;
         }
         }
-        
+
         public static GenerateTexture(name: string, scene: Scene): DynamicTexture {
         public static GenerateTexture(name: string, scene: Scene): DynamicTexture {
             // Generate fur textures
             // Generate fur textures
             var texture = new DynamicTexture("FurTexture " + name, 256, scene, true);
             var texture = new DynamicTexture("FurTexture " + name, 256, scene, true);
             var context = texture.getContext();
             var context = texture.getContext();
-            
-            for ( var i = 0; i < 20000; ++i ) {
+
+            for (var i = 0; i < 20000; ++i) {
                 context.fillStyle = "rgba(255, " + Math.floor(Math.random() * 255) + ", " + Math.floor(Math.random() * 255) + ", 1)";
                 context.fillStyle = "rgba(255, " + Math.floor(Math.random() * 255) + ", " + Math.floor(Math.random() * 255) + ", 1)";
                 context.fillRect((Math.random() * texture.getSize().width), (Math.random() * texture.getSize().height), 2, 2);
                 context.fillRect((Math.random() * texture.getSize().width), (Math.random() * texture.getSize().height), 2, 2);
             }
             }
-            
+
             texture.update(false);
             texture.update(false);
             texture.wrapU = Texture.WRAP_ADDRESSMODE;
             texture.wrapU = Texture.WRAP_ADDRESSMODE;
             texture.wrapV = Texture.WRAP_ADDRESSMODE;
             texture.wrapV = Texture.WRAP_ADDRESSMODE;
-            
+
             return texture;
             return texture;
         }
         }
-        
+
         // Creates and returns an array of meshes used as shells for the Fur Material
         // Creates and returns an array of meshes used as shells for the Fur Material
         // that can be disposed later in your code
         // that can be disposed later in your code
         // The quality is in interval [0, 100]
         // The quality is in interval [0, 100]
@@ -482,17 +482,17 @@ module BABYLON {
             var meshes = [sourceMesh];
             var meshes = [sourceMesh];
             var mat: FurMaterial = <FurMaterial>sourceMesh.material;
             var mat: FurMaterial = <FurMaterial>sourceMesh.material;
             var i;
             var i;
-            
+
             if (!(mat instanceof FurMaterial)) {
             if (!(mat instanceof FurMaterial)) {
                 throw "The material of the source mesh must be a Fur Material";
                 throw "The material of the source mesh must be a Fur Material";
             }
             }
-            
+
             for (i = 1; i < quality; i++) {
             for (i = 1; i < quality; i++) {
                 var offsetFur = new BABYLON.FurMaterial(mat.name + i, sourceMesh.getScene());
                 var offsetFur = new BABYLON.FurMaterial(mat.name + i, sourceMesh.getScene());
                 sourceMesh.getScene().materials.pop();
                 sourceMesh.getScene().materials.pop();
                 Tags.EnableFor(offsetFur);
                 Tags.EnableFor(offsetFur);
                 Tags.AddTagsTo(offsetFur, "furShellMaterial");
                 Tags.AddTagsTo(offsetFur, "furShellMaterial");
-                
+
                 offsetFur.furLength = mat.furLength;
                 offsetFur.furLength = mat.furLength;
                 offsetFur.furAngle = mat.furAngle;
                 offsetFur.furAngle = mat.furAngle;
                 offsetFur.furGravity = mat.furGravity;
                 offsetFur.furGravity = mat.furGravity;
@@ -505,23 +505,23 @@ module BABYLON {
                 offsetFur.highLevelFur = mat.highLevelFur;
                 offsetFur.highLevelFur = mat.highLevelFur;
                 offsetFur.furTime = mat.furTime;
                 offsetFur.furTime = mat.furTime;
                 offsetFur.furDensity = mat.furDensity;
                 offsetFur.furDensity = mat.furDensity;
-                
+
                 var offsetMesh = sourceMesh.clone(sourceMesh.name + i);
                 var offsetMesh = sourceMesh.clone(sourceMesh.name + i);
-                
+
                 offsetMesh.material = offsetFur;
                 offsetMesh.material = offsetFur;
                 offsetMesh.skeleton = sourceMesh.skeleton;
                 offsetMesh.skeleton = sourceMesh.skeleton;
                 offsetMesh.position = Vector3.Zero();
                 offsetMesh.position = Vector3.Zero();
                 meshes.push(offsetMesh);
                 meshes.push(offsetMesh);
             }
             }
-            
+
             for (i = 1; i < meshes.length; i++) {
             for (i = 1; i < meshes.length; i++) {
                 meshes[i].parent = sourceMesh;
                 meshes[i].parent = sourceMesh;
             }
             }
-            
+
             (<FurMaterial>sourceMesh.material)._meshes = meshes;
             (<FurMaterial>sourceMesh.material)._meshes = meshes;
-            
+
             return meshes;
             return meshes;
         }
         }
     }
     }
-} 
+}
 
 

+ 19 - 19
materialsLibrary/src/gradient/babylon.gradientMaterial.ts

@@ -27,7 +27,7 @@ module BABYLON {
         public POINTLIGHT0 = false;
         public POINTLIGHT0 = false;
         public POINTLIGHT1 = false;
         public POINTLIGHT1 = false;
         public POINTLIGHT2 = false;
         public POINTLIGHT2 = false;
-        public POINTLIGHT3 = false;        
+        public POINTLIGHT3 = false;
         public SHADOW0 = false;
         public SHADOW0 = false;
         public SHADOW1 = false;
         public SHADOW1 = false;
         public SHADOW2 = false;
         public SHADOW2 = false;
@@ -57,30 +57,30 @@ module BABYLON {
     }
     }
 
 
     export class GradientMaterial extends PushMaterial {
     export class GradientMaterial extends PushMaterial {
-          
+
         @serialize("maxSimultaneousLights")
         @serialize("maxSimultaneousLights")
         private _maxSimultaneousLights = 4;
         private _maxSimultaneousLights = 4;
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
-        public maxSimultaneousLights: number;       
+        public maxSimultaneousLights: number;
 
 
         // The gradient top color, red by default
         // The gradient top color, red by default
         @serializeAsColor3()
         @serializeAsColor3()
         public topColor = new Color3(1, 0, 0);
         public topColor = new Color3(1, 0, 0);
-        
+
         @serialize()
         @serialize()
         public topColorAlpha = 1.0;
         public topColorAlpha = 1.0;
 
 
         // The gradient top color, blue by default
         // The gradient top color, blue by default
         @serializeAsColor3()
         @serializeAsColor3()
         public bottomColor = new Color3(0, 0, 1);
         public bottomColor = new Color3(0, 0, 1);
-        
+
         @serialize()
         @serialize()
         public bottomColorAlpha = 1.0;
         public bottomColorAlpha = 1.0;
 
 
         // Gradient offset
         // Gradient offset
         @serialize()
         @serialize()
         public offset = 0;
         public offset = 0;
-        
+
         @serialize()
         @serialize()
         public smoothness = 1.0;
         public smoothness = 1.0;
 
 
@@ -106,7 +106,7 @@ module BABYLON {
         }
         }
 
 
         // Methods   
         // Methods   
-        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {   
+        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {
             if (this.isFrozen) {
             if (this.isFrozen) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                     return true;
                     return true;
@@ -128,7 +128,7 @@ module BABYLON {
 
 
             var engine = scene.getEngine();
             var engine = scene.getEngine();
 
 
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
 
 
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
 
 
@@ -144,13 +144,13 @@ module BABYLON {
                 scene.resetCachedMaterial();
                 scene.resetCachedMaterial();
 
 
                 // Fallbacks
                 // Fallbacks
-                var fallbacks = new EffectFallbacks();             
+                var fallbacks = new EffectFallbacks();
                 if (defines.FOG) {
                 if (defines.FOG) {
                     fallbacks.addFallback(1, "FOG");
                     fallbacks.addFallback(1, "FOG");
                 }
                 }
 
 
                 MaterialHelper.HandleFallbacksForShadows(defines, fallbacks);
                 MaterialHelper.HandleFallbacksForShadows(defines, fallbacks);
-             
+
                 if (defines.NUM_BONE_INFLUENCERS > 0) {
                 if (defines.NUM_BONE_INFLUENCERS > 0) {
                     fallbacks.addCPUSkinningFallback(0, mesh);
                     fallbacks.addCPUSkinningFallback(0, mesh);
                 }
                 }
@@ -184,7 +184,7 @@ module BABYLON {
 
 
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
                     "vFogInfos", "vFogColor", "pointSize",
                     "vFogInfos", "vFogColor", "pointSize",
-                    "vDiffuseInfos", 
+                    "vDiffuseInfos",
                     "mBones",
                     "mBones",
                     "vClipPlane", "diffuseMatrix",
                     "vClipPlane", "diffuseMatrix",
                     "topColor", "bottomColor", "offset", "smoothness"
                     "topColor", "bottomColor", "offset", "smoothness"
@@ -193,13 +193,13 @@ module BABYLON {
                 var uniformBuffers = new Array<string>();
                 var uniformBuffers = new Array<string>();
 
 
                 MaterialHelper.PrepareUniformsAndSamplersList(<EffectCreationOptions>{
                 MaterialHelper.PrepareUniformsAndSamplersList(<EffectCreationOptions>{
-                    uniformsNames: uniforms, 
+                    uniformsNames: uniforms,
                     uniformBuffersNames: uniformBuffers,
                     uniformBuffersNames: uniformBuffers,
-                    samplers: samplers, 
-                    defines: defines, 
+                    samplers: samplers,
+                    defines: defines,
                     maxSimultaneousLights: 4
                     maxSimultaneousLights: 4
                 });
                 });
-                
+
                 subMesh.setEffect(scene.getEngine().createEffect(shaderName,
                 subMesh.setEffect(scene.getEngine().createEffect(shaderName,
                     <EffectCreationOptions>{
                     <EffectCreationOptions>{
                         attributes: attribs,
                         attributes: attribs,
@@ -237,7 +237,7 @@ module BABYLON {
             }
             }
 
 
             this._activeEffect = effect;
             this._activeEffect = effect;
-            
+
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
             this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
             this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
@@ -254,7 +254,7 @@ module BABYLON {
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                 }
                 }
 
 
-                MaterialHelper.BindEyePosition(effect, scene);              
+                MaterialHelper.BindEyePosition(effect, scene);
             }
             }
 
 
             this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
             this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
@@ -300,12 +300,12 @@ module BABYLON {
 
 
         public getClassName(): string {
         public getClassName(): string {
             return "GradientMaterial";
             return "GradientMaterial";
-        }              
+        }
 
 
         // Statics
         // Statics
         public static Parse(source: any, scene: Scene, rootUrl: string): GradientMaterial {
         public static Parse(source: any, scene: Scene, rootUrl: string): GradientMaterial {
             return SerializationHelper.Parse(() => new GradientMaterial(source.name, scene), source, scene, rootUrl);
             return SerializationHelper.Parse(() => new GradientMaterial(source.name, scene), source, scene, rootUrl);
         }
         }
     }
     }
-} 
+}
 
 

+ 29 - 29
materialsLibrary/src/lava/babylon.lavaMaterial.ts

@@ -61,39 +61,39 @@ module BABYLON {
         private _diffuseTexture: BaseTexture;
         private _diffuseTexture: BaseTexture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         public diffuseTexture: BaseTexture;
         public diffuseTexture: BaseTexture;
-        
+
         @serializeAsTexture()
         @serializeAsTexture()
         public noiseTexture: BaseTexture;
         public noiseTexture: BaseTexture;
-        
+
         @serializeAsColor3()
         @serializeAsColor3()
         public fogColor: Color3;
         public fogColor: Color3;
-        
+
         @serialize()
         @serialize()
-        public speed : number = 1;
-        
+        public speed: number = 1;
+
         @serialize()
         @serialize()
-        public movingSpeed : number = 1;
-        
+        public movingSpeed: number = 1;
+
         @serialize()
         @serialize()
-        public lowFrequencySpeed : number = 1;
-        
+        public lowFrequencySpeed: number = 1;
+
         @serialize()
         @serialize()
-        public fogDensity : number = 0.15;
+        public fogDensity: number = 0.15;
 
 
-        private _lastTime : number = 0;
+        private _lastTime: number = 0;
 
 
         @serializeAsColor3()
         @serializeAsColor3()
         public diffuseColor = new Color3(1, 1, 1);
         public diffuseColor = new Color3(1, 1, 1);
-        
+
         @serialize("disableLighting")
         @serialize("disableLighting")
         private _disableLighting = false;
         private _disableLighting = false;
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
-        public disableLighting: boolean;   
+        public disableLighting: boolean;
 
 
         @serialize("maxSimultaneousLights")
         @serialize("maxSimultaneousLights")
         private _maxSimultaneousLights = 4;
         private _maxSimultaneousLights = 4;
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
-        public maxSimultaneousLights: number; 
+        public maxSimultaneousLights: number;
 
 
         private _scaledDiffuse = new Color3();
         private _scaledDiffuse = new Color3();
         private _renderId: number;
         private _renderId: number;
@@ -115,7 +115,7 @@ module BABYLON {
         }
         }
 
 
         // Methods   
         // Methods   
-        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {   
+        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {
             if (this.isFrozen) {
             if (this.isFrozen) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                     return true;
                     return true;
@@ -148,19 +148,19 @@ module BABYLON {
                             defines._needUVs = true;
                             defines._needUVs = true;
                             defines.DIFFUSE = true;
                             defines.DIFFUSE = true;
                         }
                         }
-                    }                
+                    }
                 }
                 }
             }
             }
 
 
-               // Misc.
+            // Misc.
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
 
 
             // Lights
             // Lights
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
 
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
-            
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
+
             // Attribs
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
 
 
@@ -212,8 +212,8 @@ module BABYLON {
                     "vDiffuseInfos",
                     "vDiffuseInfos",
                     "mBones",
                     "mBones",
                     "vClipPlane", "diffuseMatrix",
                     "vClipPlane", "diffuseMatrix",
-                    "time", "speed","movingSpeed",
-                    "fogColor","fogDensity", "lowFrequencySpeed"
+                    "time", "speed", "movingSpeed",
+                    "fogColor", "fogDensity", "lowFrequencySpeed"
                 ];
                 ];
 
 
                 var samplers = ["diffuseSampler",
                 var samplers = ["diffuseSampler",
@@ -222,10 +222,10 @@ module BABYLON {
                 var uniformBuffers = new Array<string>()
                 var uniformBuffers = new Array<string>()
 
 
                 MaterialHelper.PrepareUniformsAndSamplersList(<EffectCreationOptions>{
                 MaterialHelper.PrepareUniformsAndSamplersList(<EffectCreationOptions>{
-                    uniformsNames: uniforms, 
+                    uniformsNames: uniforms,
                     uniformBuffersNames: uniformBuffers,
                     uniformBuffersNames: uniformBuffers,
-                    samplers: samplers, 
-                    defines: defines, 
+                    samplers: samplers,
+                    defines: defines,
                     maxSimultaneousLights: this.maxSimultaneousLights
                     maxSimultaneousLights: this.maxSimultaneousLights
                 });
                 });
 
 
@@ -248,7 +248,7 @@ module BABYLON {
 
 
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
             this._wasPreviouslyReady = true;
             this._wasPreviouslyReady = true;
-            
+
             return true;
             return true;
         }
         }
 
 
@@ -316,7 +316,7 @@ module BABYLON {
             this._lastTime += scene.getEngine().getDeltaTime();
             this._lastTime += scene.getEngine().getDeltaTime();
             this._activeEffect.setFloat("time", this._lastTime * this.speed / 1000);
             this._activeEffect.setFloat("time", this._lastTime * this.speed / 1000);
 
 
-            if (! this.fogColor) {
+            if (!this.fogColor) {
                 this.fogColor = Color3.Black();
                 this.fogColor = Color3.Black();
             }
             }
             this._activeEffect.setColor3("fogColor", this.fogColor);
             this._activeEffect.setColor3("fogColor", this.fogColor);
@@ -360,9 +360,9 @@ module BABYLON {
             if (this.diffuseTexture === texture) {
             if (this.diffuseTexture === texture) {
                 return true;
                 return true;
             }
             }
-            
-            return false;    
-        }        
+
+            return false;
+        }
 
 
         public dispose(forceDisposeEffect?: boolean): void {
         public dispose(forceDisposeEffect?: boolean): void {
             if (this.diffuseTexture) {
             if (this.diffuseTexture) {

+ 23 - 23
materialsLibrary/src/normal/babylon.normalMaterial.ts

@@ -27,7 +27,7 @@ module BABYLON {
         public POINTLIGHT0 = false;
         public POINTLIGHT0 = false;
         public POINTLIGHT1 = false;
         public POINTLIGHT1 = false;
         public POINTLIGHT2 = false;
         public POINTLIGHT2 = false;
-        public POINTLIGHT3 = false;        
+        public POINTLIGHT3 = false;
         public SHADOW0 = false;
         public SHADOW0 = false;
         public SHADOW1 = false;
         public SHADOW1 = false;
         public SHADOW2 = false;
         public SHADOW2 = false;
@@ -64,16 +64,16 @@ module BABYLON {
 
 
         @serializeAsColor3()
         @serializeAsColor3()
         public diffuseColor = new Color3(1, 1, 1);
         public diffuseColor = new Color3(1, 1, 1);
-        
+
         @serialize("disableLighting")
         @serialize("disableLighting")
         private _disableLighting = false;
         private _disableLighting = false;
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
-        public disableLighting: boolean;   
-        
+        public disableLighting: boolean;
+
         @serialize("maxSimultaneousLights")
         @serialize("maxSimultaneousLights")
         private _maxSimultaneousLights = 4;
         private _maxSimultaneousLights = 4;
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
-        public maxSimultaneousLights: number; 
+        public maxSimultaneousLights: number;
 
 
         private _renderId: number;
         private _renderId: number;
 
 
@@ -94,7 +94,7 @@ module BABYLON {
         }
         }
 
 
         // Methods   
         // Methods   
-        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {   
+        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {
             if (this.isFrozen) {
             if (this.isFrozen) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                     return true;
                     return true;
@@ -116,7 +116,7 @@ module BABYLON {
 
 
             var engine = scene.getEngine();
             var engine = scene.getEngine();
 
 
-             // Textures
+            // Textures
             if (defines._areTexturesDirty) {
             if (defines._areTexturesDirty) {
                 defines._needUVs = false;
                 defines._needUVs = false;
                 if (scene.texturesEnabled) {
                 if (scene.texturesEnabled) {
@@ -127,7 +127,7 @@ module BABYLON {
                             defines._needUVs = true;
                             defines._needUVs = true;
                             defines.DIFFUSE = true;
                             defines.DIFFUSE = true;
                         }
                         }
-                    }                
+                    }
                 }
                 }
             }
             }
 
 
@@ -138,8 +138,8 @@ module BABYLON {
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
 
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
-            
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
+
             // Attribs
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
 
 
@@ -150,13 +150,13 @@ module BABYLON {
                 scene.resetCachedMaterial();
                 scene.resetCachedMaterial();
 
 
                 // Fallbacks
                 // Fallbacks
-                var fallbacks = new EffectFallbacks();             
+                var fallbacks = new EffectFallbacks();
                 if (defines.FOG) {
                 if (defines.FOG) {
                     fallbacks.addFallback(1, "FOG");
                     fallbacks.addFallback(1, "FOG");
                 }
                 }
 
 
                 MaterialHelper.HandleFallbacksForShadows(defines, fallbacks);
                 MaterialHelper.HandleFallbacksForShadows(defines, fallbacks);
-                
+
                 if (defines.NUM_BONE_INFLUENCERS > 0) {
                 if (defines.NUM_BONE_INFLUENCERS > 0) {
                     fallbacks.addCPUSkinningFallback(0, mesh);
                     fallbacks.addCPUSkinningFallback(0, mesh);
                 }
                 }
@@ -188,7 +188,7 @@ module BABYLON {
 
 
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
                     "vFogInfos", "vFogColor", "pointSize",
                     "vFogInfos", "vFogColor", "pointSize",
-                    "vDiffuseInfos", 
+                    "vDiffuseInfos",
                     "mBones",
                     "mBones",
                     "vClipPlane", "diffuseMatrix"
                     "vClipPlane", "diffuseMatrix"
                 ];
                 ];
@@ -196,10 +196,10 @@ module BABYLON {
                 var uniformBuffers = new Array<string>()
                 var uniformBuffers = new Array<string>()
 
 
                 MaterialHelper.PrepareUniformsAndSamplersList(<EffectCreationOptions>{
                 MaterialHelper.PrepareUniformsAndSamplersList(<EffectCreationOptions>{
-                    uniformsNames: uniforms, 
+                    uniformsNames: uniforms,
                     uniformBuffersNames: uniformBuffers,
                     uniformBuffersNames: uniformBuffers,
-                    samplers: samplers, 
-                    defines: defines, 
+                    samplers: samplers,
+                    defines: defines,
                     maxSimultaneousLights: 4
                     maxSimultaneousLights: 4
                 });
                 });
 
 
@@ -263,14 +263,14 @@ module BABYLON {
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                 }
                 }
 
 
-                MaterialHelper.BindEyePosition(effect, scene);            
+                MaterialHelper.BindEyePosition(effect, scene);
             }
             }
 
 
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
 
 
             // Lights
             // Lights
             if (scene.lightsEnabled && !this.disableLighting) {
             if (scene.lightsEnabled && !this.disableLighting) {
-                MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines);          
+                MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines);
             }
             }
 
 
             // View
             // View
@@ -311,10 +311,10 @@ module BABYLON {
 
 
             if (this.diffuseTexture === texture) {
             if (this.diffuseTexture === texture) {
                 return true;
                 return true;
-            }  
+            }
 
 
-            return false;    
-        }        
+            return false;
+        }
 
 
         public dispose(forceDisposeEffect?: boolean): void {
         public dispose(forceDisposeEffect?: boolean): void {
             if (this.diffuseTexture) {
             if (this.diffuseTexture) {
@@ -336,12 +336,12 @@ module BABYLON {
 
 
         public getClassName(): string {
         public getClassName(): string {
             return "NormalMaterial";
             return "NormalMaterial";
-        }        
+        }
 
 
         // Statics
         // Statics
         public static Parse(source: any, scene: Scene, rootUrl: string): NormalMaterial {
         public static Parse(source: any, scene: Scene, rootUrl: string): NormalMaterial {
             return SerializationHelper.Parse(() => new NormalMaterial(source.name, scene), source, scene, rootUrl);
             return SerializationHelper.Parse(() => new NormalMaterial(source.name, scene), source, scene, rootUrl);
         }
         }
     }
     }
-} 
+}
 
 

+ 18 - 18
materialsLibrary/src/shadowOnly/babylon.shadowOnlyMaterial.ts

@@ -42,10 +42,10 @@ module BABYLON {
 
 
         public set activeLight(light: IShadowLight) {
         public set activeLight(light: IShadowLight) {
             this._activeLight = light;
             this._activeLight = light;
-        }        
+        }
 
 
         // Methods   
         // Methods   
-        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {   
+        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {
             if (this.isFrozen) {
             if (this.isFrozen) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                     return true;
                     return true;
@@ -86,7 +86,7 @@ module BABYLON {
                 }
                 }
             }
             }
 
 
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
 
 
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
 
 
@@ -102,13 +102,13 @@ module BABYLON {
                 scene.resetCachedMaterial();
                 scene.resetCachedMaterial();
 
 
                 // Fallbacks
                 // Fallbacks
-                var fallbacks = new EffectFallbacks();             
+                var fallbacks = new EffectFallbacks();
                 if (defines.FOG) {
                 if (defines.FOG) {
                     fallbacks.addFallback(1, "FOG");
                     fallbacks.addFallback(1, "FOG");
                 }
                 }
 
 
                 MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, 1);
                 MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, 1);
-                
+
                 if (defines.NUM_BONE_INFLUENCERS > 0) {
                 if (defines.NUM_BONE_INFLUENCERS > 0) {
                     fallbacks.addCPUSkinningFallback(0, mesh);
                     fallbacks.addCPUSkinningFallback(0, mesh);
                 }
                 }
@@ -126,22 +126,22 @@ module BABYLON {
                 var shaderName = "shadowOnly";
                 var shaderName = "shadowOnly";
                 var join = defines.toString();
                 var join = defines.toString();
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType",
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType",
-                                "vFogInfos", "vFogColor", "pointSize", "alpha",
-                                "mBones",
-                                "vClipPlane"
+                    "vFogInfos", "vFogColor", "pointSize", "alpha",
+                    "mBones",
+                    "vClipPlane"
                 ];
                 ];
                 var samplers = new Array<string>();
                 var samplers = new Array<string>();
-                
+
                 var uniformBuffers = new Array<string>()
                 var uniformBuffers = new Array<string>()
 
 
                 MaterialHelper.PrepareUniformsAndSamplersList(<EffectCreationOptions>{
                 MaterialHelper.PrepareUniformsAndSamplersList(<EffectCreationOptions>{
-                    uniformsNames: uniforms, 
+                    uniformsNames: uniforms,
                     uniformBuffersNames: uniformBuffers,
                     uniformBuffersNames: uniformBuffers,
-                    samplers: samplers, 
-                    defines: defines, 
+                    samplers: samplers,
+                    defines: defines,
                     maxSimultaneousLights: 1
                     maxSimultaneousLights: 1
                 });
                 });
-                
+
                 subMesh.setEffect(scene.getEngine().createEffect(shaderName,
                 subMesh.setEffect(scene.getEngine().createEffect(shaderName,
                     <EffectCreationOptions>{
                     <EffectCreationOptions>{
                         attributes: attribs,
                         attributes: attribs,
@@ -197,12 +197,12 @@ module BABYLON {
 
 
                 this._activeEffect.setFloat("alpha", this.alpha);
                 this._activeEffect.setFloat("alpha", this.alpha);
 
 
-                MaterialHelper.BindEyePosition(effect, scene);             
+                MaterialHelper.BindEyePosition(effect, scene);
             }
             }
 
 
             // Lights
             // Lights
             if (scene.lightsEnabled) {
             if (scene.lightsEnabled) {
-                MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, 1);          
+                MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, 1);
             }
             }
 
 
             // View
             // View
@@ -219,7 +219,7 @@ module BABYLON {
         public clone(name: string): ShadowOnlyMaterial {
         public clone(name: string): ShadowOnlyMaterial {
             return SerializationHelper.Clone<ShadowOnlyMaterial>(() => new ShadowOnlyMaterial(name, this.getScene()), this);
             return SerializationHelper.Clone<ShadowOnlyMaterial>(() => new ShadowOnlyMaterial(name, this.getScene()), this);
         }
         }
-        
+
         public serialize(): any {
         public serialize(): any {
             var serializationObject = SerializationHelper.Serialize(this);
             var serializationObject = SerializationHelper.Serialize(this);
             serializationObject.customType = "BABYLON.ShadowOnlyMaterial";
             serializationObject.customType = "BABYLON.ShadowOnlyMaterial";
@@ -228,12 +228,12 @@ module BABYLON {
 
 
         public getClassName(): string {
         public getClassName(): string {
             return "ShadowOnlyMaterial";
             return "ShadowOnlyMaterial";
-        }               
+        }
 
 
         // Statics
         // Statics
         public static Parse(source: any, scene: Scene, rootUrl: string): ShadowOnlyMaterial {
         public static Parse(source: any, scene: Scene, rootUrl: string): ShadowOnlyMaterial {
             return SerializationHelper.Parse(() => new ShadowOnlyMaterial(source.name, scene), source, scene, rootUrl);
             return SerializationHelper.Parse(() => new ShadowOnlyMaterial(source.name, scene), source, scene, rootUrl);
         }
         }
     }
     }
-} 
+}
 
 

+ 27 - 27
materialsLibrary/src/simple/babylon.simpleMaterial.ts

@@ -31,16 +31,16 @@ module BABYLON {
 
 
         @serializeAsColor3("diffuse")
         @serializeAsColor3("diffuse")
         public diffuseColor = new Color3(1, 1, 1);
         public diffuseColor = new Color3(1, 1, 1);
-        
+
         @serialize("disableLighting")
         @serialize("disableLighting")
         private _disableLighting = false;
         private _disableLighting = false;
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
-        public disableLighting: boolean;   
-        
+        public disableLighting: boolean;
+
         @serialize("maxSimultaneousLights")
         @serialize("maxSimultaneousLights")
         private _maxSimultaneousLights = 4;
         private _maxSimultaneousLights = 4;
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
-        public maxSimultaneousLights: number; 
+        public maxSimultaneousLights: number;
 
 
         private _renderId: number;
         private _renderId: number;
 
 
@@ -61,7 +61,7 @@ module BABYLON {
         }
         }
 
 
         // Methods   
         // Methods   
-        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {   
+        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {
             if (this.isFrozen) {
             if (this.isFrozen) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                     return true;
                     return true;
@@ -94,7 +94,7 @@ module BABYLON {
                             defines._needUVs = true;
                             defines._needUVs = true;
                             defines.DIFFUSE = true;
                             defines.DIFFUSE = true;
                         }
                         }
-                    }                
+                    }
                 }
                 }
             }
             }
 
 
@@ -105,8 +105,8 @@ module BABYLON {
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
 
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
-            
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
+
             // Attribs
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
 
 
@@ -116,13 +116,13 @@ module BABYLON {
                 scene.resetCachedMaterial();
                 scene.resetCachedMaterial();
 
 
                 // Fallbacks
                 // Fallbacks
-                var fallbacks = new EffectFallbacks();             
+                var fallbacks = new EffectFallbacks();
                 if (defines.FOG) {
                 if (defines.FOG) {
                     fallbacks.addFallback(1, "FOG");
                     fallbacks.addFallback(1, "FOG");
                 }
                 }
 
 
                 MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
                 MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
-                
+
                 if (defines.NUM_BONE_INFLUENCERS > 0) {
                 if (defines.NUM_BONE_INFLUENCERS > 0) {
                     fallbacks.addCPUSkinningFallback(0, mesh);
                     fallbacks.addCPUSkinningFallback(0, mesh);
                 }
                 }
@@ -152,19 +152,19 @@ module BABYLON {
                 var shaderName = "simple";
                 var shaderName = "simple";
                 var join = defines.toString();
                 var join = defines.toString();
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
-                                "vFogInfos", "vFogColor", "pointSize",
-                                "vDiffuseInfos", 
-                                "mBones",
-                                "vClipPlane", "diffuseMatrix"
+                    "vFogInfos", "vFogColor", "pointSize",
+                    "vDiffuseInfos",
+                    "mBones",
+                    "vClipPlane", "diffuseMatrix"
                 ];
                 ];
                 var samplers = ["diffuseSampler"];
                 var samplers = ["diffuseSampler"];
                 var uniformBuffers = new Array<string>()
                 var uniformBuffers = new Array<string>()
 
 
                 MaterialHelper.PrepareUniformsAndSamplersList(<EffectCreationOptions>{
                 MaterialHelper.PrepareUniformsAndSamplersList(<EffectCreationOptions>{
-                    uniformsNames: uniforms, 
+                    uniformsNames: uniforms,
                     uniformBuffersNames: uniformBuffers,
                     uniformBuffersNames: uniformBuffers,
-                    samplers: samplers, 
-                    defines: defines, 
+                    samplers: samplers,
+                    defines: defines,
                     maxSimultaneousLights: this.maxSimultaneousLights
                     maxSimultaneousLights: this.maxSimultaneousLights
                 });
                 });
                 subMesh.setEffect(scene.getEngine().createEffect(shaderName,
                 subMesh.setEffect(scene.getEngine().createEffect(shaderName,
@@ -220,7 +220,7 @@ module BABYLON {
                     this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
                     this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
                     this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
                     this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
                 }
                 }
-                
+
                 // Clip plane
                 // Clip plane
                 MaterialHelper.BindClipPlane(this._activeEffect, scene);
                 MaterialHelper.BindClipPlane(this._activeEffect, scene);
 
 
@@ -229,14 +229,14 @@ module BABYLON {
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                 }
                 }
 
 
-                MaterialHelper.BindEyePosition(effect, scene);            
+                MaterialHelper.BindEyePosition(effect, scene);
             }
             }
 
 
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
 
 
             // Lights
             // Lights
             if (scene.lightsEnabled && !this.disableLighting) {
             if (scene.lightsEnabled && !this.disableLighting) {
-                MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);          
+                MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
             }
             }
 
 
             // View
             // View
@@ -277,10 +277,10 @@ module BABYLON {
 
 
             if (this.diffuseTexture === texture) {
             if (this.diffuseTexture === texture) {
                 return true;
                 return true;
-            } 
+            }
 
 
-            return false;    
-        }        
+            return false;
+        }
 
 
         public dispose(forceDisposeEffect?: boolean): void {
         public dispose(forceDisposeEffect?: boolean): void {
             if (this._diffuseTexture) {
             if (this._diffuseTexture) {
@@ -293,7 +293,7 @@ module BABYLON {
         public clone(name: string): SimpleMaterial {
         public clone(name: string): SimpleMaterial {
             return SerializationHelper.Clone<SimpleMaterial>(() => new SimpleMaterial(name, this.getScene()), this);
             return SerializationHelper.Clone<SimpleMaterial>(() => new SimpleMaterial(name, this.getScene()), this);
         }
         }
-        
+
         public serialize(): any {
         public serialize(): any {
             var serializationObject = SerializationHelper.Serialize(this);
             var serializationObject = SerializationHelper.Serialize(this);
             serializationObject.customType = "BABYLON.SimpleMaterial";
             serializationObject.customType = "BABYLON.SimpleMaterial";
@@ -302,12 +302,12 @@ module BABYLON {
 
 
         public getClassName(): string {
         public getClassName(): string {
             return "SimpleMaterial";
             return "SimpleMaterial";
-        }               
-        
+        }
+
         // Statics
         // Statics
         public static Parse(source: any, scene: Scene, rootUrl: string): SimpleMaterial {
         public static Parse(source: any, scene: Scene, rootUrl: string): SimpleMaterial {
             return SerializationHelper.Parse(() => new SimpleMaterial(source.name, scene), source, scene, rootUrl);
             return SerializationHelper.Parse(() => new SimpleMaterial(source.name, scene), source, scene, rootUrl);
         }
         }
     }
     }
-} 
+}
 
 

+ 39 - 39
materialsLibrary/src/terrain/babylon.terrainMaterial.ts

@@ -30,8 +30,8 @@ module BABYLON {
         @serializeAsTexture("mixTexture")
         @serializeAsTexture("mixTexture")
         private _mixTexture: BaseTexture;
         private _mixTexture: BaseTexture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public mixTexture: BaseTexture;        
-        
+        public mixTexture: BaseTexture;
+
         @serializeAsTexture("diffuseTexture1")
         @serializeAsTexture("diffuseTexture1")
         private _diffuseTexture1: Texture;
         private _diffuseTexture1: Texture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
@@ -41,45 +41,45 @@ module BABYLON {
         private _diffuseTexture2: Texture;
         private _diffuseTexture2: Texture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         public diffuseTexture2: Texture;
         public diffuseTexture2: Texture;
-        
+
         @serializeAsTexture("diffuseTexture3")
         @serializeAsTexture("diffuseTexture3")
         private _diffuseTexture3: Texture;
         private _diffuseTexture3: Texture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         public diffuseTexture3: Texture;
         public diffuseTexture3: Texture;
-        
+
         @serializeAsTexture("bumpTexture1")
         @serializeAsTexture("bumpTexture1")
         private _bumpTexture1: Texture;
         private _bumpTexture1: Texture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public bumpTexture1: Texture;        
-        
+        public bumpTexture1: Texture;
+
         @serializeAsTexture("bumpTexture2")
         @serializeAsTexture("bumpTexture2")
         private _bumpTexture2: Texture;
         private _bumpTexture2: Texture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public bumpTexture2: Texture;        
-        
+        public bumpTexture2: Texture;
+
         @serializeAsTexture("bumpTexture3")
         @serializeAsTexture("bumpTexture3")
         private _bumpTexture3: Texture;
         private _bumpTexture3: Texture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public bumpTexture3: Texture;   
-        
+        public bumpTexture3: Texture;
+
         @serializeAsColor3()
         @serializeAsColor3()
         public diffuseColor = new Color3(1, 1, 1);
         public diffuseColor = new Color3(1, 1, 1);
-        
+
         @serializeAsColor3()
         @serializeAsColor3()
         public specularColor = new Color3(0, 0, 0);
         public specularColor = new Color3(0, 0, 0);
-        
+
         @serialize()
         @serialize()
         public specularPower = 64;
         public specularPower = 64;
-        
+
         @serialize("disableLighting")
         @serialize("disableLighting")
         private _disableLighting = false;
         private _disableLighting = false;
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
-        public disableLighting: boolean;   
-        
+        public disableLighting: boolean;
+
         @serialize("maxSimultaneousLights")
         @serialize("maxSimultaneousLights")
         private _maxSimultaneousLights = 4;
         private _maxSimultaneousLights = 4;
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
-        public maxSimultaneousLights: number; 
+        public maxSimultaneousLights: number;
 
 
         private _renderId: number;
         private _renderId: number;
 
 
@@ -100,7 +100,7 @@ module BABYLON {
         }
         }
 
 
         // Methods   
         // Methods   
-        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {   
+        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {
             if (this.isFrozen) {
             if (this.isFrozen) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                     return true;
                     return true;
@@ -138,7 +138,7 @@ module BABYLON {
                     defines.BUMP = true;
                     defines.BUMP = true;
                 }
                 }
             }
             }
-            
+
             // Misc.
             // Misc.
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
 
 
@@ -146,8 +146,8 @@ module BABYLON {
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
 
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
-            
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
+
             // Attribs
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
 
 
@@ -157,13 +157,13 @@ module BABYLON {
                 scene.resetCachedMaterial();
                 scene.resetCachedMaterial();
 
 
                 // Fallbacks
                 // Fallbacks
-                var fallbacks = new EffectFallbacks();             
+                var fallbacks = new EffectFallbacks();
                 if (defines.FOG) {
                 if (defines.FOG) {
                     fallbacks.addFallback(1, "FOG");
                     fallbacks.addFallback(1, "FOG");
                 }
                 }
 
 
                 MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
                 MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
-             
+
                 if (defines.NUM_BONE_INFLUENCERS > 0) {
                 if (defines.NUM_BONE_INFLUENCERS > 0) {
                     fallbacks.addCPUSkinningFallback(0, mesh);
                     fallbacks.addCPUSkinningFallback(0, mesh);
                 }
                 }
@@ -195,7 +195,7 @@ module BABYLON {
                 var join = defines.toString();
                 var join = defines.toString();
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
                     "vFogInfos", "vFogColor", "pointSize",
                     "vFogInfos", "vFogColor", "pointSize",
-                    "vTextureInfos", 
+                    "vTextureInfos",
                     "mBones",
                     "mBones",
                     "vClipPlane", "textureMatrix",
                     "vClipPlane", "textureMatrix",
                     "diffuse1Infos", "diffuse2Infos", "diffuse3Infos"
                     "diffuse1Infos", "diffuse2Infos", "diffuse3Infos"
@@ -207,13 +207,13 @@ module BABYLON {
                 var uniformBuffers = new Array<string>()
                 var uniformBuffers = new Array<string>()
 
 
                 MaterialHelper.PrepareUniformsAndSamplersList(<EffectCreationOptions>{
                 MaterialHelper.PrepareUniformsAndSamplersList(<EffectCreationOptions>{
-                    uniformsNames: uniforms, 
+                    uniformsNames: uniforms,
                     uniformBuffersNames: uniformBuffers,
                     uniformBuffersNames: uniformBuffers,
-                    samplers: samplers, 
-                    defines: defines, 
+                    samplers: samplers,
+                    defines: defines,
                     maxSimultaneousLights: this.maxSimultaneousLights
                     maxSimultaneousLights: this.maxSimultaneousLights
                 });
                 });
-                
+
                 subMesh.setEffect(scene.getEngine().createEffect(shaderName,
                 subMesh.setEffect(scene.getEngine().createEffect(shaderName,
                     <EffectCreationOptions>{
                     <EffectCreationOptions>{
                         attributes: attribs,
                         attributes: attribs,
@@ -264,7 +264,7 @@ module BABYLON {
                     this._activeEffect.setTexture("textureSampler", this._mixTexture);
                     this._activeEffect.setTexture("textureSampler", this._mixTexture);
                     this._activeEffect.setFloat2("vTextureInfos", this._mixTexture.coordinatesIndex, this._mixTexture.level);
                     this._activeEffect.setFloat2("vTextureInfos", this._mixTexture.coordinatesIndex, this._mixTexture.level);
                     this._activeEffect.setMatrix("textureMatrix", this._mixTexture.getTextureMatrix());
                     this._activeEffect.setMatrix("textureMatrix", this._mixTexture.getTextureMatrix());
-                    
+
                     if (StandardMaterial.DiffuseTextureEnabled) {
                     if (StandardMaterial.DiffuseTextureEnabled) {
                         if (this._diffuseTexture1) {
                         if (this._diffuseTexture1) {
                             this._activeEffect.setTexture("diffuse1Sampler", this._diffuseTexture1);
                             this._activeEffect.setTexture("diffuse1Sampler", this._diffuseTexture1);
@@ -279,7 +279,7 @@ module BABYLON {
                             this._activeEffect.setFloat2("diffuse3Infos", this._diffuseTexture3.uScale, this._diffuseTexture3.vScale);
                             this._activeEffect.setFloat2("diffuse3Infos", this._diffuseTexture3.uScale, this._diffuseTexture3.vScale);
                         }
                         }
                     }
                     }
-                    
+
                     if (StandardMaterial.BumpTextureEnabled && scene.getEngine().getCaps().standardDerivatives) {
                     if (StandardMaterial.BumpTextureEnabled && scene.getEngine().getCaps().standardDerivatives) {
                         if (this._bumpTexture1) {
                         if (this._bumpTexture1) {
                             this._activeEffect.setTexture("bump1Sampler", this._bumpTexture1);
                             this._activeEffect.setTexture("bump1Sampler", this._bumpTexture1);
@@ -300,11 +300,11 @@ module BABYLON {
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                 }
                 }
 
 
-                MaterialHelper.BindEyePosition(effect, scene);             
+                MaterialHelper.BindEyePosition(effect, scene);
             }
             }
 
 
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
-            
+
             if (defines.SPECULARTERM) {
             if (defines.SPECULARTERM) {
                 this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
                 this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
             }
             }
@@ -379,7 +379,7 @@ module BABYLON {
 
 
             if (this._diffuseTexture1 === texture) {
             if (this._diffuseTexture1 === texture) {
                 return true;
                 return true;
-            }    
+            }
 
 
             if (this._diffuseTexture2 === texture) {
             if (this._diffuseTexture2 === texture) {
                 return true;
                 return true;
@@ -387,7 +387,7 @@ module BABYLON {
 
 
             if (this._diffuseTexture3 === texture) {
             if (this._diffuseTexture3 === texture) {
                 return true;
                 return true;
-            }        
+            }
 
 
             if (this._bumpTexture1 === texture) {
             if (this._bumpTexture1 === texture) {
                 return true;
                 return true;
@@ -395,14 +395,14 @@ module BABYLON {
 
 
             if (this._bumpTexture2 === texture) {
             if (this._bumpTexture2 === texture) {
                 return true;
                 return true;
-            }        
+            }
 
 
             if (this._bumpTexture3 === texture) {
             if (this._bumpTexture3 === texture) {
                 return true;
                 return true;
-            }      
+            }
 
 
-            return false;    
-        }        
+            return false;
+        }
 
 
         public dispose(forceDisposeEffect?: boolean): void {
         public dispose(forceDisposeEffect?: boolean): void {
             if (this.mixTexture) {
             if (this.mixTexture) {
@@ -411,7 +411,7 @@ module BABYLON {
 
 
             super.dispose(forceDisposeEffect);
             super.dispose(forceDisposeEffect);
         }
         }
-        
+
         public clone(name: string): TerrainMaterial {
         public clone(name: string): TerrainMaterial {
             return SerializationHelper.Clone(() => new TerrainMaterial(name, this.getScene()), this);
             return SerializationHelper.Clone(() => new TerrainMaterial(name, this.getScene()), this);
         }
         }
@@ -431,5 +431,5 @@ module BABYLON {
             return SerializationHelper.Parse(() => new TerrainMaterial(source.name, scene), source, scene, rootUrl);
             return SerializationHelper.Parse(() => new TerrainMaterial(source.name, scene), source, scene, rootUrl);
         }
         }
     }
     }
-} 
+}
 
 

+ 49 - 49
materialsLibrary/src/triPlanar/babylon.triPlanarMaterial.ts

@@ -5,11 +5,11 @@ module BABYLON {
         public DIFFUSEX = false;
         public DIFFUSEX = false;
         public DIFFUSEY = false;
         public DIFFUSEY = false;
         public DIFFUSEZ = false;
         public DIFFUSEZ = false;
-        
+
         public BUMPX = false;
         public BUMPX = false;
         public BUMPY = false;
         public BUMPY = false;
         public BUMPZ = false;
         public BUMPZ = false;
-        
+
         public CLIPPLANE = false;
         public CLIPPLANE = false;
         public ALPHATEST = false;
         public ALPHATEST = false;
         public DEPTHPREPASS = false;
         public DEPTHPREPASS = false;
@@ -32,59 +32,59 @@ module BABYLON {
     export class TriPlanarMaterial extends PushMaterial {
     export class TriPlanarMaterial extends PushMaterial {
         @serializeAsTexture()
         @serializeAsTexture()
         public mixTexture: BaseTexture;
         public mixTexture: BaseTexture;
-        
+
         @serializeAsTexture("diffuseTextureX")
         @serializeAsTexture("diffuseTextureX")
         private _diffuseTextureX: BaseTexture;
         private _diffuseTextureX: BaseTexture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         public diffuseTextureX: BaseTexture;
         public diffuseTextureX: BaseTexture;
-        
+
         @serializeAsTexture("diffuseTexturY")
         @serializeAsTexture("diffuseTexturY")
         private _diffuseTextureY: BaseTexture;
         private _diffuseTextureY: BaseTexture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public diffuseTextureY: BaseTexture;        
-        
+        public diffuseTextureY: BaseTexture;
+
         @serializeAsTexture("diffuseTextureZ")
         @serializeAsTexture("diffuseTextureZ")
         private _diffuseTextureZ: BaseTexture;
         private _diffuseTextureZ: BaseTexture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public diffuseTextureZ: BaseTexture;        
-        
+        public diffuseTextureZ: BaseTexture;
+
         @serializeAsTexture("normalTextureX")
         @serializeAsTexture("normalTextureX")
         private _normalTextureX: BaseTexture;
         private _normalTextureX: BaseTexture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public normalTextureX: BaseTexture;        
-        
+        public normalTextureX: BaseTexture;
+
         @serializeAsTexture("normalTextureY")
         @serializeAsTexture("normalTextureY")
         private _normalTextureY: BaseTexture;
         private _normalTextureY: BaseTexture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public normalTextureY: BaseTexture;        
-        
+        public normalTextureY: BaseTexture;
+
         @serializeAsTexture("normalTextureZ")
         @serializeAsTexture("normalTextureZ")
         private _normalTextureZ: BaseTexture;
         private _normalTextureZ: BaseTexture;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public normalTextureZ: BaseTexture;        
-               
+        public normalTextureZ: BaseTexture;
+
         @serialize()
         @serialize()
         public tileSize: number = 1;
         public tileSize: number = 1;
-        
+
         @serializeAsColor3()
         @serializeAsColor3()
         public diffuseColor = new Color3(1, 1, 1);
         public diffuseColor = new Color3(1, 1, 1);
-        
+
         @serializeAsColor3()
         @serializeAsColor3()
         public specularColor = new Color3(0.2, 0.2, 0.2);
         public specularColor = new Color3(0.2, 0.2, 0.2);
-        
+
         @serialize()
         @serialize()
         public specularPower = 64;
         public specularPower = 64;
-        
+
         @serialize("disableLighting")
         @serialize("disableLighting")
         private _disableLighting = false;
         private _disableLighting = false;
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
-        public disableLighting: boolean;   
-        
+        public disableLighting: boolean;
+
         @serialize("maxSimultaneousLights")
         @serialize("maxSimultaneousLights")
         private _maxSimultaneousLights = 4;
         private _maxSimultaneousLights = 4;
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
-        public maxSimultaneousLights: number; 
-        
+        public maxSimultaneousLights: number;
+
         private _renderId: number;
         private _renderId: number;
 
 
         constructor(name: string, scene: Scene) {
         constructor(name: string, scene: Scene) {
@@ -104,7 +104,7 @@ module BABYLON {
         }
         }
 
 
         // Methods   
         // Methods   
-        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {   
+        public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {
             if (this.isFrozen) {
             if (this.isFrozen) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                 if (this._wasPreviouslyReady && subMesh.effect) {
                     return true;
                     return true;
@@ -127,13 +127,13 @@ module BABYLON {
             var engine = scene.getEngine();
             var engine = scene.getEngine();
 
 
             // Textures
             // Textures
-            if (defines._areTexturesDirty) {                
+            if (defines._areTexturesDirty) {
                 if (scene.texturesEnabled) {
                 if (scene.texturesEnabled) {
                     if (StandardMaterial.DiffuseTextureEnabled) {
                     if (StandardMaterial.DiffuseTextureEnabled) {
                         var textures = [this.diffuseTextureX, this.diffuseTextureY, this.diffuseTextureZ];
                         var textures = [this.diffuseTextureX, this.diffuseTextureY, this.diffuseTextureZ];
                         var textureDefines = ["DIFFUSEX", "DIFFUSEY", "DIFFUSEZ"];
                         var textureDefines = ["DIFFUSEX", "DIFFUSEY", "DIFFUSEZ"];
-                        
-                        for (var i=0; i < textures.length; i++) {
+
+                        for (var i = 0; i < textures.length; i++) {
                             if (textures[i]) {
                             if (textures[i]) {
                                 if (!textures[i].isReady()) {
                                 if (!textures[i].isReady()) {
                                     return false;
                                     return false;
@@ -146,8 +146,8 @@ module BABYLON {
                     if (StandardMaterial.BumpTextureEnabled) {
                     if (StandardMaterial.BumpTextureEnabled) {
                         var textures = [this.normalTextureX, this.normalTextureY, this.normalTextureZ];
                         var textures = [this.normalTextureX, this.normalTextureY, this.normalTextureZ];
                         var textureDefines = ["BUMPX", "BUMPY", "BUMPZ"];
                         var textureDefines = ["BUMPX", "BUMPY", "BUMPZ"];
-                        
-                        for (var i=0; i < textures.length; i++) {
+
+                        for (var i = 0; i < textures.length; i++) {
                             if (textures[i]) {
                             if (textures[i]) {
                                 if (!textures[i].isReady()) {
                                 if (!textures[i].isReady()) {
                                     return false;
                                     return false;
@@ -167,8 +167,8 @@ module BABYLON {
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
 
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
-            
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
+
             // Attribs
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
 
 
@@ -178,13 +178,13 @@ module BABYLON {
                 scene.resetCachedMaterial();
                 scene.resetCachedMaterial();
 
 
                 // Fallbacks
                 // Fallbacks
-                var fallbacks = new EffectFallbacks();             
+                var fallbacks = new EffectFallbacks();
                 if (defines.FOG) {
                 if (defines.FOG) {
                     fallbacks.addFallback(1, "FOG");
                     fallbacks.addFallback(1, "FOG");
                 }
                 }
 
 
                 MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
                 MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
-             
+
                 if (defines.NUM_BONE_INFLUENCERS > 0) {
                 if (defines.NUM_BONE_INFLUENCERS > 0) {
                     fallbacks.addCPUSkinningFallback(0, mesh);
                     fallbacks.addCPUSkinningFallback(0, mesh);
                 }
                 }
@@ -219,13 +219,13 @@ module BABYLON {
                 var uniformBuffers = new Array<string>()
                 var uniformBuffers = new Array<string>()
 
 
                 MaterialHelper.PrepareUniformsAndSamplersList(<EffectCreationOptions>{
                 MaterialHelper.PrepareUniformsAndSamplersList(<EffectCreationOptions>{
-                    uniformsNames: uniforms, 
+                    uniformsNames: uniforms,
                     uniformBuffersNames: uniformBuffers,
                     uniformBuffersNames: uniformBuffers,
-                    samplers: samplers, 
-                    defines: defines, 
+                    samplers: samplers,
+                    defines: defines,
                     maxSimultaneousLights: this.maxSimultaneousLights
                     maxSimultaneousLights: this.maxSimultaneousLights
                 });
                 });
-                
+
                 subMesh.setEffect(scene.getEngine().createEffect(shaderName,
                 subMesh.setEffect(scene.getEngine().createEffect(shaderName,
                     <EffectCreationOptions>{
                     <EffectCreationOptions>{
                         attributes: attribs,
                         attributes: attribs,
@@ -245,7 +245,7 @@ module BABYLON {
 
 
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
             this._wasPreviouslyReady = true;
             this._wasPreviouslyReady = true;
-            
+
             return true;
             return true;
         }
         }
 
 
@@ -269,7 +269,7 @@ module BABYLON {
 
 
             // Bones
             // Bones
             MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
             MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
-            
+
             this._activeEffect.setFloat("tileSize", this.tileSize);
             this._activeEffect.setFloat("tileSize", this.tileSize);
 
 
             if (scene.getCachedMaterial() !== this) {
             if (scene.getCachedMaterial() !== this) {
@@ -300,11 +300,11 @@ module BABYLON {
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                 }
                 }
 
 
-                MaterialHelper.BindEyePosition(effect, scene);               
+                MaterialHelper.BindEyePosition(effect, scene);
             }
             }
 
 
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
-            
+
             if (defines.SPECULARTERM) {
             if (defines.SPECULARTERM) {
                 this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
                 this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
             }
             }
@@ -371,11 +371,11 @@ module BABYLON {
 
 
             if (this._diffuseTextureX === texture) {
             if (this._diffuseTextureX === texture) {
                 return true;
                 return true;
-            }    
+            }
 
 
             if (this._diffuseTextureY === texture) {
             if (this._diffuseTextureY === texture) {
                 return true;
                 return true;
-            }         
+            }
 
 
             if (this._diffuseTextureZ === texture) {
             if (this._diffuseTextureZ === texture) {
                 return true;
                 return true;
@@ -383,17 +383,17 @@ module BABYLON {
 
 
             if (this._normalTextureX === texture) {
             if (this._normalTextureX === texture) {
                 return true;
                 return true;
-            }     
+            }
 
 
             if (this._normalTextureY === texture) {
             if (this._normalTextureY === texture) {
                 return true;
                 return true;
-            }     
+            }
 
 
             if (this._normalTextureZ === texture) {
             if (this._normalTextureZ === texture) {
                 return true;
                 return true;
-            }                                 
-            return false;    
-        }        
+            }
+            return false;
+        }
 
 
         public dispose(forceDisposeEffect?: boolean): void {
         public dispose(forceDisposeEffect?: boolean): void {
             if (this.mixTexture) {
             if (this.mixTexture) {
@@ -402,7 +402,7 @@ module BABYLON {
 
 
             super.dispose(forceDisposeEffect);
             super.dispose(forceDisposeEffect);
         }
         }
-        
+
         public clone(name: string): TriPlanarMaterial {
         public clone(name: string): TriPlanarMaterial {
             return SerializationHelper.Clone(() => new TriPlanarMaterial(name, this.getScene()), this);
             return SerializationHelper.Clone(() => new TriPlanarMaterial(name, this.getScene()), this);
         }
         }
@@ -422,5 +422,5 @@ module BABYLON {
             return SerializationHelper.Parse(() => new TriPlanarMaterial(source.name, scene), source, scene, rootUrl);
             return SerializationHelper.Parse(() => new TriPlanarMaterial(source.name, scene), source, scene, rootUrl);
         }
         }
     }
     }
-} 
+}
 
 

+ 6 - 6
materialsLibrary/src/water/babylon.waterMaterial.ts

@@ -164,8 +164,8 @@ module BABYLON {
             // Create render targets
             // Create render targets
             this.getRenderTargetTextures = (): SmartArray<RenderTargetTexture> => {
             this.getRenderTargetTextures = (): SmartArray<RenderTargetTexture> => {
                 this._renderTargets.reset();
                 this._renderTargets.reset();
-                this._renderTargets.push(<RenderTargetTexture> this._reflectionRTT);
-                this._renderTargets.push(<RenderTargetTexture> this._refractionRTT);
+                this._renderTargets.push(<RenderTargetTexture>this._reflectionRTT);
+                this._renderTargets.push(<RenderTargetTexture>this._refractionRTT);
 
 
                 return this._renderTargets;
                 return this._renderTargets;
             }
             }
@@ -275,7 +275,7 @@ module BABYLON {
                 }
                 }
             }
             }
 
 
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh));
 
 
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
 
 
@@ -614,12 +614,12 @@ module BABYLON {
                 this.bumpTexture.dispose();
                 this.bumpTexture.dispose();
             }
             }
 
 
-            var index = this.getScene().customRenderTargets.indexOf(<RenderTargetTexture> this._refractionRTT);
+            var index = this.getScene().customRenderTargets.indexOf(<RenderTargetTexture>this._refractionRTT);
             if (index != -1) {
             if (index != -1) {
                 this.getScene().customRenderTargets.splice(index, 1);
                 this.getScene().customRenderTargets.splice(index, 1);
             }
             }
             index = -1;
             index = -1;
-            index = this.getScene().customRenderTargets.indexOf(<RenderTargetTexture> this._reflectionRTT);
+            index = this.getScene().customRenderTargets.indexOf(<RenderTargetTexture>this._reflectionRTT);
             if (index != -1) {
             if (index != -1) {
                 this.getScene().customRenderTargets.splice(index, 1);
                 this.getScene().customRenderTargets.splice(index, 1);
             }
             }
@@ -641,7 +641,7 @@ module BABYLON {
         public serialize(): any {
         public serialize(): any {
             var serializationObject = SerializationHelper.Serialize(this);
             var serializationObject = SerializationHelper.Serialize(this);
             serializationObject.customType = "BABYLON.WaterMaterial";
             serializationObject.customType = "BABYLON.WaterMaterial";
-            
+
             serializationObject.renderList = [];
             serializationObject.renderList = [];
             if (this._refractionRTT && this._refractionRTT.renderList) {
             if (this._refractionRTT && this._refractionRTT.renderList) {
                 for (var i = 0; i < this._refractionRTT.renderList.length; i++) {
                 for (var i = 0; i < this._refractionRTT.renderList.length; i++) {

+ 0 - 9
src/Engine/babylon.engine.ts

@@ -680,7 +680,6 @@
         private _hardwareScalingLevel: number;
         private _hardwareScalingLevel: number;
         protected _caps: EngineCapabilities;
         protected _caps: EngineCapabilities;
         private _pointerLockRequested: boolean;
         private _pointerLockRequested: boolean;
-        private _alphaTest: boolean;
         private _isStencilEnable: boolean;
         private _isStencilEnable: boolean;
         private _colorWrite = true;
         private _colorWrite = true;
 
 
@@ -3028,14 +3027,6 @@
             return this._alphaMode;
             return this._alphaMode;
         }
         }
 
 
-        public setAlphaTesting(enable: boolean): void {
-            this._alphaTest = enable;
-        }
-
-        public getAlphaTesting(): boolean {
-            return !!this._alphaTest;
-        }
-
         // Textures
         // Textures
         public wipeCaches(bruteForce?: boolean): void {
         public wipeCaches(bruteForce?: boolean): void {
             if (this.preventCacheWipeBetweenFrames && !bruteForce) {
             if (this.preventCacheWipeBetweenFrames && !bruteForce) {

+ 1 - 1
src/Materials/Background/babylon.backgroundMaterial.ts

@@ -699,7 +699,7 @@
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
 
 
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances, false);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances, this._shouldTurnAlphaTestOn(mesh));
 
 
             // Attribs
             // Attribs
             if (MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true, false)) {
             if (MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true, false)) {

+ 1 - 1
src/Materials/PBR/babylon.pbrBaseMaterial.ts

@@ -904,7 +904,7 @@
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
 
 
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._forceAlphaTest);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false, this._shouldTurnAlphaTestOn(mesh) || this._forceAlphaTest);
 
 
             // Attribs
             // Attribs
             if (MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true, this._transparencyMode !== PBRMaterial.PBRMATERIAL_OPAQUE) && mesh) {
             if (MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true, this._transparencyMode !== PBRMaterial.PBRMATERIAL_OPAQUE) && mesh) {

+ 5 - 8
src/Materials/babylon.material.ts

@@ -539,6 +539,10 @@
             }
             }
         }
         }
 
 
+        protected _shouldTurnAlphaTestOn(mesh: AbstractMesh): boolean {
+            return (!this.needAlphaBlendingForMesh(mesh) && this.needAlphaTesting());
+        }
+
         protected _afterBind(mesh?: Mesh): void {
         protected _afterBind(mesh?: Mesh): void {
             this._scene._cachedMaterial = this;
             this._scene._cachedMaterial = this;
             if (mesh) {
             if (mesh) {
@@ -597,16 +601,14 @@
         /**
         /**
          * Force shader compilation including textures ready check
          * Force shader compilation including textures ready check
          */
          */
-        public forceCompilation(mesh: AbstractMesh, onCompiled?: (material: Material) => void, options?: Partial<{ alphaTest: Nullable<boolean>, clipPlane: boolean }>): void {
+        public forceCompilation(mesh: AbstractMesh, onCompiled?: (material: Material) => void, options?: Partial<{ clipPlane: boolean }>): void {
             let localOptions = {
             let localOptions = {
-                alphaTest: null,
                 clipPlane: false,
                 clipPlane: false,
                 ...options
                 ...options
             };
             };
 
 
             var subMesh = new BaseSubMesh();
             var subMesh = new BaseSubMesh();
             var scene = this.getScene();
             var scene = this.getScene();
-            var engine = scene.getEngine();
 
 
             var checkReady = () => {
             var checkReady = () => {
                 if (!this._scene || !this._scene.getEngine()) {
                 if (!this._scene || !this._scene.getEngine()) {
@@ -617,11 +619,8 @@
                     subMesh._materialDefines._renderId = -1;
                     subMesh._materialDefines._renderId = -1;
                 }
                 }
 
 
-                var alphaTestState = engine.getAlphaTesting();
                 var clipPlaneState = scene.clipPlane;
                 var clipPlaneState = scene.clipPlane;
 
 
-                engine.setAlphaTesting(localOptions.alphaTest || (!this.needAlphaBlendingForMesh(mesh) && this.needAlphaTesting()));
-
                 if (localOptions.clipPlane) {
                 if (localOptions.clipPlane) {
                     scene.clipPlane = new Plane(0, 0, 0, 1);
                     scene.clipPlane = new Plane(0, 0, 0, 1);
                 }
                 }
@@ -646,8 +645,6 @@
                     }
                     }
                 }
                 }
 
 
-                engine.setAlphaTesting(alphaTestState);
-
                 if (options && options.clipPlane) {
                 if (options && options.clipPlane) {
                     scene.clipPlane = clipPlaneState;
                     scene.clipPlane = clipPlaneState;
                 }
                 }

+ 10 - 2
src/Materials/babylon.materialHelper.ts

@@ -41,7 +41,15 @@
             }
             }
         }
         }
 
 
-        public static PrepareDefinesForFrameBoundValues(scene: Scene, engine: Engine, defines: any, useInstances: boolean, forceAlphaTest = false): void {
+        /**
+         * Helper used to prepare the list of defines for shader compilation
+         * @param scene defines the current scene
+         * @param engine defines the current engine
+         * @param defines specifies the list of active defines
+         * @param useInstances defines if instances have to be turned on
+         * @param alphaTest defines if alpha testing has to be turned on
+         */
+        public static PrepareDefinesForFrameBoundValues(scene: Scene, engine: Engine, defines: any, useInstances: boolean, alphaTest: boolean): void {
             var changed = false;
             var changed = false;
 
 
             if (defines["CLIPPLANE"] !== (scene.clipPlane !== undefined && scene.clipPlane !== null)) {
             if (defines["CLIPPLANE"] !== (scene.clipPlane !== undefined && scene.clipPlane !== null)) {
@@ -49,7 +57,7 @@
                 changed = true;
                 changed = true;
             }
             }
 
 
-            if (defines["ALPHATEST"] !== (engine.getAlphaTesting() || forceAlphaTest)) {
+            if (defines["ALPHATEST"] !== alphaTest) {
                 defines["ALPHATEST"] = !defines["ALPHATEST"];
                 defines["ALPHATEST"] = !defines["ALPHATEST"];
                 changed = true;
                 changed = true;
             }
             }

+ 1 - 1
src/Materials/babylon.shaderMaterial.ts

@@ -247,7 +247,7 @@
             }
             }
 
 
             // Alpha test
             // Alpha test
-            if (engine.getAlphaTesting()) {
+            if (mesh && this._shouldTurnAlphaTestOn(mesh)) {
                 defines.push("#define ALPHATEST");
                 defines.push("#define ALPHATEST");
             }
             }
 
 

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

@@ -745,7 +745,7 @@ module BABYLON {
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
 
 
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances, this._shouldTurnAlphaTestOn(mesh));
 
 
             // Get correct effect      
             // Get correct effect      
             if (defines.isDirty) {
             if (defines.isDirty) {

+ 0 - 8
src/Mesh/babylon.mesh.ts

@@ -623,28 +623,20 @@
 
 
             let mat = this.material || scene.defaultMaterial;
             let mat = this.material || scene.defaultMaterial;
             if (mat) {
             if (mat) {
-                let currentAlphaTestingState = engine.getAlphaTesting();
-
                 if (mat.storeEffectOnSubMeshes) {
                 if (mat.storeEffectOnSubMeshes) {
                     for (var subMesh of this.subMeshes) {
                     for (var subMesh of this.subMeshes) {
                         let effectiveMaterial = subMesh.getMaterial();
                         let effectiveMaterial = subMesh.getMaterial();
                         if (effectiveMaterial) {
                         if (effectiveMaterial) {
-                            engine.setAlphaTesting(effectiveMaterial.needAlphaTesting() && !effectiveMaterial.needAlphaBlendingForMesh(this));
                             if (!effectiveMaterial.isReadyForSubMesh(this, subMesh, hardwareInstancedRendering)) {
                             if (!effectiveMaterial.isReadyForSubMesh(this, subMesh, hardwareInstancedRendering)) {
-                                engine.setAlphaTesting(currentAlphaTestingState);
                                 return false;
                                 return false;
                             }
                             }
                         }
                         }
                     }
                     }
                 } else {
                 } else {
-                    engine.setAlphaTesting(mat.needAlphaTesting() && !mat.needAlphaBlendingForMesh(this));
                     if (!mat.isReady(this, hardwareInstancedRendering)) {
                     if (!mat.isReady(this, hardwareInstancedRendering)) {
-                        engine.setAlphaTesting(currentAlphaTestingState);
                         return false;
                         return false;
                     }
                     }
                 }
                 }
-
-                engine.setAlphaTesting(currentAlphaTestingState);
             }
             }
 
 
             // Shadows
             // Shadows

+ 0 - 2
src/PostProcess/babylon.volumetricLightScatteringPostProcess.ts

@@ -358,11 +358,9 @@
                     renderSubMesh(opaqueSubMeshes.data[index]);
                     renderSubMesh(opaqueSubMeshes.data[index]);
                 }
                 }
 
 
-                engine.setAlphaTesting(true);
                 for (index = 0; index < alphaTestSubMeshes.length; index++) {
                 for (index = 0; index < alphaTestSubMeshes.length; index++) {
                     renderSubMesh(alphaTestSubMeshes.data[index]);
                     renderSubMesh(alphaTestSubMeshes.data[index]);
                 }
                 }
-                engine.setAlphaTesting(false);
 
 
                 if (transparentSubMeshes.length) {
                 if (transparentSubMeshes.length) {
                     // Sort sub meshes
                     // Sort sub meshes

+ 14 - 20
src/Rendering/babylon.renderingGroup.ts

@@ -6,12 +6,12 @@
         private _alphaTestSubMeshes = new SmartArray<SubMesh>(256);
         private _alphaTestSubMeshes = new SmartArray<SubMesh>(256);
         private _depthOnlySubMeshes = new SmartArray<SubMesh>(256);
         private _depthOnlySubMeshes = new SmartArray<SubMesh>(256);
         private _particleSystems = new SmartArray<IParticleSystem>(256);
         private _particleSystems = new SmartArray<IParticleSystem>(256);
-        private _spriteManagers = new SmartArray<SpriteManager>(256);        
+        private _spriteManagers = new SmartArray<SpriteManager>(256);
 
 
         private _opaqueSortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number>;
         private _opaqueSortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number>;
         private _alphaTestSortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number>;
         private _alphaTestSortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number>;
         private _transparentSortCompareFn: (a: SubMesh, b: SubMesh) => number;
         private _transparentSortCompareFn: (a: SubMesh, b: SubMesh) => number;
-        
+
         private _renderOpaque: (subMeshes: SmartArray<SubMesh>) => void;
         private _renderOpaque: (subMeshes: SmartArray<SubMesh>) => void;
         private _renderAlphaTest: (subMeshes: SmartArray<SubMesh>) => void;
         private _renderAlphaTest: (subMeshes: SmartArray<SubMesh>) => void;
         private _renderTransparent: (subMeshes: SmartArray<SubMesh>) => void;
         private _renderTransparent: (subMeshes: SmartArray<SubMesh>) => void;
@@ -77,7 +77,7 @@
 
 
             this.opaqueSortCompareFn = opaqueSortCompareFn;
             this.opaqueSortCompareFn = opaqueSortCompareFn;
             this.alphaTestSortCompareFn = alphaTestSortCompareFn;
             this.alphaTestSortCompareFn = alphaTestSortCompareFn;
-            this.transparentSortCompareFn = transparentSortCompareFn;            
+            this.transparentSortCompareFn = transparentSortCompareFn;
         }
         }
 
 
         /**
         /**
@@ -95,13 +95,11 @@
 
 
             // Depth only
             // Depth only
             if (this._depthOnlySubMeshes.length !== 0) {
             if (this._depthOnlySubMeshes.length !== 0) {
-                engine.setAlphaTesting(true);
                 engine.setColorWrite(false);
                 engine.setColorWrite(false);
                 this._renderAlphaTest(this._depthOnlySubMeshes);
                 this._renderAlphaTest(this._depthOnlySubMeshes);
-                engine.setAlphaTesting(false);
                 engine.setColorWrite(true);
                 engine.setColorWrite(true);
-            }            
-            
+            }
+
             // Opaque
             // Opaque
             if (this._opaqueSubMeshes.length !== 0) {
             if (this._opaqueSubMeshes.length !== 0) {
                 this._renderOpaque(this._opaqueSubMeshes);
                 this._renderOpaque(this._opaqueSubMeshes);
@@ -109,9 +107,7 @@
 
 
             // Alpha test
             // Alpha test
             if (this._alphaTestSubMeshes.length !== 0) {
             if (this._alphaTestSubMeshes.length !== 0) {
-                engine.setAlphaTesting(true);
                 this._renderAlphaTest(this._alphaTestSubMeshes);
                 this._renderAlphaTest(this._alphaTestSubMeshes);
-                engine.setAlphaTesting(false);
             }
             }
 
 
             var stencilState = engine.getStencilBuffer();
             var stencilState = engine.getStencilBuffer();
@@ -121,7 +117,7 @@
             if (renderSprites) {
             if (renderSprites) {
                 this._renderSprites();
                 this._renderSprites();
             }
             }
-            
+
             // Particles
             // Particles
             if (renderParticles) {
             if (renderParticles) {
                 this._renderParticles(activeMeshes);
                 this._renderParticles(activeMeshes);
@@ -205,10 +201,8 @@
                     if (material && material.needDepthPrePass) {
                     if (material && material.needDepthPrePass) {
                         let engine = material.getScene().getEngine();
                         let engine = material.getScene().getEngine();
                         engine.setColorWrite(false);
                         engine.setColorWrite(false);
-                        engine.setAlphaTesting(true);
                         engine.setAlphaMode(Engine.ALPHA_DISABLE);
                         engine.setAlphaMode(Engine.ALPHA_DISABLE);
                         subMesh.render(false);
                         subMesh.render(false);
-                        engine.setAlphaTesting(false);
                         engine.setColorWrite(true);
                         engine.setColorWrite(true);
                     }
                     }
                 }
                 }
@@ -236,7 +230,7 @@
          * @param b The second submesh
          * @param b The second submesh
          * @returns The result of the comparison
          * @returns The result of the comparison
          */
          */
-        public static defaultTransparentSortCompare(a: SubMesh, b:SubMesh) : number {
+        public static defaultTransparentSortCompare(a: SubMesh, b: SubMesh): number {
             // Alpha index first
             // Alpha index first
             if (a._alphaIndex > b._alphaIndex) {
             if (a._alphaIndex > b._alphaIndex) {
                 return 1;
                 return 1;
@@ -257,7 +251,7 @@
          * @param b The second submesh
          * @param b The second submesh
          * @returns The result of the comparison
          * @returns The result of the comparison
          */
          */
-        public static backToFrontSortCompare(a: SubMesh, b:SubMesh) : number {
+        public static backToFrontSortCompare(a: SubMesh, b: SubMesh): number {
             // Then distance to camera
             // Then distance to camera
             if (a._distanceToCamera < b._distanceToCamera) {
             if (a._distanceToCamera < b._distanceToCamera) {
                 return 1;
                 return 1;
@@ -277,7 +271,7 @@
          * @param b The second submesh
          * @param b The second submesh
          * @returns The result of the comparison
          * @returns The result of the comparison
          */
          */
-        public static frontToBackSortCompare(a: SubMesh, b:SubMesh) : number {
+        public static frontToBackSortCompare(a: SubMesh, b: SubMesh): number {
             // Then distance to camera
             // Then distance to camera
             if (a._distanceToCamera < b._distanceToCamera) {
             if (a._distanceToCamera < b._distanceToCamera) {
                 return -1;
                 return -1;
@@ -298,7 +292,7 @@
             this._alphaTestSubMeshes.reset();
             this._alphaTestSubMeshes.reset();
             this._depthOnlySubMeshes.reset();
             this._depthOnlySubMeshes.reset();
             this._particleSystems.reset();
             this._particleSystems.reset();
-            this._spriteManagers.reset();            
+            this._spriteManagers.reset();
             this._edgesRenderers.reset();
             this._edgesRenderers.reset();
         }
         }
 
 
@@ -308,7 +302,7 @@
             this._alphaTestSubMeshes.dispose();
             this._alphaTestSubMeshes.dispose();
             this._depthOnlySubMeshes.dispose();
             this._depthOnlySubMeshes.dispose();
             this._particleSystems.dispose();
             this._particleSystems.dispose();
-            this._spriteManagers.dispose();                      
+            this._spriteManagers.dispose();
             this._edgesRenderers.dispose();
             this._edgesRenderers.dispose();
         }
         }
 
 
@@ -337,13 +331,13 @@
                 if (material.needDepthPrePass) {
                 if (material.needDepthPrePass) {
                     this._depthOnlySubMeshes.push(subMesh);
                     this._depthOnlySubMeshes.push(subMesh);
                 }
                 }
-                
+
                 this._alphaTestSubMeshes.push(subMesh);
                 this._alphaTestSubMeshes.push(subMesh);
             } else {
             } else {
                 if (material.needDepthPrePass) {
                 if (material.needDepthPrePass) {
                     this._depthOnlySubMeshes.push(subMesh);
                     this._depthOnlySubMeshes.push(subMesh);
                 }
                 }
-                
+
                 this._opaqueSubMeshes.push(subMesh); // Opaque
                 this._opaqueSubMeshes.push(subMesh); // Opaque
             }
             }
 
 
@@ -381,7 +375,7 @@
                 }
                 }
             }
             }
             this._scene.onAfterParticlesRenderingObservable.notifyObservers(this._scene);
             this._scene.onAfterParticlesRenderingObservable.notifyObservers(this._scene);
-            
+
         }
         }
 
 
         private _renderSprites(): void {
         private _renderSprites(): void {