فهرست منبع

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

# Conflicts:
#	dist/preview release/materialsLibrary/babylon.furMaterial.min.js
Julien Moreau-Mathis 8 سال پیش
والد
کامیت
7f2222ce54
58فایلهای تغییر یافته به همراه2473 افزوده شده و 2329 حذف شده
  1. 4 0
      Exporters/3ds Max/BabylonExport.Entities/BabylonPBRMaterial.cs
  2. 17 0
      Exporters/Maya/Tools/babylonReskinTool.mel
  3. 21 0
      Playground/debug.html
  4. 64 0
      Playground/index.css
  5. 21 0
      Playground/index.html
  6. 67 8
      Playground/index.js
  7. 1 1
      Playground/package.json
  8. 12 12
      dist/preview release/babylon.core.js
  9. 801 794
      dist/preview release/babylon.d.ts
  10. 23 23
      dist/preview release/babylon.js
  11. 110 80
      dist/preview release/babylon.max.js
  12. 801 794
      dist/preview release/babylon.module.d.ts
  13. 29 29
      dist/preview release/babylon.noworker.js
  14. 6 7
      dist/preview release/materialsLibrary/babylon.fireMaterial.d.ts
  15. 100 124
      dist/preview release/materialsLibrary/babylon.fireMaterial.js
  16. 1 1
      dist/preview release/materialsLibrary/babylon.fireMaterial.min.js
  17. 1 1
      dist/preview release/materialsLibrary/babylon.furMaterial.js
  18. 7 7
      dist/preview release/materialsLibrary/babylon.gradientMaterial.js
  19. 1 1
      dist/preview release/materialsLibrary/babylon.gradientMaterial.min.js
  20. 2 2
      dist/preview release/materialsLibrary/babylon.gridMaterial.js
  21. 1 1
      dist/preview release/materialsLibrary/babylon.gridMaterial.min.js
  22. 7 7
      dist/preview release/materialsLibrary/babylon.lavaMaterial.js
  23. 1 1
      dist/preview release/materialsLibrary/babylon.lavaMaterial.min.js
  24. 7 7
      dist/preview release/materialsLibrary/babylon.normalMaterial.js
  25. 1 1
      dist/preview release/materialsLibrary/babylon.normalMaterial.min.js
  26. 2 2
      dist/preview release/materialsLibrary/babylon.shadowOnlyMaterial.js
  27. 1 1
      dist/preview release/materialsLibrary/babylon.shadowOnlyMaterial.min.js
  28. 6 7
      dist/preview release/materialsLibrary/babylon.simpleMaterial.d.ts
  29. 89 118
      dist/preview release/materialsLibrary/babylon.simpleMaterial.js
  30. 1 1
      dist/preview release/materialsLibrary/babylon.simpleMaterial.min.js
  31. 2 2
      dist/preview release/materialsLibrary/babylon.skyMaterial.js
  32. 1 1
      dist/preview release/materialsLibrary/babylon.skyMaterial.min.js
  33. 2 2
      dist/preview release/materialsLibrary/babylon.terrainMaterial.js
  34. 1 1
      dist/preview release/materialsLibrary/babylon.terrainMaterial.min.js
  35. 2 2
      dist/preview release/materialsLibrary/babylon.triPlanarMaterial.js
  36. 1 1
      dist/preview release/materialsLibrary/babylon.triPlanarMaterial.min.js
  37. 2 2
      dist/preview release/materialsLibrary/babylon.waterMaterial.js
  38. 1 1
      dist/preview release/materialsLibrary/babylon.waterMaterial.min.js
  39. 2 0
      materialsLibrary/index.html
  40. 4 10
      materialsLibrary/src/fire/babylon.fireMaterial.ts
  41. 1 1
      materialsLibrary/src/fur/babylon.furMaterial.ts
  42. 6 6
      materialsLibrary/src/gradient/babylon.gradientMaterial.ts
  43. 1 1
      materialsLibrary/src/grid/babylon.gridmaterial.ts
  44. 6 6
      materialsLibrary/src/lava/babylon.lavaMaterial.ts
  45. 6 6
      materialsLibrary/src/normal/babylon.normalMaterial.ts
  46. 1 1
      materialsLibrary/src/shadowOnly/babylon.shadowOnlyMaterial.ts
  47. 5 15
      materialsLibrary/src/simple/babylon.simpleMaterial.ts
  48. 1 1
      materialsLibrary/src/sky/babylon.skyMaterial.ts
  49. 1 1
      materialsLibrary/src/terrain/babylon.terrainMaterial.ts
  50. 1 1
      materialsLibrary/src/triPlanar/babylon.triPlanarMaterial.ts
  51. 124 167
      materialsLibrary/src/water/babylon.waterMaterial.ts
  52. 39 34
      src/Materials/babylon.material.ts
  53. 37 2
      src/Materials/babylon.materialHelper.ts
  54. 1 1
      src/Materials/babylon.pbrMaterial.ts
  55. 5 5
      src/Materials/babylon.pushMaterial.ts
  56. 12 26
      src/Materials/babylon.standardMaterial.ts
  57. 2 2
      src/Mesh/babylon.abstractMesh.ts
  58. 1 1
      src/babylon.engine.ts

+ 4 - 0
Exporters/3ds Max/BabylonExport.Entities/BabylonPBRMaterial.cs

@@ -169,6 +169,9 @@ namespace BabylonExport.Entities
         [DataMember]
         public bool disableLighting { get; set; }
 
+        [DataMember]
+        public bool twoSidedLighting { get; set; }
+
         public BabylonPBRMaterial() : base()
         {
             customType = "BABYLON.PBRMaterial";
@@ -180,6 +183,7 @@ namespace BabylonExport.Entities
             cameraExposure = 1.0f;
             cameraContrast = 1.0f;
             indexOfRefraction = 0.66f;
+            twoSidedLighting = false;
             useRadianceOverAlpha = true;
             useSpecularOverAlpha = true;
             usePhysicalLightFalloff = true;

+ 17 - 0
Exporters/Maya/Tools/babylonReskinTool.mel

@@ -3,9 +3,25 @@ global proc reskinSelectedMeshes() {
     $selected = size($selection);
     if ($selected > 0) {
         $skinName = `textFieldGrp -q -text myReskinName`;
+        $copyName = `textFieldGrp -q -text myUvsetName`;
         $regenerate = `radioButtonGrp -q -select myReskinGenerate`;
         $influencers = `intSliderGrp -q -value myReskinInfluencers`;
         if ($skinName != "") {
+            if ($copyName != "") {
+                for ($i = 0; $i < $selected; $i++) {
+                    string $selectedObject = $selection[$i];
+                    select $selectedObject;
+                    string $uvSets[] = `polyUVSet -q -allUVSets`;
+                    int $uvSize = `size($uvSets)`;
+                    if ($uvSize > 0) {
+                        string $defaultSet = $uvSets[0];
+                        if ($defaultSet != $copyName) {
+                            polyUVSet -copy -uvSet $defaultSet -nuv $copyName;
+                        }
+                    }
+                }
+                select $selection;
+            }
             $textField_exists = `objExists $skinName`;
             if ($textField_exists == 0) {
                 waitCursor -state 1;
@@ -46,6 +62,7 @@ global proc babylonReskinTool() {
     columnLayout -adjustableColumn true;
     textFieldGrp -label "Skin Name" -text "" myReskinName;
     intSliderGrp -label "Max Influencers" -field true -minValue 1 -maxValue 4 -fieldMinValue 1 -fieldMaxValue 4 -value 4 myReskinInfluencers;
+    textFieldGrp -label "Copy Set Name" -text "" myUvsetName;
     radioButtonGrp -label "UV Map Generation" -numberOfRadioButtons 3 -labelArray3 "No Merge" "Same Name" "Set Links" -select 2 myReskinGenerate;
     button -label "Reskin Selected Meshes" -command "reskinSelectedMeshes()" myReskinButton; 
     showWindow $window;

+ 21 - 0
Playground/debug.html

@@ -95,6 +95,9 @@
                 </a>
                 <ul class="dropdown-menu" id="scriptsList"></ul>
             </div>
+            <div class="save-message" id="saveMessage">
+                Be the first to fill this playground metadata!
+            </div>
         </div>
     </div>
 
@@ -125,6 +128,24 @@
         </div>
     </div>
 
+    <div id="saveLayer" class="save-layer">
+        <div class="save-form">
+            <label for="saveFormTitle">TITLE</label>
+            <div class="separator"></div>
+            <input type="text" maxlength="120" id="saveFormTitle" class="save-form-title">
+            <label for="saveFormDescription">DESCRIPTION</label>
+            <div class="separator"></div>
+            <textarea id="saveFormDescription" rows="4" cols="10"></textarea>
+            <label for="saveFormTags">TAGS (separated by comma)</label>
+            <div class="separator"></div>
+            <textarea id="saveFormTags" rows="4" cols="10"></textarea>
+            <div class="save-form-buttons">
+                <button class="btn save-form-button" id="saveFormButtonOk">OK</button>
+                <button class="btn save-form-button" id="saveFormButtonCancel">Cancel</button>
+            </div>
+        </div>
+    </div>
+
     <script src="https://code.jquery.com/jquery.js"></script>
     <script src="bootstrap/js/bootstrap.js"></script>
     <script src="index.js"></script>

+ 64 - 0
Playground/index.css

@@ -122,3 +122,67 @@ ul#scriptsList {
 .monaco-editor .invisible {
     visibility: visible;
 }
+
+
+/* Save form & co */
+
+.save-message {
+    display: none;
+    float: left;
+    width: 100%;
+    background-color: rgba(0,0,0,.5);
+    text-align: center;
+    color: white;
+    font-size: 1.1em;
+    line-height: 2em;
+}
+
+.save-layer {
+    display: none;
+    position: absolute;
+    top: 0;
+    left: 0;
+
+    width: 100%;
+    height: 100%;
+
+    background-color: rgba(120,120,120,.5);
+    text-align: center;
+}
+.save-layer .save-form {
+    position: absolute;
+    top: 150px;
+    left: calc(50% - 205px);
+
+    width: 410px;
+    height: 390px;
+    padding-top: 15px;
+    -webkit-border-radius: 6px;
+    -moz-border-radius: 6px;
+    border-radius: 6px;
+
+    background-color: rgba(27,27,27,0.75);/*#1b1b1b;*/
+    background-image: -moz-linear-gradient(top,rgba(34,34,34,.75),rgba(17,17,17,.75));
+    background-image: -webkit-gradient(linear,0 0,0 100%,from(rgba(34,34,34,.75)),to(rgba(17,17,17,.75)));
+    background-image: -webkit-linear-gradient(top,rgba(34,34,34,.75),rgba(17,17,17,.75));
+    background-image: -o-linear-gradient(top,rgba(34,34,34,.75),rgba(17,17,17,.75));
+    background-image: linear-gradient(to bottom,rgba(34,34,34,.75),rgba(17,17,17,.75));
+    background-repeat: repeat-x;
+    border-color: #252525;
+    color: white;
+    font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
+    font-size: 14px;
+}
+.save-layer .save-form .separator {
+    width: 350px;
+    border-bottom: 1px solid #999;
+    margin: auto;
+    margin-top: -6px;
+    margin-bottom: 10px;
+}
+.save-layer .save-form .save-form-buttons {
+    margin-top: 10px;
+}
+.save-layer .save-form input, .save-layer .save-form textarea {
+    width: 350px;
+}

+ 21 - 0
Playground/index.html

@@ -107,6 +107,9 @@
                 <ul class="dropdown-menu" id="scriptsList"></ul>
             </div>
         </div>
+        <div class="save-message" id="saveMessage">
+            Be the first to fill this playground metadata!
+        </div>
     </div>
 
     <x-splitbox>
@@ -136,6 +139,24 @@
         </div>
     </div>
 
+    <div id="saveLayer" class="save-layer">
+        <div class="save-form">
+            <label for="saveFormTitle">TITLE</label>
+            <div class="separator"></div>
+            <input type="text" maxlength="120" id="saveFormTitle" class="save-form-title">
+            <label for="saveFormDescription">DESCRIPTION</label>
+            <div class="separator"></div>
+            <textarea id="saveFormDescription" rows="4" cols="10"></textarea>
+            <label for="saveFormTags">TAGS (separated by comma)</label>
+            <div class="separator"></div>
+            <textarea id="saveFormTags" rows="4" cols="10"></textarea>
+            <div class="save-form-buttons">
+                <button class="btn save-form-button" id="saveFormButtonOk">OK</button>
+                <button class="btn save-form-button" id="saveFormButtonCancel">Cancel</button>
+            </div>
+        </div>
+    </div>
+
     <script src="https://code.jquery.com/jquery.js"></script>
     <script src="bootstrap/js/bootstrap.min.js"></script>
     <script src="index.js"></script>

+ 67 - 8
Playground/index.js

@@ -16,8 +16,11 @@
             document.getElementById('safemodeToggle').checked = true;
         });
 
-        var snippetUrl = "https://babylonjs-api.azurewebsites.net/api/snippet";
+        var snippetUrl = "https://babylonjs-api2.azurewebsites.net/snippets";
         var currentSnippetToken;
+        var currentSnippetTitle = null;
+        var currentSnippetDescription = null;
+        var currentSnippetTags = null;
         var engine;
         var fpsLabel = document.getElementById("fpsLabel");
         var scripts;
@@ -501,6 +504,14 @@
 
         // Snippet
         var save = function () {
+
+            // Retrieve title if necessary
+            if(document.getElementById("saveLayer")) {
+                currentSnippetTitle = document.getElementById("saveFormTitle").value;
+                currentSnippetDescription = document.getElementById("saveFormDescription").value;
+                currentSnippetTags = document.getElementById("saveFormTags").value;
+            }
+
             var xmlHttp = new XMLHttpRequest();
             xmlHttp.onreadystatechange = function () {
                 if (xmlHttp.readyState === 4) {
@@ -509,10 +520,12 @@
                         var snippet = JSON.parse(xmlHttp.responseText);
                         var newUrl = baseUrl + "#" + snippet.id;
                         currentSnippetToken = snippet.id;
-                        if (snippet.version !== "0") {
+                        if (snippet.version && snippet.version !== "0") {
                             newUrl += "#" + snippet.version;
                         }
                         location.href = newUrl;
+                        // Hide the complete title & co message
+                        document.getElementById("saveMessage").style.display = "none";
                         compileAndRun();
                     } else {
                         showError("Unable to save your code. It may be too long.", null);
@@ -523,14 +536,39 @@
             xmlHttp.open("POST", snippetUrl + (currentSnippetToken ? "/" + currentSnippetToken : ""), true);
             xmlHttp.setRequestHeader("Content-Type", "application/json");
 
-            var payload = {
-                code: jsEditor.getValue()
+            var dataToSend = {
+                payload: {
+                    code: jsEditor.getValue()
+                },
+                name: currentSnippetTitle,
+                description: currentSnippetDescription,
+                tags: currentSnippetTags
             };
 
-            xmlHttp.send(JSON.stringify(payload));
+            xmlHttp.send(JSON.stringify(dataToSend));
         }
 
-        document.getElementById("saveButton").addEventListener("click", save);
+        document.getElementById("saveButton").addEventListener("click", function() {
+            if(currentSnippetTitle == null
+                && currentSnippetDescription == null
+                && currentSnippetTags == null) {
+
+                document.getElementById("saveLayer").style.display = "block";
+            }
+            else {
+                save();
+            }
+        });
+        document.getElementById("saveFormButtonOk").addEventListener("click", function () {
+            document.getElementById("saveLayer").style.display = "none";
+            save();
+        });
+        document.getElementById("saveFormButtonCancel").addEventListener("click", function () {
+            document.getElementById("saveLayer").style.display = "none";
+        });
+        document.getElementById("saveMessage").addEventListener("click", function() {
+            document.getElementById("saveMessage").style.display = "none";
+        });
         document.getElementById("mainTitle").innerHTML = "Babylon.js v" + BABYLON.Engine.Version + " Playground";
 
         var previousHash = "";
@@ -557,9 +595,30 @@
                         xmlHttp.onreadystatechange = function () {
                             if (xmlHttp.readyState === 4) {
                                 if (xmlHttp.status === 200) {
-                                    var snippet = JSON.parse(xmlHttp.responseText);
+                                    var snippet = JSON.parse(xmlHttp.responseText)[0];
+
                                     blockEditorChange = true;
-                                    jsEditor.setValue(snippet.code.toString());
+                                    jsEditor.setValue(JSON.parse(snippet.jsonPayload).code.toString());
+
+                                    // Check if title / descr / tags are already set
+                                    if((snippet.name != null && snippet.name != "")
+                                        || (snippet.description != null && snippet.description != "")
+                                        || (snippet.tags != null && snippet.tags != ""))
+                                    {
+                                        currentSnippetTitle = snippet.name;
+                                        currentSnippetDescription = snippet.description;
+                                        currentSnippetTags = snippet.tags;
+
+                                        if(document.getElementById("saveLayer")) {
+                                            var elem = document.getElementById("saveLayer");
+                                            elem.outerHTML = "";
+                                            delete elem;
+                                        }
+                                    }
+                                    else {
+                                        document.getElementById("saveMessage").style.display = "block";
+                                    }
+
                                     jsEditor.setPosition({ lineNumber: 0, column: 0 });
                                     blockEditorChange = false;
                                     compileAndRun();

+ 1 - 1
Playground/package.json

@@ -4,7 +4,7 @@
   "description": "Babylon.js is a 3D engine based on webgl and javascript",
   "main": "",
   "repository": { "url": "https://github.com/BabylonJS/Babylon.js/" },
-  "readme": "https://github.com/BabylonJS/Babylon.js/edit/master/readme.md",
+  "readme": "https://github.com/BabylonJS/Babylon.js/blob/master/readme.md",
   "license": "(Apache-2.0)",
   "devDependencies": {
     "monaco-editor": "^0.7.0"

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 12 - 12
dist/preview release/babylon.core.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 801 - 794
dist/preview release/babylon.d.ts


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 23 - 23
dist/preview release/babylon.js


+ 110 - 80
dist/preview release/babylon.max.js

@@ -9567,7 +9567,7 @@ var BABYLON;
             this._alphaTest = enable;
         };
         Engine.prototype.getAlphaTesting = function () {
-            return this._alphaTest;
+            return !!this._alphaTest;
         };
         // Textures
         Engine.prototype.wipeCaches = function () {
@@ -12564,10 +12564,10 @@ var BABYLON;
             }
         };
         AbstractMesh.prototype._markSubMeshesAsLightDirty = function () {
-            this._markSubMeshesAsDirty(function (defines) { return defines._areLightsDirty = true; });
+            this._markSubMeshesAsDirty(function (defines) { return defines.markAsLightDirty(); });
         };
         AbstractMesh.prototype._markSubMeshesAsAttributesDirty = function () {
-            this._markSubMeshesAsDirty(function (defines) { return defines._areAttributesDirty = true; });
+            this._markSubMeshesAsDirty(function (defines) { return defines.markAsAttributesDirty(); });
         };
         AbstractMesh.prototype._markSubMeshesAsMiscDirty = function () {
             if (!this.subMeshes) {
@@ -30073,6 +30073,31 @@ var BABYLON;
     var MaterialHelper = (function () {
         function MaterialHelper() {
         }
+        MaterialHelper.PrepareDefinesForMisc = function (mesh, scene, useLogarithmicDepth, pointsCloud, fogEnabled, defines) {
+            if (defines._areMiscDirty) {
+                defines["LOGARITHMICDEPTH"] = useLogarithmicDepth;
+                defines["POINTSIZE"] = (pointsCloud || scene.forcePointsCloud);
+                defines["FOG"] = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && fogEnabled);
+            }
+        };
+        MaterialHelper.PrepareDefinesForFrameBoundValues = function (scene, engine, defines, useInstances) {
+            var changed = false;
+            if (defines["CLIPPLANE"] !== (scene.clipPlane !== undefined && scene.clipPlane !== null)) {
+                defines["CLIPPLANE"] = !defines["CLIPPLANE"];
+                changed = true;
+            }
+            if (defines["ALPHATEST"] !== engine.getAlphaTesting()) {
+                defines["ALPHATEST"] = !defines["ALPHATEST"];
+                changed = true;
+            }
+            if (defines["INSTANCES"] !== useInstances) {
+                defines["INSTANCES"] = useInstances;
+                changed = true;
+            }
+            if (changed) {
+                defines.markAsUnprocessed();
+            }
+        };
         MaterialHelper.PrepareDefinesForAttributes = function (mesh, defines, useInstances) {
             if (!defines._areAttributesDirty) {
                 return;
@@ -30097,7 +30122,7 @@ var BABYLON;
                 defines["BonesPerMesh"] = 0;
             }
         };
-        MaterialHelper.PrepareDefinesForLights = function (scene, mesh, defines, maxSimultaneousLights, disableLighting) {
+        MaterialHelper.PrepareDefinesForLights = function (scene, mesh, defines, specularSupported, maxSimultaneousLights, disableLighting) {
             if (maxSimultaneousLights === void 0) { maxSimultaneousLights = 4; }
             if (disableLighting === void 0) { disableLighting = false; }
             if (!defines._areLightsDirty) {
@@ -30136,7 +30161,7 @@ var BABYLON;
                     }
                     defines[type] = true;
                     // Specular
-                    if (!light.specular.equalsFloats(0, 0, 0)) {
+                    if (specularSupported && !light.specular.equalsFloats(0, 0, 0)) {
                         specularEnabled = true;
                     }
                     // Shadows
@@ -30201,6 +30226,9 @@ var BABYLON;
         };
         MaterialHelper.HandleFallbacksForShadows = function (defines, fallbacks, maxSimultaneousLights) {
             if (maxSimultaneousLights === void 0) { maxSimultaneousLights = 4; }
+            if (!defines["SHADOWS"]) {
+                return;
+            }
             for (var lightIndex = 0; lightIndex < maxSimultaneousLights; lightIndex++) {
                 if (!defines["LIGHT" + lightIndex]) {
                     break;
@@ -30386,9 +30414,8 @@ var BABYLON;
 var BABYLON;
 (function (BABYLON) {
     var MaterialDefines = (function () {
-        function MaterialDefines(trackIsDirty) {
+        function MaterialDefines() {
             this._isDirty = true;
-            this._trackIsDirty = false;
             this._areLightsDirty = true;
             this._areAttributesDirty = true;
             this._areTexturesDirty = true;
@@ -30396,24 +30423,44 @@ var BABYLON;
             this._areMiscDirty = true;
             this._needNormals = false;
             this._needUVs = false;
-            this._trackIsDirty = trackIsDirty;
         }
-        MaterialDefines.prototype._reBind = function (key) {
-            this["_" + key] = this[key];
-            Object.defineProperty(this, key, {
-                get: function () {
-                    return this["_" + key];
-                },
-                set: function (value) {
-                    if (this["_" + key] === value) {
-                        return;
-                    }
-                    this["_" + key] = value;
-                    this._isDirty = true;
-                },
-                enumerable: true,
-                configurable: true
-            });
+        Object.defineProperty(MaterialDefines.prototype, "isDirty", {
+            get: function () {
+                return this._isDirty;
+            },
+            enumerable: true,
+            configurable: true
+        });
+        MaterialDefines.prototype.markAsProcessed = function () {
+            this._isDirty = false;
+            this._areAttributesDirty = false;
+            this._areTexturesDirty = false;
+            this._areFresnelDirty = false;
+            this._areLightsDirty = false;
+            this._areMiscDirty = false;
+        };
+        MaterialDefines.prototype.markAsUnprocessed = function () {
+            this._isDirty = true;
+        };
+        MaterialDefines.prototype.markAsLightDirty = function () {
+            this._areLightsDirty = true;
+            this._isDirty = true;
+        };
+        MaterialDefines.prototype.markAsAttributesDirty = function () {
+            this._areAttributesDirty = true;
+            this._isDirty = true;
+        };
+        MaterialDefines.prototype.markAsTexturesDirty = function () {
+            this._areTexturesDirty = true;
+            this._isDirty = true;
+        };
+        MaterialDefines.prototype.markAsFresnelDirty = function () {
+            this._areFresnelDirty = true;
+            this._isDirty = true;
+        };
+        MaterialDefines.prototype.markAsMiscDirty = function () {
+            this._areMiscDirty = true;
+            this._isDirty = true;
         };
         MaterialDefines.prototype.rebuild = function () {
             if (this._keys) {
@@ -30426,15 +30473,7 @@ var BABYLON;
                     continue;
                 }
                 this._keys.push(key);
-                if (!this._trackIsDirty) {
-                    continue;
-                }
-                if (Object.getOwnPropertyDescriptor(this, key).get) {
-                    continue;
-                }
-                this._reBind(key);
             }
-            this._isDirty = true;
         };
         MaterialDefines.prototype.isEqual = function (other) {
             if (this._keys.length !== other._keys.length) {
@@ -30968,19 +31007,19 @@ var BABYLON;
             }
         };
         PushMaterial.prototype._markAllSubMeshesAsTexturesDirty = function () {
-            this._markAllSubMeshesAsDirty(function (defines) { return defines._areTexturesDirty = true; });
+            this._markAllSubMeshesAsDirty(function (defines) { return defines.markAsTexturesDirty(); });
         };
         PushMaterial.prototype._markAllSubMeshesAsFresnelDirty = function () {
-            this._markAllSubMeshesAsDirty(function (defines) { return defines._areFresnelDirty = true; });
+            this._markAllSubMeshesAsDirty(function (defines) { return defines.markAsFresnelDirty(); });
         };
         PushMaterial.prototype._markAllSubMeshesAsLightsDirty = function () {
-            this._markAllSubMeshesAsDirty(function (defines) { return defines._areLightsDirty = true; });
+            this._markAllSubMeshesAsDirty(function (defines) { return defines.markAsLightDirty(); });
         };
         PushMaterial.prototype._markAllSubMeshesAsAttributesDirty = function () {
-            this._markAllSubMeshesAsDirty(function (defines) { return defines._areAttributesDirty = true; });
+            this._markAllSubMeshesAsDirty(function (defines) { return defines.markAsAttributesDirty(); });
         };
         PushMaterial.prototype._markAllSubMeshesAsMiscDirty = function () {
-            this._markAllSubMeshesAsDirty(function (defines) { return defines._areMiscDirty = true; });
+            this._markAllSubMeshesAsDirty(function (defines) { return defines.markAsMiscDirty(); });
         };
         return PushMaterial;
     }(BABYLON.Material));
@@ -31000,7 +31039,7 @@ var BABYLON;
     var StandardMaterialDefines = (function (_super) {
         __extends(StandardMaterialDefines, _super);
         function StandardMaterialDefines() {
-            var _this = _super.call(this, true) || this;
+            var _this = _super.call(this) || this;
             _this.DIFFUSE = false;
             _this.AMBIENT = false;
             _this.OPACITY = false;
@@ -31152,16 +31191,16 @@ var BABYLON;
             configurable: true
         });
         StandardMaterial.prototype.needAlphaBlending = function () {
-            return (this.alpha < 1.0) || (this._opacityTexture != null) || this._shouldUseAlphaFromDiffuseTexture() || this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled;
+            return (this.alpha < 1.0) || (this._opacityTexture != null) || this._shouldUseAlphaFromDiffuseTexture() || this._opacityFresnelParameters && this._opacityFresnelParameters.isEnabled;
         };
         StandardMaterial.prototype.needAlphaTesting = function () {
-            return this.diffuseTexture != null && this.diffuseTexture.hasAlpha;
+            return this._diffuseTexture != null && this._diffuseTexture.hasAlpha;
         };
         StandardMaterial.prototype._shouldUseAlphaFromDiffuseTexture = function () {
-            return this.diffuseTexture != null && this.diffuseTexture.hasAlpha && this.useAlphaFromDiffuseTexture;
+            return this._diffuseTexture != null && this._diffuseTexture.hasAlpha && this._useAlphaFromDiffuseTexture;
         };
         StandardMaterial.prototype.getAlphaTestTexture = function () {
-            return this.diffuseTexture;
+            return this._diffuseTexture;
         };
         /**
          * Child classes can use it to update shaders
@@ -31184,8 +31223,7 @@ var BABYLON;
             }
             var engine = scene.getEngine();
             // Lights
-            defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, this._maxSimultaneousLights, this._disableLighting);
-            defines._areLightsDirty = false;
+            defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, true, this._maxSimultaneousLights, this._disableLighting);
             // Textures
             if (defines._areTexturesDirty) {
                 defines._needUVs = false;
@@ -31369,7 +31407,6 @@ var BABYLON;
                 defines.EMISSIVEASILLUMINATION = this._useEmissiveAsIllumination;
                 defines.LINKEMISSIVEWITHDIFFUSE = this._linkEmissiveWithDiffuse;
                 defines.SPECULAROVERALPHA = this._useSpecularOverAlpha;
-                defines._areTexturesDirty = false;
             }
             if (defines._areFresnelDirty) {
                 if (StandardMaterial.FresnelEnabled) {
@@ -31392,29 +31429,21 @@ var BABYLON;
                 else {
                     defines.FRESNEL = false;
                 }
-                defines._areFresnelDirty = false;
             }
             // Misc.
-            if (defines._areMiscDirty) {
-                defines.LOGARITHMICDEPTH = this._useLogarithmicDepth;
-                defines.POINTSIZE = (this.pointsCloud || scene.forcePointsCloud);
-                defines.FOG = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled);
-                defines._areMiscDirty = false;
-            }
+            BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, useInstances);
-            defines._areAttributesDirty = false;
             // Values that need to be evaluated on every frame
-            defines.CLIPPLANE = (scene.clipPlane !== undefined && scene.clipPlane !== null);
-            defines.ALPHATEST = engine.getAlphaTesting();
-            defines.INSTANCES = useInstances;
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
             if (scene._mirroredCameraPosition && defines.BUMP) {
                 defines.INVERTNORMALMAPX = !this.invertNormalMapX;
                 defines.INVERTNORMALMAPY = !this.invertNormalMapY;
+                defines.markAsUnprocessed();
             }
             // Get correct effect      
-            if (defines._isDirty) {
-                defines._isDirty = false;
+            if (defines.isDirty) {
+                defines.markAsProcessed();
                 scene.resetCachedMaterial();
                 // Fallbacks
                 var fallbacks = new BABYLON.EffectFallbacks();
@@ -60010,7 +60039,7 @@ var BABYLON;
             var needUVs = false;
             this._defines.reset();
             if (scene.lightsEnabled && !this.disableLighting) {
-                needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, this.maxSimultaneousLights) || needNormals;
+                needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, true, this.maxSimultaneousLights) || needNormals;
             }
             if (!this.checkReadyOnEveryCall) {
                 if (this._renderId === scene.getRenderId()) {
@@ -61013,6 +61042,7 @@ var BABYLON;
             // Getters and setters
             _this._depthOfFieldEnabled = true;
             _this._lensFlareEnabled = true;
+            _this._cameras = cameras || [];
             // Initialize
             _this._scene = scene;
             // Create pass post-processe
@@ -61063,15 +61093,15 @@ var BABYLON;
             set: function (enabled) {
                 var blurIndex = this.gaussianBlurHPostProcesses.length - 1;
                 if (enabled && !this._depthOfFieldEnabled) {
-                    this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRGaussianBlurH" + blurIndex, this._scene.cameras);
-                    this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRGaussianBlurV" + blurIndex, this._scene.cameras);
-                    this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRDepthOfField", this._scene.cameras);
+                    this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRGaussianBlurH" + blurIndex, this._cameras);
+                    this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRGaussianBlurV" + blurIndex, this._cameras);
+                    this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRDepthOfField", this._cameras);
                     this._depthRenderer = this._scene.enableDepthRenderer();
                 }
                 else if (!enabled && this._depthOfFieldEnabled) {
-                    this._scene.postProcessRenderPipelineManager.disableEffectInPipeline(this._name, "HDRGaussianBlurH" + blurIndex, this._scene.cameras);
-                    this._scene.postProcessRenderPipelineManager.disableEffectInPipeline(this._name, "HDRGaussianBlurV" + blurIndex, this._scene.cameras);
-                    this._scene.postProcessRenderPipelineManager.disableEffectInPipeline(this._name, "HDRDepthOfField", this._scene.cameras);
+                    this._scene.postProcessRenderPipelineManager.disableEffectInPipeline(this._name, "HDRGaussianBlurH" + blurIndex, this._cameras);
+                    this._scene.postProcessRenderPipelineManager.disableEffectInPipeline(this._name, "HDRGaussianBlurV" + blurIndex, this._cameras);
+                    this._scene.postProcessRenderPipelineManager.disableEffectInPipeline(this._name, "HDRDepthOfField", this._cameras);
                 }
                 this._depthOfFieldEnabled = enabled;
             },
@@ -61085,19 +61115,19 @@ var BABYLON;
             set: function (enabled) {
                 var blurIndex = this.gaussianBlurHPostProcesses.length - 2;
                 if (enabled && !this._lensFlareEnabled) {
-                    this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRLensFlare", this._scene.cameras);
-                    this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRLensFlareShift", this._scene.cameras);
-                    this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRGaussianBlurH" + blurIndex, this._scene.cameras);
-                    this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRGaussianBlurV" + blurIndex, this._scene.cameras);
-                    this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRLensFlareCompose", this._scene.cameras);
+                    this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRLensFlare", this._cameras);
+                    this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRLensFlareShift", this._cameras);
+                    this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRGaussianBlurH" + blurIndex, this._cameras);
+                    this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRGaussianBlurV" + blurIndex, this._cameras);
+                    this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, "HDRLensFlareCompose", this._cameras);
                     this._setDepthOfFieldSavePostProcess("HDRPostLensFlareDepthOfFieldSource");
                 }
                 else if (!enabled && this._lensFlareEnabled) {
-                    this._scene.postProcessRenderPipelineManager.disableEffectInPipeline(this._name, "HDRLensFlare", this._scene.cameras);
-                    this._scene.postProcessRenderPipelineManager.disableEffectInPipeline(this._name, "HDRLensFlareShift", this._scene.cameras);
-                    this._scene.postProcessRenderPipelineManager.disableEffectInPipeline(this._name, "HDRGaussianBlurH" + blurIndex, this._scene.cameras);
-                    this._scene.postProcessRenderPipelineManager.disableEffectInPipeline(this._name, "HDRGaussianBlurV" + blurIndex, this._scene.cameras);
-                    this._scene.postProcessRenderPipelineManager.disableEffectInPipeline(this._name, "HDRLensFlareCompose", this._scene.cameras);
+                    this._scene.postProcessRenderPipelineManager.disableEffectInPipeline(this._name, "HDRLensFlare", this._cameras);
+                    this._scene.postProcessRenderPipelineManager.disableEffectInPipeline(this._name, "HDRLensFlareShift", this._cameras);
+                    this._scene.postProcessRenderPipelineManager.disableEffectInPipeline(this._name, "HDRGaussianBlurH" + blurIndex, this._cameras);
+                    this._scene.postProcessRenderPipelineManager.disableEffectInPipeline(this._name, "HDRGaussianBlurV" + blurIndex, this._cameras);
+                    this._scene.postProcessRenderPipelineManager.disableEffectInPipeline(this._name, "HDRLensFlareCompose", this._cameras);
                     this._setDepthOfFieldSavePostProcess("HDRBaseDepthOfFieldSource");
                 }
                 this._lensFlareEnabled = enabled;
@@ -61107,8 +61137,8 @@ var BABYLON;
         });
         // Sets depth-of-field save post-process
         StandardRenderingPipeline.prototype._setDepthOfFieldSavePostProcess = function (name) {
-            this._scene.postProcessRenderPipelineManager.disableEffectInPipeline(this._name, "HDRPostLensFlareDepthOfFieldSource", this._scene.cameras);
-            this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, name, this._scene.cameras);
+            this._scene.postProcessRenderPipelineManager.disableEffectInPipeline(this._name, "HDRPostLensFlareDepthOfFieldSource", this._cameras);
+            this._scene.postProcessRenderPipelineManager.enableEffectInPipeline(this._name, name, this._cameras);
             switch (name) {
                 case "HDRBaseDepthOfFieldSource":
                     this._currentDepthOfFieldSource = this.textureAdderFinalPostProcess;
@@ -61274,8 +61304,8 @@ var BABYLON;
         };
         // Dispose
         StandardRenderingPipeline.prototype.dispose = function () {
-            for (var i = 0; i < this._scene.cameras.length; i++) {
-                var camera = this._scene.cameras[i];
+            for (var i = 0; i < this._cameras.length; i++) {
+                var camera = this._cameras[i];
                 this.originalPostProcess.dispose(camera);
                 this.downSampleX4PostProcess.dispose(camera);
                 this.brightPassPostProcess.dispose(camera);
@@ -61291,7 +61321,7 @@ var BABYLON;
                 this.lensFlareComposePostProcess.dispose(camera);
                 this.depthOfFieldPostProcess.dispose(camera);
             }
-            this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, this._scene.cameras);
+            this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, this._cameras);
             _super.prototype.dispose.call(this);
         };
         // Serialize rendering pipeline

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 801 - 794
dist/preview release/babylon.module.d.ts


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 29 - 29
dist/preview release/babylon.noworker.js


+ 6 - 7
dist/preview release/materialsLibrary/babylon.fireMaterial.d.ts

@@ -1,24 +1,23 @@
 /// <reference path="../../../dist/preview release/babylon.d.ts" />
 declare module BABYLON {
-    class FireMaterial extends Material {
+    class FireMaterial extends PushMaterial {
+        private _diffuseTexture;
         diffuseTexture: BaseTexture;
+        private _distortionTexture;
         distortionTexture: BaseTexture;
+        private _opacityTexture;
         opacityTexture: BaseTexture;
         diffuseColor: Color3;
         speed: number;
         private _scaledDiffuse;
         private _renderId;
-        private _defines;
-        private _cachedDefines;
         private _lastTime;
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         getAlphaTestTexture(): BaseTexture;
-        private _checkCache(scene, mesh?, useInstances?);
-        isReady(mesh?: AbstractMesh, useInstances?: boolean): boolean;
-        bindOnlyWorldMatrix(world: Matrix): void;
-        bind(world: Matrix, mesh?: Mesh): void;
+        isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
+        bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
         dispose(forceDisposeEffect?: boolean): void;
         clone(name: string): FireMaterial;

+ 100 - 124
dist/preview release/materialsLibrary/babylon.fireMaterial.js

@@ -17,7 +17,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
 };
 var BABYLON;
 (function (BABYLON) {
-    var maxSimultaneousLights = 4;
     var FireMaterialDefines = (function (_super) {
         __extends(FireMaterialDefines, _super);
         function FireMaterialDefines() {
@@ -33,7 +32,7 @@ var BABYLON;
             _this.BonesPerMesh = 0;
             _this.NUM_BONE_INFLUENCERS = 0;
             _this.INSTANCES = false;
-            _this._keys = Object.keys(_this);
+            _this.rebuild();
             return _this;
         }
         return FireMaterialDefines;
@@ -45,122 +44,87 @@ var BABYLON;
             _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
             _this.speed = 1.0;
             _this._scaledDiffuse = new BABYLON.Color3();
-            _this._defines = new FireMaterialDefines();
-            _this._cachedDefines = new FireMaterialDefines();
             _this._lastTime = 0;
-            _this._cachedDefines.BonesPerMesh = -1;
             return _this;
         }
         FireMaterial.prototype.needAlphaBlending = function () {
-            return (this.alpha < 1.0);
+            return false;
         };
         FireMaterial.prototype.needAlphaTesting = function () {
-            return false;
+            return true;
         };
         FireMaterial.prototype.getAlphaTestTexture = function () {
             return null;
         };
         // Methods   
-        FireMaterial.prototype._checkCache = function (scene, mesh, useInstances) {
-            if (!mesh) {
-                return true;
-            }
-            if (this._defines.INSTANCES !== useInstances) {
-                return false;
-            }
-            return false;
-        };
-        FireMaterial.prototype.isReady = function (mesh, useInstances) {
-            if (this.checkReadyOnlyOnce) {
-                if (this._wasPreviouslyReady) {
+        FireMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
+            if (this.isFrozen) {
+                if (this._wasPreviouslyReady && subMesh.effect) {
                     return true;
                 }
             }
+            if (!subMesh._materialDefines) {
+                subMesh._materialDefines = new FireMaterialDefines();
+            }
+            var defines = subMesh._materialDefines;
             var scene = this.getScene();
             if (!this.checkReadyOnEveryCall) {
                 if (this._renderId === scene.getRenderId()) {
-                    if (this._checkCache(scene, mesh, useInstances)) {
-                        return true;
-                    }
+                    return true;
                 }
             }
             var engine = scene.getEngine();
-            var needNormals = false;
-            var needUVs = false;
-            this._defines.reset();
             // Textures
-            if (scene.texturesEnabled) {
-                if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
-                    if (!this.diffuseTexture.isReady()) {
+            if (defines._areTexturesDirty) {
+                defines._needUVs = false;
+                if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
+                    if (!this._diffuseTexture.isReady()) {
                         return false;
                     }
                     else {
-                        needUVs = true;
-                        this._defines.DIFFUSE = true;
+                        defines._needUVs = true;
+                        defines.DIFFUSE = true;
                     }
                 }
+                defines._areTexturesDirty = false;
             }
-            // Effect
-            if (scene.clipPlane) {
-                this._defines.CLIPPLANE = true;
-            }
-            this._defines.ALPHATEST = true;
-            // Point size
-            if (this.pointsCloud || scene.forcePointsCloud) {
-                this._defines.POINTSIZE = true;
-            }
-            // Fog
-            if (scene.fogEnabled && mesh && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled) {
-                this._defines.FOG = true;
+            // Misc.
+            if (defines._areMiscDirty) {
+                defines.POINTSIZE = (this.pointsCloud || scene.forcePointsCloud);
+                defines.FOG = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled);
+                defines._areMiscDirty = false;
             }
+            // Values that need to be evaluated on every frame
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
             // Attribs
-            if (mesh) {
-                if (needUVs) {
-                    if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
-                        this._defines.UV1 = true;
-                    }
-                }
-                if (mesh.useVertexColors && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)) {
-                    this._defines.VERTEXCOLOR = true;
-                    if (mesh.hasVertexAlpha) {
-                        this._defines.VERTEXALPHA = true;
-                    }
-                }
-                if (mesh.useBones && mesh.computeBonesUsingShaders) {
-                    this._defines.NUM_BONE_INFLUENCERS = mesh.numBoneInfluencers;
-                    this._defines.BonesPerMesh = (mesh.skeleton.bones.length + 1);
-                }
-                // Instances
-                if (useInstances) {
-                    this._defines.INSTANCES = true;
-                }
-            }
+            BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, useInstances);
+            defines._areAttributesDirty = false;
             // Get correct effect      
-            if (!this._defines.isEqual(this._cachedDefines)) {
-                this._defines.cloneTo(this._cachedDefines);
+            if (defines.isDirty) {
+                defines.markAsProcessed();
                 scene.resetCachedMaterial();
                 // Fallbacks
                 var fallbacks = new BABYLON.EffectFallbacks();
-                if (this._defines.FOG) {
+                if (defines.FOG) {
                     fallbacks.addFallback(1, "FOG");
                 }
-                if (this._defines.NUM_BONE_INFLUENCERS > 0) {
+                if (defines.NUM_BONE_INFLUENCERS > 0) {
                     fallbacks.addCPUSkinningFallback(0, mesh);
                 }
                 //Attributes
                 var attribs = [BABYLON.VertexBuffer.PositionKind];
-                if (this._defines.UV1) {
+                if (defines.UV1) {
                     attribs.push(BABYLON.VertexBuffer.UVKind);
                 }
-                if (this._defines.VERTEXCOLOR) {
+                if (defines.VERTEXCOLOR) {
                     attribs.push(BABYLON.VertexBuffer.ColorKind);
                 }
-                BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
-                BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, this._defines);
+                BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
+                BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
                 // Legacy browser patch
                 var shaderName = "fire";
-                var join = this._defines.toString();
-                this._effect = scene.getEngine().createEffect(shaderName, attribs, ["world", "view", "viewProjection", "vEyePosition",
+                var join = defines.toString();
+                subMesh.setEffect(scene.getEngine().createEffect(shaderName, attribs, ["world", "view", "viewProjection", "vEyePosition",
                     "vFogInfos", "vFogColor", "pointSize",
                     "vDiffuseInfos",
                     "mBones",
@@ -170,78 +134,81 @@ var BABYLON;
                 ], ["diffuseSampler",
                     // Fire
                     "distortionSampler", "opacitySampler"
-                ], join, fallbacks, this.onCompiled, this.onError);
+                ], join, fallbacks, this.onCompiled, this.onError), defines);
             }
-            if (!this._effect.isReady()) {
+            if (!subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
             this._wasPreviouslyReady = true;
             return true;
         };
-        FireMaterial.prototype.bindOnlyWorldMatrix = function (world) {
-            this._effect.setMatrix("world", world);
-        };
-        FireMaterial.prototype.bind = function (world, mesh) {
+        FireMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
             var scene = this.getScene();
-            // Matrices        
+            var defines = subMesh._materialDefines;
+            if (!defines) {
+                return;
+            }
+            var effect = subMesh.effect;
+            this._activeEffect = effect;
+            // Matrices
             this.bindOnlyWorldMatrix(world);
-            this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
+            this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
             // Bones
-            BABYLON.MaterialHelper.BindBonesParameters(mesh, this._effect);
-            if (scene.getCachedMaterial() !== this) {
+            BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
+            if (this._mustRebind(scene, effect)) {
                 // Textures        
-                if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
-                    this._effect.setTexture("diffuseSampler", this.diffuseTexture);
-                    this._effect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
-                    this._effect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
-                    this._effect.setTexture("distortionSampler", this.distortionTexture);
-                    this._effect.setTexture("opacitySampler", this.opacityTexture);
+                if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
+                    this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
+                    this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
+                    this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
+                    this._activeEffect.setTexture("distortionSampler", this._distortionTexture);
+                    this._activeEffect.setTexture("opacitySampler", this._opacityTexture);
                 }
                 // Clip plane
                 if (scene.clipPlane) {
                     var clipPlane = scene.clipPlane;
-                    this._effect.setFloat4("vClipPlane", clipPlane.normal.x, clipPlane.normal.y, clipPlane.normal.z, clipPlane.d);
+                    this._activeEffect.setFloat4("vClipPlane", clipPlane.normal.x, clipPlane.normal.y, clipPlane.normal.z, clipPlane.d);
                 }
                 // Point size
                 if (this.pointsCloud) {
-                    this._effect.setFloat("pointSize", this.pointSize);
+                    this._activeEffect.setFloat("pointSize", this.pointSize);
                 }
-                this._effect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
+                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
             }
-            this._effect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
+            this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
             // View
             if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
-                this._effect.setMatrix("view", scene.getViewMatrix());
+                this._activeEffect.setMatrix("view", scene.getViewMatrix());
             }
             // Fog
-            BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._effect);
+            BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
             // Time
             this._lastTime += scene.getEngine().getDeltaTime();
-            this._effect.setFloat("time", this._lastTime);
+            this._activeEffect.setFloat("time", this._lastTime);
             // Speed
-            this._effect.setFloat("speed", this.speed);
-            _super.prototype.bind.call(this, world, mesh);
+            this._activeEffect.setFloat("speed", this.speed);
+            this._afterBind(mesh, this._activeEffect);
         };
         FireMaterial.prototype.getAnimatables = function () {
             var results = [];
-            if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
-                results.push(this.diffuseTexture);
+            if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
+                results.push(this._diffuseTexture);
             }
-            if (this.distortionTexture && this.distortionTexture.animations && this.distortionTexture.animations.length > 0) {
-                results.push(this.distortionTexture);
+            if (this._distortionTexture && this._distortionTexture.animations && this._distortionTexture.animations.length > 0) {
+                results.push(this._distortionTexture);
             }
-            if (this.opacityTexture && this.opacityTexture.animations && this.opacityTexture.animations.length > 0) {
-                results.push(this.opacityTexture);
+            if (this._opacityTexture && this._opacityTexture.animations && this._opacityTexture.animations.length > 0) {
+                results.push(this._opacityTexture);
             }
             return results;
         };
         FireMaterial.prototype.dispose = function (forceDisposeEffect) {
-            if (this.diffuseTexture) {
-                this.diffuseTexture.dispose();
+            if (this._diffuseTexture) {
+                this._diffuseTexture.dispose();
             }
-            if (this.distortionTexture) {
-                this.distortionTexture.dispose();
+            if (this._distortionTexture) {
+                this._distortionTexture.dispose();
             }
             _super.prototype.dispose.call(this, forceDisposeEffect);
         };
@@ -254,14 +221,14 @@ var BABYLON;
             serializationObject.customType = "BABYLON.FireMaterial";
             serializationObject.diffuseColor = this.diffuseColor.asArray();
             serializationObject.speed = this.speed;
-            if (this.diffuseTexture) {
-                serializationObject.diffuseTexture = this.diffuseTexture.serialize();
+            if (this._diffuseTexture) {
+                serializationObject._diffuseTexture = this._diffuseTexture.serialize();
             }
-            if (this.distortionTexture) {
-                serializationObject.distortionTexture = this.distortionTexture.serialize();
+            if (this._distortionTexture) {
+                serializationObject._distortionTexture = this._distortionTexture.serialize();
             }
-            if (this.opacityTexture) {
-                serializationObject.opacityTexture = this.opacityTexture.serialize();
+            if (this._opacityTexture) {
+                serializationObject._opacityTexture = this._opacityTexture.serialize();
             }
             return serializationObject;
         };
@@ -274,14 +241,14 @@ var BABYLON;
             BABYLON.Tags.AddTagsTo(material, source.tags);
             material.backFaceCulling = source.backFaceCulling;
             material.wireframe = source.wireframe;
-            if (source.diffuseTexture) {
-                material.diffuseTexture = BABYLON.Texture.Parse(source.diffuseTexture, scene, rootUrl);
+            if (source._diffuseTexture) {
+                material._diffuseTexture = BABYLON.Texture.Parse(source._diffuseTexture, scene, rootUrl);
             }
-            if (source.distortionTexture) {
-                material.distortionTexture = BABYLON.Texture.Parse(source.distortionTexture, scene, rootUrl);
+            if (source._distortionTexture) {
+                material._distortionTexture = BABYLON.Texture.Parse(source._distortionTexture, scene, rootUrl);
             }
-            if (source.opacityTexture) {
-                material.opacityTexture = BABYLON.Texture.Parse(source.opacityTexture, scene, rootUrl);
+            if (source._opacityTexture) {
+                material._opacityTexture = BABYLON.Texture.Parse(source._opacityTexture, scene, rootUrl);
             }
             if (source.checkReadyOnlyOnce) {
                 material.checkReadyOnlyOnce = source.checkReadyOnlyOnce;
@@ -289,15 +256,24 @@ var BABYLON;
             return material;
         };
         return FireMaterial;
-    }(BABYLON.Material));
+    }(BABYLON.PushMaterial));
     __decorate([
-        BABYLON.serializeAsTexture()
+        BABYLON.serializeAsTexture("diffuseTexture")
+    ], FireMaterial.prototype, "_diffuseTexture", void 0);
+    __decorate([
+        BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
     ], FireMaterial.prototype, "diffuseTexture", void 0);
     __decorate([
-        BABYLON.serializeAsTexture()
+        BABYLON.serializeAsTexture("distortionTexture")
+    ], FireMaterial.prototype, "_distortionTexture", void 0);
+    __decorate([
+        BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
     ], FireMaterial.prototype, "distortionTexture", void 0);
     __decorate([
-        BABYLON.serializeAsTexture()
+        BABYLON.serializeAsTexture("opacityTexture")
+    ], FireMaterial.prototype, "_opacityTexture", void 0);
+    __decorate([
+        BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
     ], FireMaterial.prototype, "opacityTexture", void 0);
     __decorate([
         BABYLON.serialize("diffuseColor")

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
dist/preview release/materialsLibrary/babylon.fireMaterial.min.js


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

@@ -170,7 +170,7 @@ var BABYLON;
             }
             // Lights
             if (scene.lightsEnabled && !this.disableLighting) {
-                needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, this.maxSimultaneousLights);
+                needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, false, this.maxSimultaneousLights);
             }
             // Attribs
             if (mesh) {

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

@@ -68,7 +68,7 @@ var BABYLON;
             _this.NUM_BONE_INFLUENCERS = 0;
             _this.BonesPerMesh = 0;
             _this.INSTANCES = false;
-            _this._keys = Object.keys(_this);
+            _this.rebuild();
             return _this;
         }
         return GradientMaterialDefines;
@@ -149,7 +149,7 @@ var BABYLON;
             }
             var lightIndex = 0;
             if (scene.lightsEnabled && !this.disableLighting) {
-                needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines);
+                needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, false);
             }
             // Attribs
             if (mesh) {
@@ -212,10 +212,10 @@ var BABYLON;
                 var shaderName = "gradient";
                 var join = this._defines.toString();
                 this._effect = scene.getEngine().createEffect(shaderName, attribs, ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
-                    "vLightData0", "vLightDiffuse0", "vLightSpecular0", "vLightDirection0", "vLightGround0", "lightMatrix0",
-                    "vLightData1", "vLightDiffuse1", "vLightSpecular1", "vLightDirection1", "vLightGround1", "lightMatrix1",
-                    "vLightData2", "vLightDiffuse2", "vLightSpecular2", "vLightDirection2", "vLightGround2", "lightMatrix2",
-                    "vLightData3", "vLightDiffuse3", "vLightSpecular3", "vLightDirection3", "vLightGround3", "lightMatrix3",
+                    "vLightData0", "vLightDiffuse0", "vLightDirection0", "vLightGround0", "lightMatrix0",
+                    "vLightData1", "vLightDiffuse1", "vLightDirection1", "vLightGround1", "lightMatrix1",
+                    "vLightData2", "vLightDiffuse2", "vLightDirection2", "vLightGround2", "lightMatrix2",
+                    "vLightData3", "vLightDiffuse3", "vLightDirection3", "vLightGround3", "lightMatrix3",
                     "vFogInfos", "vFogColor", "pointSize",
                     "vDiffuseInfos",
                     "mBones",
@@ -265,7 +265,7 @@ var BABYLON;
             this._effect.setColor4("bottomColor", this.bottomColor, this.bottomColorAlpha);
             this._effect.setFloat("offset", this.offset);
             this._effect.setFloat("smoothness", this.smoothness);
-            _super.prototype.bind.call(this, world, mesh);
+            this._afterBind(mesh);
         };
         GradientMaterial.prototype.getAnimatables = function () {
             return [];

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
dist/preview release/materialsLibrary/babylon.gradientMaterial.min.js


+ 2 - 2
dist/preview release/materialsLibrary/babylon.gridMaterial.js

@@ -23,7 +23,7 @@ var BABYLON;
             var _this = _super.call(this) || this;
             _this.TRANSPARENT = false;
             _this.FOG = false;
-            _this._keys = Object.keys(_this);
+            _this.rebuild();
             return _this;
         }
         return GRIDMaterialDefines;
@@ -151,7 +151,7 @@ var BABYLON;
             }
             // Fog
             BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._effect);
-            _super.prototype.bind.call(this, world, mesh);
+            this._afterBind(mesh);
         };
         GridMaterial.prototype.dispose = function (forceDisposeEffect) {
             _super.prototype.dispose.call(this, forceDisposeEffect);

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
dist/preview release/materialsLibrary/babylon.gridMaterial.min.js


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

@@ -67,7 +67,7 @@ var BABYLON;
             _this.NUM_BONE_INFLUENCERS = 0;
             _this.BonesPerMesh = 0;
             _this.INSTANCES = false;
-            _this._keys = Object.keys(_this);
+            _this.rebuild();
             return _this;
         }
         return LavaMaterialDefines;
@@ -155,7 +155,7 @@ var BABYLON;
                 this._defines.FOG = true;
             }
             if (scene.lightsEnabled && !this.disableLighting) {
-                BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, this.maxSimultaneousLights);
+                BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, false, this.maxSimultaneousLights);
             }
             // Attribs
             if (mesh) {
@@ -218,10 +218,10 @@ var BABYLON;
                 var shaderName = "lava";
                 var join = this._defines.toString();
                 this._effect = scene.getEngine().createEffect(shaderName, attribs, ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
-                    "vLightData0", "vLightDiffuse0", "vLightSpecular0", "vLightDirection0", "vLightGround0", "lightMatrix0",
-                    "vLightData1", "vLightDiffuse1", "vLightSpecular1", "vLightDirection1", "vLightGround1", "lightMatrix1",
-                    "vLightData2", "vLightDiffuse2", "vLightSpecular2", "vLightDirection2", "vLightGround2", "lightMatrix2",
-                    "vLightData3", "vLightDiffuse3", "vLightSpecular3", "vLightDirection3", "vLightGround3", "lightMatrix3",
+                    "vLightData0", "vLightDiffuse0", "vLightDirection0", "vLightGround0", "lightMatrix0",
+                    "vLightData1", "vLightDiffuse1", "vLightDirection1", "vLightGround1", "lightMatrix1",
+                    "vLightData2", "vLightDiffuse2", "vLightDirection2", "vLightGround2", "lightMatrix2",
+                    "vLightData3", "vLightDiffuse3", "vLightDirection3", "vLightGround3", "lightMatrix3",
                     "vFogInfos", "vFogColor", "pointSize",
                     "vDiffuseInfos",
                     "mBones",
@@ -287,7 +287,7 @@ var BABYLON;
             this._effect.setFloat("fogDensity", this.fogDensity);
             this._effect.setFloat("lowFrequencySpeed", this.lowFrequencySpeed);
             this._effect.setFloat("movingSpeed", this.movingSpeed);
-            _super.prototype.bind.call(this, world, mesh);
+            this._afterBind(mesh);
         };
         LavaMaterial.prototype.getAnimatables = function () {
             var results = [];

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
dist/preview release/materialsLibrary/babylon.lavaMaterial.min.js


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

@@ -67,7 +67,7 @@ var BABYLON;
             _this.NUM_BONE_INFLUENCERS = 0;
             _this.BonesPerMesh = 0;
             _this.INSTANCES = false;
-            _this._keys = Object.keys(_this);
+            _this.rebuild();
             return _this;
         }
         return NormalMaterialDefines;
@@ -151,7 +151,7 @@ var BABYLON;
             }
             var lightIndex = 0;
             if (scene.lightsEnabled && !this.disableLighting) {
-                needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines);
+                needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, false);
             }
             // Attribs
             if (mesh) {
@@ -213,10 +213,10 @@ var BABYLON;
                 var shaderName = "normal";
                 var join = this._defines.toString();
                 this._effect = scene.getEngine().createEffect(shaderName, attribs, ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
-                    "vLightData0", "vLightDiffuse0", "vLightSpecular0", "vLightDirection0", "vLightGround0", "lightMatrix0",
-                    "vLightData1", "vLightDiffuse1", "vLightSpecular1", "vLightDirection1", "vLightGround1", "lightMatrix1",
-                    "vLightData2", "vLightDiffuse2", "vLightSpecular2", "vLightDirection2", "vLightGround2", "lightMatrix2",
-                    "vLightData3", "vLightDiffuse3", "vLightSpecular3", "vLightDirection3", "vLightGround3", "lightMatrix3",
+                    "vLightData0", "vLightDiffuse0", "vLightDirection0", "vLightGround0", "lightMatrix0",
+                    "vLightData1", "vLightDiffuse1", "vLightDirection1", "vLightGround1", "lightMatrix1",
+                    "vLightData2", "vLightDiffuse2", "vLightDirection2", "vLightGround2", "lightMatrix2",
+                    "vLightData3", "vLightDiffuse3", "vLightDirection3", "vLightGround3", "lightMatrix3",
                     "vFogInfos", "vFogColor", "pointSize",
                     "vDiffuseInfos",
                     "mBones",
@@ -269,7 +269,7 @@ var BABYLON;
             }
             // Fog
             BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._effect);
-            _super.prototype.bind.call(this, world, mesh);
+            this._afterBind(mesh);
         };
         NormalMaterial.prototype.getAnimatables = function () {
             var results = [];

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
dist/preview release/materialsLibrary/babylon.normalMaterial.min.js


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

@@ -93,7 +93,7 @@ var BABYLON;
                 this._defines.FOG = true;
             }
             if (scene.lightsEnabled) {
-                needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, 1);
+                needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, false, 1);
             }
             // Attribs
             if (mesh) {
@@ -176,7 +176,7 @@ var BABYLON;
             }
             // Fog
             BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._effect);
-            _super.prototype.bind.call(this, world, mesh);
+            this._afterBind(mesh);
         };
         ShadowOnlyMaterial.prototype.clone = function (name) {
             var _this = this;

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
dist/preview release/materialsLibrary/babylon.shadowOnlyMaterial.min.js


+ 6 - 7
dist/preview release/materialsLibrary/babylon.simpleMaterial.d.ts

@@ -1,23 +1,22 @@
 /// <reference path="../../../dist/preview release/babylon.d.ts" />
 declare module BABYLON {
-    class SimpleMaterial extends Material {
+    class SimpleMaterial extends PushMaterial {
+        private _diffuseTexture;
         diffuseTexture: BaseTexture;
         diffuseColor: Color3;
+        private _disableLighting;
         disableLighting: boolean;
+        private _maxSimultaneousLights;
         maxSimultaneousLights: number;
         private _worldViewProjectionMatrix;
         private _scaledDiffuse;
         private _renderId;
-        private _defines;
-        private _cachedDefines;
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         getAlphaTestTexture(): BaseTexture;
-        private _checkCache(scene, mesh?, useInstances?);
-        isReady(mesh?: AbstractMesh, useInstances?: boolean): boolean;
-        bindOnlyWorldMatrix(world: Matrix): void;
-        bind(world: Matrix, mesh?: Mesh): void;
+        isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
+        bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
         dispose(forceDisposeEffect?: boolean): void;
         clone(name: string): SimpleMaterial;

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 89 - 118
dist/preview release/materialsLibrary/babylon.simpleMaterial.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
dist/preview release/materialsLibrary/babylon.simpleMaterial.min.js


+ 2 - 2
dist/preview release/materialsLibrary/babylon.skyMaterial.js

@@ -26,7 +26,7 @@ var BABYLON;
             _this.FOG = false;
             _this.VERTEXCOLOR = false;
             _this.VERTEXALPHA = false;
-            _this._keys = Object.keys(_this);
+            _this.rebuild();
             return _this;
         }
         return SkyMaterialDefines;
@@ -184,7 +184,7 @@ var BABYLON;
                 this.sunPosition.z = this.distance * Math.sin(phi) * Math.cos(theta);
             }
             this._effect.setVector3("sunPosition", this.sunPosition);
-            _super.prototype.bind.call(this, world, mesh);
+            this._afterBind(mesh);
         };
         SkyMaterial.prototype.getAnimatables = function () {
             return [];

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
dist/preview release/materialsLibrary/babylon.skyMaterial.min.js


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

@@ -111,7 +111,7 @@ var BABYLON;
             }
             // Lights
             if (scene.lightsEnabled && !this.disableLighting) {
-                needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, this.maxSimultaneousLights);
+                needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, true, this.maxSimultaneousLights);
             }
             // Textures
             if (scene.texturesEnabled) {
@@ -273,7 +273,7 @@ var BABYLON;
             }
             // Fog
             BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._effect);
-            _super.prototype.bind.call(this, world, mesh);
+            this._afterBind(mesh);
         };
         TerrainMaterial.prototype.getAnimatables = function () {
             var results = [];

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
dist/preview release/materialsLibrary/babylon.terrainMaterial.min.js


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

@@ -144,7 +144,7 @@ var BABYLON;
             }
             // Lights
             if (scene.lightsEnabled && !this.disableLighting) {
-                needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, this.maxSimultaneousLights);
+                needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, true, this.maxSimultaneousLights);
             }
             // Attribs
             if (mesh) {
@@ -263,7 +263,7 @@ var BABYLON;
             }
             // Fog
             BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._effect);
-            _super.prototype.bind.call(this, world, mesh);
+            this._afterBind(mesh);
         };
         TriPlanarMaterial.prototype.getAnimatables = function () {
             var results = [];

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
dist/preview release/materialsLibrary/babylon.triPlanarMaterial.min.js


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

@@ -248,7 +248,7 @@ var BABYLON;
             }
             // Lights
             if (scene.lightsEnabled && !this.disableLighting) {
-                needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, this.maxSimultaneousLights);
+                needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, true, this.maxSimultaneousLights);
             }
             // Attribs
             if (mesh) {
@@ -397,7 +397,7 @@ var BABYLON;
             this._effect.setColor4("waterColor2", this.waterColor2, 1.0);
             this._effect.setFloat("colorBlendFactor2", this.colorBlendFactor2);
             this._effect.setFloat("waveSpeed", this.waveSpeed);
-            _super.prototype.bind.call(this, world, mesh);
+            this._afterBind(mesh);
         };
         WaterMaterial.prototype._createRenderTargets = function (scene, renderTargetSize) {
             var _this = this;

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
dist/preview release/materialsLibrary/babylon.waterMaterial.min.js


+ 2 - 0
materialsLibrary/index.html

@@ -71,6 +71,7 @@
 			pointLight.setEnabled(false);
 			var directionalLight = new BABYLON.DirectionalLight("directional", new BABYLON.Vector3(0,-1, 0), scene);
 			directionalLight.setEnabled(false);
+			directionalLight.position = new BABYLON.Vector3(0, 50, 0);
 			var spotLight = new BABYLON.SpotLight("spot", new BABYLON.Vector3(0, -30, 0), new BABYLON.Vector3(0, 1, 0), 1.1, 1, scene);
 			spotLight.setEnabled(false);
 
@@ -128,6 +129,7 @@
 				var shadowGenerator = new BABYLON.ShadowGenerator(1024, directionalLight);
 				shadowGenerator.getShadowMap().renderList.push(shadowCaster);
 				shadowGenerator.usePoissonSampling = true;
+				shadowGenerator.bias = 0;
 				
 				var shadowGenerator2 = new BABYLON.ShadowGenerator(1024, spotLight);
 				shadowGenerator2.getShadowMap().renderList.push(shadowCaster2);

+ 4 - 10
materialsLibrary/src/fire/babylon.fireMaterial.ts

@@ -96,30 +96,24 @@ module BABYLON {
                         defines._needUVs = true;
                         defines.DIFFUSE = true;
                     }
-                }  
-                defines._areTexturesDirty = false;              
+                }              
             }
 
             // Misc.
             if (defines._areMiscDirty) {
                 defines.POINTSIZE = (this.pointsCloud || scene.forcePointsCloud);
                 defines.FOG = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE && this.fogEnabled);
-
-                defines._areMiscDirty = false;
             }
             
             // Values that need to be evaluated on every frame
-            defines.CLIPPLANE = (scene.clipPlane !== undefined && scene.clipPlane !== null);
-            defines.ALPHATEST = engine.getAlphaTesting();
-            defines.INSTANCES = useInstances;
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
             
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, useInstances);
-            defines._areAttributesDirty = false;
 
             // Get correct effect      
-            if (defines._isDirty) {
-                defines._isDirty = false;
+            if (defines.isDirty) {
+                defines.markAsProcessed();
 
                 scene.resetCachedMaterial();
 

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

@@ -209,7 +209,7 @@ module BABYLON {
 
             // Lights
             if (scene.lightsEnabled && !this.disableLighting) {
-                needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, this.maxSimultaneousLights);
+                needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, false, this.maxSimultaneousLights);
             }
 
             // Attribs

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

@@ -53,7 +53,7 @@ module BABYLON {
 
         constructor() {
             super();
-            this._keys = Object.keys(this);
+            this.rebuild();
         }
     }
 
@@ -167,7 +167,7 @@ module BABYLON {
 
             var lightIndex = 0;
             if (scene.lightsEnabled && !this.disableLighting) {
-                needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines);
+                needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, false);
             }
 
             // Attribs
@@ -248,10 +248,10 @@ module BABYLON {
                 this._effect = scene.getEngine().createEffect(shaderName,
                     attribs,
                     ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
-                        "vLightData0", "vLightDiffuse0", "vLightSpecular0", "vLightDirection0", "vLightGround0", "lightMatrix0",
-                        "vLightData1", "vLightDiffuse1", "vLightSpecular1", "vLightDirection1", "vLightGround1", "lightMatrix1",
-                        "vLightData2", "vLightDiffuse2", "vLightSpecular2", "vLightDirection2", "vLightGround2", "lightMatrix2",
-                        "vLightData3", "vLightDiffuse3", "vLightSpecular3", "vLightDirection3", "vLightGround3", "lightMatrix3",
+                        "vLightData0", "vLightDiffuse0","vLightDirection0", "vLightGround0", "lightMatrix0",
+                        "vLightData1", "vLightDiffuse1", "vLightDirection1", "vLightGround1", "lightMatrix1",
+                        "vLightData2", "vLightDiffuse2", "vLightDirection2", "vLightGround2", "lightMatrix2",
+                        "vLightData3", "vLightDiffuse3", "vLightDirection3", "vLightGround3", "lightMatrix3",
                         "vFogInfos", "vFogColor", "pointSize",
                         "vDiffuseInfos", 
                         "mBones",

+ 1 - 1
materialsLibrary/src/grid/babylon.gridmaterial.ts

@@ -8,7 +8,7 @@ module BABYLON {
 
         constructor() {
             super();
-            this._keys = Object.keys(this);
+            this.rebuild();
         }
     }
 

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

@@ -51,7 +51,7 @@ module BABYLON {
 
         constructor() {
             super();
-            this._keys = Object.keys(this);
+            this.rebuild();
         }
     }
 
@@ -180,7 +180,7 @@ module BABYLON {
             }
 
             if (scene.lightsEnabled && !this.disableLighting) {
-                MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, this.maxSimultaneousLights);
+                MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, false, this.maxSimultaneousLights);
             }
 
             // Attribs
@@ -260,10 +260,10 @@ module BABYLON {
                 this._effect = scene.getEngine().createEffect(shaderName,
                     attribs,
                     ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
-                        "vLightData0", "vLightDiffuse0", "vLightSpecular0", "vLightDirection0", "vLightGround0", "lightMatrix0",
-                        "vLightData1", "vLightDiffuse1", "vLightSpecular1", "vLightDirection1", "vLightGround1", "lightMatrix1",
-                        "vLightData2", "vLightDiffuse2", "vLightSpecular2", "vLightDirection2", "vLightGround2", "lightMatrix2",
-                        "vLightData3", "vLightDiffuse3", "vLightSpecular3", "vLightDirection3", "vLightGround3", "lightMatrix3",
+                        "vLightData0", "vLightDiffuse0", "vLightDirection0", "vLightGround0", "lightMatrix0",
+                        "vLightData1", "vLightDiffuse1", "vLightDirection1", "vLightGround1", "lightMatrix1",
+                        "vLightData2", "vLightDiffuse2", "vLightDirection2", "vLightGround2", "lightMatrix2",
+                        "vLightData3", "vLightDiffuse3", "vLightDirection3", "vLightGround3", "lightMatrix3",
                         "vFogInfos", "vFogColor", "pointSize",
                         "vDiffuseInfos",
                         "mBones",

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

@@ -51,7 +51,7 @@ module BABYLON {
 
         constructor() {
             super();
-            this._keys = Object.keys(this);
+            this.rebuild();
         }
     }
 
@@ -159,7 +159,7 @@ module BABYLON {
 
             var lightIndex = 0;
             if (scene.lightsEnabled && !this.disableLighting) {
-                needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines);
+                needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, false);
             }
 
             // Attribs
@@ -238,10 +238,10 @@ module BABYLON {
                 this._effect = scene.getEngine().createEffect(shaderName,
                     attribs,
                     ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
-                        "vLightData0", "vLightDiffuse0", "vLightSpecular0", "vLightDirection0", "vLightGround0", "lightMatrix0",
-                        "vLightData1", "vLightDiffuse1", "vLightSpecular1", "vLightDirection1", "vLightGround1", "lightMatrix1",
-                        "vLightData2", "vLightDiffuse2", "vLightSpecular2", "vLightDirection2", "vLightGround2", "lightMatrix2",
-                        "vLightData3", "vLightDiffuse3", "vLightSpecular3", "vLightDirection3", "vLightGround3", "lightMatrix3",
+                        "vLightData0", "vLightDiffuse0", "vLightDirection0", "vLightGround0", "lightMatrix0",
+                        "vLightData1", "vLightDiffuse1", "vLightDirection1", "vLightGround1", "lightMatrix1",
+                        "vLightData2", "vLightDiffuse2", "vLightDirection2", "vLightGround2", "lightMatrix2",
+                        "vLightData3", "vLightDiffuse3", "vLightDirection3", "vLightGround3", "lightMatrix3",
                         "vFogInfos", "vFogColor", "pointSize",
                         "vDiffuseInfos", 
                         "mBones",

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

@@ -95,7 +95,7 @@ module BABYLON {
             }
 
             if (scene.lightsEnabled) {
-                needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, 1);
+                needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, false, 1);
             }
 
             // Attribs

+ 5 - 15
materialsLibrary/src/simple/babylon.simpleMaterial.ts

@@ -97,33 +97,23 @@ module BABYLON {
                         }
                     }                
                 }
-                defines._areTexturesDirty = false;
             }
 
             // Misc.
-            if (defines._areMiscDirty) {
-                defines.POINTSIZE = (this.pointsCloud || scene.forcePointsCloud);
-                defines.FOG = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE && this.fogEnabled);
-
-                defines._areMiscDirty = false;
-            }
+            MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
 
             // Lights
-            defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, this._maxSimultaneousLights, this._disableLighting);
-            defines._areLightsDirty = false;
+            defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
             // Values that need to be evaluated on every frame
-            defines.CLIPPLANE = (scene.clipPlane !== undefined && scene.clipPlane !== null);
-            defines.ALPHATEST = true;
-            defines.INSTANCES = useInstances;
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
             
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, useInstances);
-            defines._areAttributesDirty = false;
 
             // Get correct effect      
-            if (defines._isDirty) {
-                defines._isDirty = false;
+            if (defines.isDirty) {
+                defines.markAsProcessed();
                 scene.resetCachedMaterial();
 
                 // Fallbacks

+ 1 - 1
materialsLibrary/src/sky/babylon.skyMaterial.ts

@@ -10,7 +10,7 @@ module BABYLON {
 
         constructor() {
             super();
-            this._keys = Object.keys(this);
+            this.rebuild();
         }
     }
     

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

@@ -144,7 +144,7 @@ module BABYLON {
 
             // Lights
             if (scene.lightsEnabled && !this.disableLighting) {
-                needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, this.maxSimultaneousLights);
+                needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, true, this.maxSimultaneousLights);
             }
             
             // Textures

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

@@ -182,7 +182,7 @@ module BABYLON {
 
             // Lights
             if (scene.lightsEnabled && !this.disableLighting) {
-                needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, this.maxSimultaneousLights);
+                needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, true, this.maxSimultaneousLights);
             }
 
             // Attribs

+ 124 - 167
materialsLibrary/src/water/babylon.waterMaterial.ts

@@ -29,12 +29,14 @@ module BABYLON {
         }
     }
 	
-	export class WaterMaterial extends Material {
+	export class WaterMaterial extends PushMaterial {
 		/*
 		* Public members
 		*/
-        @serializeAsTexture()
-        public bumpTexture: BaseTexture;
+        @serializeAsTexture("bumpTexture")
+        private _bumpTexture: BaseTexture;
+        @expandToProperty("_markAllSubMeshesAsTexturesDirty")
+        public bumpTexture: BaseTexture;        
         
         @serializeAsColor3()
         public diffuseColor = new Color3(1, 1, 1);
@@ -45,11 +47,15 @@ module BABYLON {
         @serialize()
         public specularPower = 64;
         
-        @serialize()
-        public disableLighting = false;
+        @serialize("disableLighting")
+        private _disableLighting = false;
+        @expandToProperty("_markAllSubMeshesAsLightsDirty")
+        public disableLighting: boolean;
         
-        @serialize()
-        public maxSimultaneousLights = 4;
+        @serialize("maxSimultaneousLights")
+        private _maxSimultaneousLights = 4;
+        @expandToProperty("_markAllSubMeshesAsLightsDirty")
+        public maxSimultaneousLights: number;                   
         
         /**
         * @param {number}: Represents the wind force
@@ -74,18 +80,26 @@ module BABYLON {
         /**
          * @param {boolean}: Add a smaller moving bump to less steady waves.
          */
-        @serialize()
-        public bumpSuperimpose = false;
+        @serialize("bumpSuperimpose")
+        private _bumpSuperimpose = false;
+        @expandToProperty("_markAllSubMeshesAsMiscDirty")
+        public bumpSuperimpose: boolean;
+
         /**
          * @param {boolean}: Color refraction and reflection differently with .waterColor2 and .colorBlendFactor2. Non-linear (physically correct) fresnel.
          */
-        @serialize()
-        public fresnelSeparate = false;
+        @serialize("fresnelSeparate")
+        private _fresnelSeparate = false;
+        @expandToProperty("_markAllSubMeshesAsMiscDirty")
+        public fresnelSeparate: boolean;
+
         /**
          * @param {boolean}: bump Waves modify the reflection.
          */
-        @serialize()
-        public bumpAffectsReflection = false;
+        @serialize("bumpAffectsReflection")
+        private _bumpAffectsReflection = false;
+        @expandToProperty("_markAllSubMeshesAsMiscDirty")
+        public bumpAffectsReflection: boolean;        
 
         /**
         * @param {number}: The water color blended with the refraction (near)
@@ -134,9 +148,6 @@ module BABYLON {
         
         private _renderId: number;
 
-        private _defines = new WaterMaterialDefines();
-        private _cachedDefines = new WaterMaterialDefines();
-
         private _useLogarithmicDepth: boolean;
 
         /**
@@ -156,6 +167,7 @@ module BABYLON {
 
         public set useLogarithmicDepth(value: boolean) {
             this._useLogarithmicDepth = value && this.getScene().getEngine().getCaps().fragmentDepthSupported;
+            this._markAllSubMeshesAsMiscDirty();
         }
 
         // Get / Set
@@ -199,179 +211,120 @@ module BABYLON {
         public getAlphaTestTexture(): BaseTexture {
             return null;
         }
-        
-        private _checkCache(scene: Scene, mesh?: AbstractMesh, useInstances?: boolean): boolean {
-            if (!mesh) {
-                return true;
-            }
-
-            if (this._defines.INSTANCES !== useInstances) {
-                return false;
-            }
-
-            return false;
-        }
 		
-		public isReady(mesh?: AbstractMesh, useInstances?: boolean): boolean {
-			if (this.checkReadyOnlyOnce) {
-                if (this._wasPreviouslyReady) {
+		public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {
+            if (this.isFrozen) {
+                if (this._wasPreviouslyReady && subMesh.effect) {
                     return true;
                 }
             }
 
+            if (!subMesh._materialDefines) {
+                subMesh._materialDefines = new WaterMaterialDefines();
+            }
+
+            var defines = <WaterMaterialDefines>subMesh._materialDefines;
             var scene = this.getScene();
 
             if (!this.checkReadyOnEveryCall) {
                 if (this._renderId === scene.getRenderId()) {
-                    if (this._checkCache(scene, mesh, useInstances)) {
-                        return true;
-                    }
+                    return true;
                 }
             }
 
             var engine = scene.getEngine();
-            var needNormals = false;
-            var needUVs = false;
-
-            this._defines.reset();
 
             // Textures
-            if (scene.texturesEnabled) {
-                if (this.bumpTexture && StandardMaterial.BumpTextureEnabled) {
-                    if (!this.bumpTexture.isReady()) {
-                        return false;
-                    } else {
-                        needUVs = true;
-                        this._defines.BUMP = true;
+            if (defines._areTexturesDirty) {
+                defines._needUVs = false;
+                if (scene.texturesEnabled) {
+                    if (this.bumpTexture && StandardMaterial.BumpTextureEnabled) {
+                        if (!this.bumpTexture.isReady()) {
+                            return false;
+                        } else {
+                            defines._needUVs = true;
+                            defines.BUMP = true;
+                        }
+                    }
+                    
+                    if (StandardMaterial.ReflectionTextureEnabled) {
+                        defines.REFLECTION = true;
                     }
                 }
-                
-                if (StandardMaterial.ReflectionTextureEnabled) {
-                    this._defines.REFLECTION = true;
-                }
-            }
-
-            // Effect
-            if (scene.clipPlane) {
-                this._defines.CLIPPLANE = true;
-            }
-
-            if (engine.getAlphaTesting()) {
-                this._defines.ALPHATEST = true;
-            }
-
-            // Point size
-            if (this.pointsCloud || scene.forcePointsCloud) {
-                this._defines.POINTSIZE = true;
-            }
-
-            if (this.useLogarithmicDepth) {
-                this._defines.LOGARITHMICDEPTH = true;
-            }
-
-            if (this.fresnelSeparate) {
-                this._defines.FRESNELSEPARATE = true;
             }
 
-            if (this.bumpSuperimpose) {
-                this._defines.BUMPSUPERIMPOSE = true;
-            }
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
 
-            if (this.bumpAffectsReflection) {
-                this._defines.BUMPAFFECTSREFLECTION = true;
-            }
+            MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
 
-            // Fog
-            if (scene.fogEnabled && mesh && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE && this.fogEnabled) {
-                this._defines.FOG = true;
-            }
-            
-            // Lights
-            if (scene.lightsEnabled && !this.disableLighting) {
-                needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, this.maxSimultaneousLights);
-            }
-
-            // Attribs
-            if (mesh) {
-                if (needNormals && mesh.isVerticesDataPresent(VertexBuffer.NormalKind)) {
-                    this._defines.NORMAL = true;
+            if (defines._areMiscDirty) {
+                if (this._fresnelSeparate) {
+                    defines.FRESNELSEPARATE = true;
                 }
-                if (needUVs) {
-                    if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
-                        this._defines.UV1 = true;
-                    }
-                    if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind)) {
-                        this._defines.UV2 = true;
-                    }
-                }
-                if (mesh.useVertexColors && mesh.isVerticesDataPresent(VertexBuffer.ColorKind)) {
-                    this._defines.VERTEXCOLOR = true;
 
-                    if (mesh.hasVertexAlpha) {
-                        this._defines.VERTEXALPHA = true;
-                    }
-                }
-                
-                if (mesh.useBones && mesh.computeBonesUsingShaders) {
-                    this._defines.NUM_BONE_INFLUENCERS = mesh.numBoneInfluencers;
-                    this._defines.BonesPerMesh = (mesh.skeleton.bones.length + 1);
+                if (this._bumpSuperimpose) {
+                    defines.BUMPSUPERIMPOSE = true;
                 }
 
-                // Instances
-                if (useInstances) {
-                    this._defines.INSTANCES = true;
+                if (this._bumpAffectsReflection) {
+                    defines.BUMPAFFECTSREFLECTION = true;
                 }
             }
+           
+            // Lights
+            defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, true, this._maxSimultaneousLights, this._disableLighting);
+
+            // Attribs
+            MaterialHelper.PrepareDefinesForAttributes(mesh, defines, useInstances);
             
             this._mesh = mesh;
 
             // Get correct effect      
-            if (!this._defines.isEqual(this._cachedDefines)) {
-                this._defines.cloneTo(this._cachedDefines);
-
+            if (defines.isDirty) {
+                defines.markAsProcessed();
                 scene.resetCachedMaterial();
 
                 // Fallbacks
                 var fallbacks = new EffectFallbacks();             
-                if (this._defines.FOG) {
+                if (defines.FOG) {
                     fallbacks.addFallback(1, "FOG");
                 }
 
-                if (this._defines.LOGARITHMICDEPTH) {
+                if (defines.LOGARITHMICDEPTH) {
                     fallbacks.addFallback(0, "LOGARITHMICDEPTH");
                 }
 
-                MaterialHelper.HandleFallbacksForShadows(this._defines, fallbacks, this.maxSimultaneousLights);
+                MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
              
-                if (this._defines.NUM_BONE_INFLUENCERS > 0) {
+                if (defines.NUM_BONE_INFLUENCERS > 0) {
                     fallbacks.addCPUSkinningFallback(0, mesh);
                 }
 
                 //Attributes
                 var attribs = [VertexBuffer.PositionKind];
 
-                if (this._defines.NORMAL) {
+                if (defines.NORMAL) {
                     attribs.push(VertexBuffer.NormalKind);
                 }
 
-                if (this._defines.UV1) {
+                if (defines.UV1) {
                     attribs.push(VertexBuffer.UVKind);
                 }
 
-                if (this._defines.UV2) {
+                if (defines.UV2) {
                     attribs.push(VertexBuffer.UV2Kind);
                 }
 
-                if (this._defines.VERTEXCOLOR) {
+                if (defines.VERTEXCOLOR) {
                     attribs.push(VertexBuffer.ColorKind);
                 }
 
-                MaterialHelper.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
-                MaterialHelper.PrepareAttributesForInstances(attribs, this._defines);
+                MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
+                MaterialHelper.PrepareAttributesForInstances(attribs, defines);
 
                 // Legacy browser patch
                 var shaderName = "water";
-                var join = this._defines.toString();
+                var join = defines.toString();
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
                     "vFogInfos", "vFogColor", "pointSize",
                     "vNormalInfos", 
@@ -388,13 +341,13 @@ module BABYLON {
                     "refractionSampler", "reflectionSampler"
                 ];
                 
-                MaterialHelper.PrepareUniformsAndSamplersList(uniforms, samplers, this._defines, this.maxSimultaneousLights);
+                MaterialHelper.PrepareUniformsAndSamplersList(uniforms, samplers, defines, this.maxSimultaneousLights);
                 
-                this._effect = scene.getEngine().createEffect(shaderName,
+                subMesh.setEffect(scene.getEngine().createEffect(shaderName,
                     attribs, uniforms, samplers,
-                    join, fallbacks, this.onCompiled, this.onError, { maxSimultaneousLights: this.maxSimultaneousLights });
+                    join, fallbacks, this.onCompiled, this.onError, { maxSimultaneousLights: this.maxSimultaneousLights }), defines);
             }
-            if (!this._effect.isReady()) {
+            if (!subMesh.effect.isReady()) {
                 return false;
             }
 
@@ -404,83 +357,87 @@ module BABYLON {
             return true;
 		}
         
-        public bindOnlyWorldMatrix(world: Matrix): void {
-            this._effect.setMatrix("world", world);
-        }
-		
-		public bind(world: Matrix, mesh?: Mesh): void {
+		public bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void {
             var scene = this.getScene();
 
+            var defines = <WaterMaterialDefines>subMesh._materialDefines;
+            if (!defines) {
+                return;
+            }
+
+            var effect = subMesh.effect;
+            this._activeEffect = effect;
+
             // Matrices        
             this.bindOnlyWorldMatrix(world);
-            this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
+            this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
 
             // Bones
-            MaterialHelper.BindBonesParameters(mesh, this._effect);
+            MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
 
-            if (scene.getCachedMaterial() !== this) {
+            if (this._mustRebind(scene, effect)) {
                 // Textures        
                 if (this.bumpTexture && StandardMaterial.BumpTextureEnabled) {
-                    this._effect.setTexture("normalSampler", this.bumpTexture);
+                    this._activeEffect.setTexture("normalSampler", this.bumpTexture);
 
-                    this._effect.setFloat2("vNormalInfos", this.bumpTexture.coordinatesIndex, this.bumpTexture.level);
-                    this._effect.setMatrix("normalMatrix", this.bumpTexture.getTextureMatrix());
+                    this._activeEffect.setFloat2("vNormalInfos", this.bumpTexture.coordinatesIndex, this.bumpTexture.level);
+                    this._activeEffect.setMatrix("normalMatrix", this.bumpTexture.getTextureMatrix());
                 }
                 // Clip plane
-                MaterialHelper.BindClipPlane(this._effect, scene);
+                MaterialHelper.BindClipPlane(this._activeEffect, scene);
 
                 // Point size
                 if (this.pointsCloud) {
-                    this._effect.setFloat("pointSize", this.pointSize);
+                    this._activeEffect.setFloat("pointSize", this.pointSize);
                 }
 
-                this._effect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);                
+                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);                
             }
 
-            this._effect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
+            this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
             
-            if (this._defines.SPECULARTERM) {
-                this._effect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
+            if (defines.SPECULARTERM) {
+                this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
             }
 
             if (scene.lightsEnabled && !this.disableLighting) {
-                MaterialHelper.BindLights(scene, mesh, this._effect, this._defines, this.maxSimultaneousLights);
+                MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
             }
 
             // View
             if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
-                this._effect.setMatrix("view", scene.getViewMatrix());
+                this._activeEffect.setMatrix("view", scene.getViewMatrix());
             }
 
             // Fog
-            MaterialHelper.BindFogParameters(scene, mesh, this._effect);
+            MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
 
             // Log. depth
-            MaterialHelper.BindLogDepth(this._defines, this._effect, scene);
+            MaterialHelper.BindLogDepth(defines, this._activeEffect, scene);
 
             // Water
             if (StandardMaterial.ReflectionTextureEnabled) {
-                this._effect.setTexture("refractionSampler", this._refractionRTT);
-                this._effect.setTexture("reflectionSampler", this._reflectionRTT);
+                this._activeEffect.setTexture("refractionSampler", this._refractionRTT);
+                this._activeEffect.setTexture("reflectionSampler", this._reflectionRTT);
             }
             
 			var wrvp = this._mesh.getWorldMatrix().multiply(this._reflectionTransform).multiply(scene.getProjectionMatrix());
 			this._lastTime += scene.getEngine().getDeltaTime();
 			
-			this._effect.setMatrix("worldReflectionViewProjection", wrvp);
-			this._effect.setVector2("windDirection", this.windDirection);
-			this._effect.setFloat("waveLength", this.waveLength);
-			this._effect.setFloat("time", this._lastTime / 100000);
-			this._effect.setFloat("windForce", this.windForce);
-			this._effect.setFloat("waveHeight", this.waveHeight);
-            this._effect.setFloat("bumpHeight", this.bumpHeight);
-			this._effect.setColor4("waterColor", this.waterColor, 1.0);
-			this._effect.setFloat("colorBlendFactor", this.colorBlendFactor);
-            this._effect.setColor4("waterColor2", this.waterColor2, 1.0);
-            this._effect.setFloat("colorBlendFactor2", this.colorBlendFactor2);
-            this._effect.setFloat("waveSpeed", this.waveSpeed);
-
-            this._afterBind(mesh);
+			this._activeEffect.setMatrix("worldReflectionViewProjection", wrvp);
+			this._activeEffect.setVector2("windDirection", this.windDirection);
+			this._activeEffect.setFloat("waveLength", this.waveLength);
+			this._activeEffect.setFloat("time", this._lastTime / 100000);
+			this._activeEffect.setFloat("windForce", this.windForce);
+			this._activeEffect.setFloat("waveHeight", this.waveHeight);
+            this._activeEffect.setFloat("bumpHeight", this.bumpHeight);
+			this._activeEffect.setColor4("waterColor", this.waterColor, 1.0);
+			this._activeEffect.setFloat("colorBlendFactor", this.colorBlendFactor);
+            this._activeEffect.setColor4("waterColor2", this.waterColor2, 1.0);
+            this._activeEffect.setFloat("colorBlendFactor2", this.colorBlendFactor2);
+            this._activeEffect.setFloat("waveSpeed", this.waveSpeed);
+
+            this._afterBind(mesh, this._activeEffect);
 		}
 		
 		private _createRenderTargets(scene: Scene, renderTargetSize: Vector2): void {

+ 39 - 34
src/Materials/babylon.material.ts

@@ -1,9 +1,7 @@
 module BABYLON {
     export class MaterialDefines {
-        _keys: string[];
-        _isDirty = true;
-        _trackIsDirty = false;    
-
+        private _keys: string[];
+        private _isDirty = true;
         public _renderId: number;
 
         public _areLightsDirty = true;
@@ -15,27 +13,46 @@
         public _needNormals = false;
         public _needUVs = false;
 
-        constructor(trackIsDirty?: boolean) {
-            this._trackIsDirty = trackIsDirty;
+        public get isDirty(): boolean {
+            return this._isDirty;
+        }
+
+        public markAsProcessed() {
+            this._isDirty = false;
+            this._areAttributesDirty = false;
+            this._areTexturesDirty = false;
+            this._areFresnelDirty = false;
+            this._areLightsDirty = false;
+            this._areMiscDirty = false;
+        }
+
+        public markAsUnprocessed() {
+            this._isDirty = true;
+        }
+
+        public markAsLightDirty() {
+            this._areLightsDirty = true;
+            this._isDirty = true;
+        }
+
+        public markAsAttributesDirty() {
+            this._areAttributesDirty = true;
+            this._isDirty = true;
+        }
+        
+        public markAsTexturesDirty() {
+            this._areTexturesDirty = true;
+            this._isDirty = true;
         }
 
-        private _reBind(key: string): void {
-            this["_" + key] = this[key]; 
+        public markAsFresnelDirty() {
+            this._areFresnelDirty = true;
+            this._isDirty = true;
+        }
 
-            Object.defineProperty(this, key, {
-                get: function () {
-                    return this["_" + key];
-                },
-                set: function (value) {
-                    if (this["_" + key] === value) {
-                        return;
-                    }
-                    this["_" + key] = value;
-                    this._isDirty = true;
-                },
-                enumerable: true,
-                configurable: true
-            });
+        public markAsMiscDirty() {
+            this._areMiscDirty = true;
+            this._isDirty = true;
         }
 
         public rebuild() {
@@ -51,19 +68,7 @@
                 }
 
                 this._keys.push(key);
-
-                if (!this._trackIsDirty) {
-                    continue;
-                }
-            
-                if (Object.getOwnPropertyDescriptor(this, key).get) {
-                    continue;
-                }
-
-                this._reBind(key);
             }
-
-            this._isDirty = true;
         } 
 
         public isEqual(other: MaterialDefines): boolean {

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

@@ -1,6 +1,37 @@
 module BABYLON {
     export class MaterialHelper {
 
+        public static PrepareDefinesForMisc(mesh: AbstractMesh, scene: Scene, useLogarithmicDepth: boolean, pointsCloud, fogEnabled: boolean, defines: MaterialDefines): void {
+            if (defines._areMiscDirty) {
+                defines["LOGARITHMICDEPTH"] = useLogarithmicDepth;
+                defines["POINTSIZE"] = (pointsCloud || scene.forcePointsCloud);
+                defines["FOG"] = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE && fogEnabled);
+            }
+        }
+
+        public static PrepareDefinesForFrameBoundValues(scene: Scene, engine: Engine, defines: MaterialDefines, useInstances: boolean): void {
+            var changed = false;
+
+            if (defines["CLIPPLANE"] !== (scene.clipPlane !== undefined && scene.clipPlane !== null)) {
+                defines["CLIPPLANE"] = !defines["CLIPPLANE"];
+                changed = true;
+            }
+
+            if (defines["ALPHATEST"] !== engine.getAlphaTesting()) {
+                defines["ALPHATEST"] = !defines["ALPHATEST"];
+                changed = true;
+            }
+
+            if (defines["INSTANCES"] !== useInstances) {
+                defines["INSTANCES"] = useInstances;
+                changed = true;
+            }
+            
+            if (changed) {
+                defines.markAsUnprocessed();
+            }
+        }
+
         public static PrepareDefinesForAttributes(mesh: AbstractMesh, defines: MaterialDefines, useInstances: boolean): void {
             if (!defines._areAttributesDirty) {
                 return;
@@ -29,7 +60,7 @@
             }           
         }
 
-        public static PrepareDefinesForLights(scene: Scene, mesh: AbstractMesh, defines: MaterialDefines, maxSimultaneousLights = 4, disableLighting = false): boolean {
+        public static PrepareDefinesForLights(scene: Scene, mesh: AbstractMesh, defines: MaterialDefines, specularSupported: boolean, maxSimultaneousLights = 4, disableLighting = false): boolean {
             if (!defines._areLightsDirty) {
                 return defines._needNormals;
             }
@@ -70,7 +101,7 @@
                     defines[type] = true;
 
                     // Specular
-                    if (!light.specular.equalsFloats(0, 0, 0)) {
+                    if (specularSupported && !light.specular.equalsFloats(0, 0, 0)) {
                         specularEnabled = true;
                     }
 
@@ -157,6 +188,10 @@
         }
 
         public static HandleFallbacksForShadows(defines: MaterialDefines, fallbacks: EffectFallbacks, maxSimultaneousLights = 4): void {
+            if (!defines["SHADOWS"]) {
+                return;
+            }
+
             for (var lightIndex = 0; lightIndex < maxSimultaneousLights; lightIndex++) {
                 if (!defines["LIGHT" + lightIndex]) {
                     break;

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

@@ -644,7 +644,7 @@
             this._defines.reset();
 
             if (scene.lightsEnabled && !this.disableLighting) {
-                needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, this.maxSimultaneousLights) || needNormals;
+                needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, true, this.maxSimultaneousLights) || needNormals;
             }
 
             if (!this.checkReadyOnEveryCall) {

+ 5 - 5
src/Materials/babylon.pushMaterial.ts

@@ -88,23 +88,23 @@
         }
 
         protected _markAllSubMeshesAsTexturesDirty() {
-            this._markAllSubMeshesAsDirty(defines => defines._areTexturesDirty = true);
+            this._markAllSubMeshesAsDirty(defines => defines.markAsTexturesDirty());
         }
 
         protected _markAllSubMeshesAsFresnelDirty() {
-            this._markAllSubMeshesAsDirty(defines => defines._areFresnelDirty = true);
+            this._markAllSubMeshesAsDirty(defines => defines.markAsFresnelDirty());
         }
 
         protected _markAllSubMeshesAsLightsDirty() {
-            this._markAllSubMeshesAsDirty(defines => defines._areLightsDirty = true);
+            this._markAllSubMeshesAsDirty(defines => defines.markAsLightDirty());
         }
 
         protected _markAllSubMeshesAsAttributesDirty() {
-            this._markAllSubMeshesAsDirty(defines => defines._areAttributesDirty = true);
+            this._markAllSubMeshesAsDirty(defines => defines.markAsAttributesDirty());
         }
 
         protected _markAllSubMeshesAsMiscDirty() {
-            this._markAllSubMeshesAsDirty(defines => defines._areMiscDirty = true);
+            this._markAllSubMeshesAsDirty(defines => defines.markAsMiscDirty());
         }
     }
 } 

+ 12 - 26
src/Materials/babylon.standardMaterial.ts

@@ -61,7 +61,7 @@ module BABYLON {
         public CAMERACOLORCURVES = false;
 
         constructor() {
-            super(true);
+            super();
             this.rebuild();
         }
 
@@ -168,8 +168,7 @@ module BABYLON {
         @serialize("disableLighting")
         private _disableLighting = false;
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
-        public disableLighting: boolean;           
-          
+        public disableLighting: boolean;
 
         @serialize("useParallax")
         private _useParallax = false;
@@ -328,19 +327,19 @@ module BABYLON {
         }
 
         public needAlphaBlending(): boolean {
-            return (this.alpha < 1.0) || (this._opacityTexture != null) || this._shouldUseAlphaFromDiffuseTexture() || this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled;
+            return (this.alpha < 1.0) || (this._opacityTexture != null) || this._shouldUseAlphaFromDiffuseTexture() || this._opacityFresnelParameters && this._opacityFresnelParameters.isEnabled;
         }
 
         public needAlphaTesting(): boolean {
-            return this.diffuseTexture != null && this.diffuseTexture.hasAlpha;
+            return this._diffuseTexture != null && this._diffuseTexture.hasAlpha;
         }
 
         protected _shouldUseAlphaFromDiffuseTexture(): boolean {
-            return this.diffuseTexture != null && this.diffuseTexture.hasAlpha && this.useAlphaFromDiffuseTexture;
+            return this._diffuseTexture != null && this._diffuseTexture.hasAlpha && this._useAlphaFromDiffuseTexture;
         }
 
         public getAlphaTestTexture(): BaseTexture {
-            return this.diffuseTexture;
+            return this._diffuseTexture;
         }
 
         /**
@@ -368,8 +367,7 @@ module BABYLON {
             var engine = scene.getEngine();
 
             // Lights
-            defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, this._maxSimultaneousLights, this._disableLighting);
-            defines._areLightsDirty = false;
+            defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, true, this._maxSimultaneousLights, this._disableLighting);
 
             // Textures
             if (defines._areTexturesDirty) {
@@ -553,8 +551,6 @@ module BABYLON {
                 defines.LINKEMISSIVEWITHDIFFUSE = this._linkEmissiveWithDiffuse;       
 
                 defines.SPECULAROVERALPHA = this._useSpecularOverAlpha;
-         
-                defines._areTexturesDirty = false;
             } 
 
             if (defines._areFresnelDirty) {
@@ -584,36 +580,26 @@ module BABYLON {
                 } else {
                     defines.FRESNEL = false;
                 }
-
-                defines._areFresnelDirty = false;
             }
 
             // Misc.
-            if (defines._areMiscDirty) {
-                defines.LOGARITHMICDEPTH = this._useLogarithmicDepth;
-                defines.POINTSIZE = (this.pointsCloud || scene.forcePointsCloud);
-                defines.FOG = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE && this.fogEnabled);
-
-                defines._areMiscDirty = false;
-            }
+            MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
 
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, useInstances);
-            defines._areAttributesDirty = false;
 
             // Values that need to be evaluated on every frame
-            defines.CLIPPLANE = (scene.clipPlane !== undefined && scene.clipPlane !== null);
-            defines.ALPHATEST = engine.getAlphaTesting();
-            defines.INSTANCES = useInstances;
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
 
             if (scene._mirroredCameraPosition && defines.BUMP) {
                 defines.INVERTNORMALMAPX = !this.invertNormalMapX;
                 defines.INVERTNORMALMAPY = !this.invertNormalMapY;
+                defines.markAsUnprocessed();
             }
 
             // Get correct effect      
-            if (defines._isDirty) {
-                defines._isDirty = false;
+            if (defines.isDirty) {
+                defines.markAsProcessed();
                 scene.resetCachedMaterial();
 
                 // Fallbacks

+ 2 - 2
src/Mesh/babylon.abstractMesh.ts

@@ -435,11 +435,11 @@
         }
 
         public _markSubMeshesAsLightDirty() {
-            this._markSubMeshesAsDirty(defines => defines._areLightsDirty = true);
+            this._markSubMeshesAsDirty(defines => defines.markAsLightDirty());
         }
 
         public _markSubMeshesAsAttributesDirty() {
-            this._markSubMeshesAsDirty(defines => defines._areAttributesDirty = true);
+            this._markSubMeshesAsDirty(defines => defines.markAsAttributesDirty());
         }
 
         public _markSubMeshesAsMiscDirty() {

+ 1 - 1
src/babylon.engine.ts

@@ -2079,7 +2079,7 @@
         }
 
         public getAlphaTesting(): boolean {
-            return this._alphaTest;
+            return !!this._alphaTest;
         }
 
         // Textures