Browse Source

Fixing IE shader

Deltakosh 12 years ago
parent
commit
db3c4126ec

+ 7 - 3
Babylon/Materials/babylon.material.js

@@ -47,15 +47,19 @@
     
     BABYLON.Material.prototype.unbind = function () {
     };
-
-    BABYLON.Material.prototype.dispose = function () {
+    
+    BABYLON.Material.prototype.baseDispose = function () {
         // Remove from scene
         var index = this._scene.materials.indexOf(this);
         this._scene.materials.splice(index, 1);
-        
+
         // Callback
         if (this.onDispose) {
             this.onDispose();
         }
     };
+
+    BABYLON.Material.prototype.dispose = function () {
+        this.baseDispose();
+    };
 })();

+ 5 - 8
Babylon/Materials/babylon.standardMaterial.js

@@ -340,6 +340,10 @@
         if (this.specularTexture && this.specularTexture.animations && this.specularTexture.animations.length > 0) {
             results.push(this.specularTexture);
         }
+        
+        if (this.bumpTexture && this.bumpTexture.animations && this.bumpTexture.animations.length > 0) {
+            results.push(this.bumpTexture);
+        }
 
         return results;
     };
@@ -373,13 +377,6 @@
             this.bumpTexture.dispose();
         }
 
-        // Remove from scene
-        var index = this._scene.materials.indexOf(this);
-        this._scene.materials.splice(index, 1);
-
-        // Callback
-        if (this.onDispose) {
-            this.onDispose();
-        }
+        this.baseDispose();
     };
 })();

+ 60 - 8
Babylon/Mesh/babylon.mesh.js

@@ -224,13 +224,20 @@
         return new BABYLON.SubMesh(0, 0, this._totalVertices, 0, this._indices.length, this);
     };
 
-    BABYLON.Mesh.prototype.setVertices = function (vertices, uvCount) {
+    BABYLON.Mesh.prototype.setVertices = function (vertices, uvCount, updatable) {
         if (this._vertexBuffer) {
             this._scene.getEngine()._releaseBuffer(this._vertexBuffer);
         }
 
         this._uvCount = uvCount;
-        this._vertexBuffer = this._scene.getEngine().createVertexBuffer(vertices);
+        
+        if (updatable) {
+            this._vertexBuffer = this._scene.getEngine().createDynamicVertexBuffer(vertices.length * 4);
+            this._scene.getEngine().updateDynamicVertexBuffer(this._vertexBuffer, vertices);
+        } else {
+            this._vertexBuffer = this._scene.getEngine().createVertexBuffer(vertices);
+        }
+        
         this._vertices = vertices;
 
         this._totalVertices = vertices.length / this.getFloatVertexStrideSize();
@@ -241,6 +248,11 @@
         this._positions = null;
     };
 
+    BABYLON.Mesh.prototype.updateVertices = function(vertices) {
+        var engine = this._scene.getEngine();
+        engine.updateDynamicVertexBuffer(this._vertexBuffer, vertices);
+    };
+
     BABYLON.Mesh.prototype.setIndices = function (indices) {
         if (this._indexBuffer) {
             this._scene.getEngine()._releaseBuffer(this._indexBuffer);
@@ -576,7 +588,7 @@
     };
 
     // Statics
-    BABYLON.Mesh.CreateBox = function (name, size, scene) {
+    BABYLON.Mesh.CreateBox = function (name, size, scene, updatable) {
         var box = new BABYLON.Mesh(name, [3, 3, 2], scene);
 
         var normals = [
@@ -623,13 +635,13 @@
             vertices.push(vertex.x, vertex.y, vertex.z, normal.x, normal.y, normal.z, 1.0, 0.0);
         }
 
-        box.setVertices(vertices, 1);
+        box.setVertices(vertices, 1, updatable);
         box.setIndices(indices);
 
         return box;
     };
 
-    BABYLON.Mesh.CreateSphere = function (name, segments, diameter, scene) {
+    BABYLON.Mesh.CreateSphere = function (name, segments, diameter, scene, updatable) {
         var sphere = new BABYLON.Mesh(name, [3, 3, 2], scene);
 
         var radius = diameter / 2;
@@ -674,14 +686,14 @@
             }
         }
 
-        sphere.setVertices(vertices, 1);
+        sphere.setVertices(vertices, 1, updatable);
         sphere.setIndices(indices);
 
         return sphere;
     };
 
     // Plane
-    BABYLON.Mesh.CreatePlane = function (name, size, scene) {
+    BABYLON.Mesh.CreatePlane = function (name, size, scene, updatable) {
         var plane = new BABYLON.Mesh(name, [3, 3, 2], scene);
 
         var indices = [];
@@ -703,9 +715,49 @@
         indices.push(2);
         indices.push(3);
 
-        plane.setVertices(vertices, 1);
+        plane.setVertices(vertices, 1, updatable);
         plane.setIndices(indices);
 
         return plane;
     };
+    
+    BABYLON.Mesh.CreateGround = function(name, width, height, subdivisions, scene, updatable) {
+        var ground = new BABYLON.Mesh(name, [3, 3, 2], scene);
+
+        var indices = [];
+        var vertices = [];
+        var row, col;
+
+        for (row = 0; row <= subdivisions; row++)
+        {
+            for (col = 0; col <= subdivisions; col++)
+            {
+                var position = new BABYLON.Vector3((col * width) / subdivisions - (width / 2.0), 0, ((subdivisions - row) * height) / subdivisions - (height / 2.0));
+                var normal = new BABYLON.Vector3(0, 1, 0);
+
+                vertices.push(  position.x, position.y, position.z, 
+                                normal.x, normal.y, normal.y,
+                                col / subdivisions, row / subdivisions);
+            }
+        }
+
+        for (row = 0; row < subdivisions; row++)
+        {
+            for (col = 0; col < subdivisions; col++)
+            {
+                indices.push(col + 1 + (row + 1) * (subdivisions + 1));
+                indices.push(col + 1 + row * (subdivisions + 1));
+                indices.push(col + row * (subdivisions + 1));
+
+                indices.push(col + (row + 1) * (subdivisions + 1));
+                indices.push(col + 1 + (row + 1) * (subdivisions + 1));
+                indices.push(col + row * (subdivisions + 1));
+            }
+        }
+        
+        ground.setVertices(vertices, 1, updatable);
+        ground.setIndices(indices);
+
+        return ground;
+    }
 })();

+ 2 - 2
Babylon/Shaders/iedefault.fragment.fx

@@ -118,8 +118,8 @@ void main(void) {
 	float specComp = dot(normalize(vNormalW), angleW);
 	specComp = pow(specComp, vSpecularColor.a);
 
-	specularBase += ndl * vLightDiffuse0;
-	diffuseBase += specComp * vLightSpecular0;
+	diffuseBase += ndl * vLightDiffuse0;
+	specularBase += specComp * vLightSpecular0;
 #endif
 
 	// Reflection

+ 1 - 1
Babylon/babylon.engine.js

@@ -250,8 +250,8 @@
 
                 if (order >= 0) {
                     this._gl.vertexAttribPointer(order, vertexDeclaration[index], this._gl.FLOAT, false, vertexStrideSize, offset);
-                    offset += vertexDeclaration[index] * 4;
                 }
+                offset += vertexDeclaration[index] * 4;
             }
         }
 

+ 36 - 14
Babylon/babylon.scene.js

@@ -21,6 +21,8 @@
 
         this._onReadyCallbacks = [];
         this._pendingData = [];
+
+        this._onBeforeRenderCallbacks = [];
         
         // Fog
         this.fogMode = BABYLON.Scene.FOGMODE_NONE;
@@ -138,6 +140,18 @@
         }
         this._onReadyCallbacks.push(func);
     };
+    
+    BABYLON.Scene.prototype.registerBeforeRender = function (func) {
+        this._onBeforeRenderCallbacks.push(func);
+    };
+    
+    BABYLON.Scene.prototype.unregisterBeforeRender = function (func) {
+        var index = this._onBeforeRenderCallbacks.indexOf(func);
+
+        if (index > -1) {
+            this._onBeforeRenderCallbacks.splice(index, 1);
+        }
+    };
 
     BABYLON.Scene.prototype._addPendingData = function (data) {
         this._pendingData.push(data);
@@ -412,6 +426,10 @@
         if (this.beforeRender) {
             this.beforeRender();
         }
+        
+        for (var callbackIndex = 0; callbackIndex < this._onBeforeRenderCallbacks.length; callbackIndex++) {
+            this._onBeforeRenderCallbacks[callbackIndex]();
+        }
 
         // Camera
         if (!this.activeCamera)
@@ -446,29 +464,33 @@
         engine.clear(this.clearColor, this.autoClear, true);
 
         // Backgrounds
-        engine.setDepthBuffer(false);
-        var layerIndex;
-        var layer;
-        for (layerIndex = 0; layerIndex < this.layers.length; layerIndex++) {
-            layer = this.layers[layerIndex];
-            if (layer.isBackground) {
-                layer.render();
+        if (this.layers.length) {
+            engine.setDepthBuffer(false);
+            var layerIndex;
+            var layer;
+            for (layerIndex = 0; layerIndex < this.layers.length; layerIndex++) {
+                layer = this.layers[layerIndex];
+                if (layer.isBackground) {
+                    layer.render();
+                }
             }
+            engine.setDepthBuffer(true);
         }
-        engine.setDepthBuffer(true);
 
         // Render
         this._localRender(this._opaqueSubMeshes, this._alphaTestSubMeshes, this._transparentSubMeshes);
 
         // Foregrounds
-        engine.setDepthBuffer(false);
-        for (layerIndex = 0; layerIndex < this.layers.length; layerIndex++) {
-            layer = this.layers[layerIndex];
-            if (!layer.isBackground) {
-                layer.render();
+        if (this.layers.length) {
+            engine.setDepthBuffer(false);
+            for (layerIndex = 0; layerIndex < this.layers.length; layerIndex++) {
+                layer = this.layers[layerIndex];
+                if (!layer.isBackground) {
+                    layer.render();
+                }
             }
+            engine.setDepthBuffer(true);
         }
-        engine.setDepthBuffer(true);
 
         this._renderDuration = new Date() - beforeRenderDate;
 

File diff suppressed because it is too large
+ 3 - 3
babylon.1.0.4.js