瀏覽代碼

optimisation in binding

Benjamin Guignabert 8 年之前
父節點
當前提交
37abe5ea4b
共有 5 個文件被更改,包括 4579 次插入4558 次删除
  1. 2272 2269
      dist/preview release/babylon.d.ts
  2. 2272 2269
      dist/preview release/babylon.module.d.ts
  3. 9 9
      index.html
  4. 12 10
      src/Materials/babylon.standardMaterial.ts
  5. 14 1
      src/Materials/babylon.uniformBuffer.ts

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


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


+ 9 - 9
index.html

@@ -54,22 +54,22 @@
 					light.intensity = .5;
 
 					// Let's try our built-in 'sphere' shape. Params: name, subdivisions, size, scene
-					for (var i = 0; i < 500; i++) {
+					for (var i = 0; i < 1; i++) {
 						var sphere = BABYLON.Mesh.CreateSphere("sphere1", 16, 2, scene);
 
 						// Move the sphere upward 1/2 its height
-						sphere.position.y = 1+i / 500;
+						// sphere.position.y = 1+i / 500;
 						sphere.material = new BABYLON.StandardMaterial("test");
 						sphere.material.diffuseColor = new BABYLON.Color3(Math.random(), Math.random(), Math.random());
-						window.sphere = sphere;
-						sphere.material.diffuseTexture = new BABYLON.Texture("test.jpeg", scene);
-						// sphere.material.freeze();
-						var t = 0;/*
+						// window.sphere = sphere;
+						// sphere.material.diffuseTexture = new BABYLON.Texture("test.jpeg", scene);
+						var t = 0;
+							sphere.material.freeze();
 						scene.registerAfterRender(function() {
-							sphere.material.specularColor = new BABYLON.Color3(0, 0, Math.sin(t/100));
-							sphere.material.diffuseColor = new BABYLON.Color3(Math.abs(Math.sin(t/100)), Math.abs(Math.cos(t/200)), Math.abs(Math.sin(t/50)));
+							// sphere.material.specularColor = new BABYLON.Color3(0, 0, Math.sin(t/100));
+							// sphere.material.diffuseColor = new BABYLON.Color3(Math.abs(Math.sin(t/100)), Math.abs(Math.cos(t/200)), Math.abs(Math.sin(t/50)));
 							t++;
-						})*/
+						})
 					}
 
 					// Let's try our built-in 'ground' shape.  Params: name, width, depth, subdivisions, scene

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

@@ -743,7 +743,6 @@ module BABYLON {
 
             this._uniformBuffer.addUniform("vEmissiveColor", 3);
 
-            this._uniformBuffer.create();
         }
 
         public unbind(): void {
@@ -768,13 +767,10 @@ module BABYLON {
             // Matrices        
             this.bindOnlyWorldMatrix(world);
 
-            // Bones
+            // Bonesf
             MaterialHelper.BindBonesParameters(mesh, this._effect);
-
-            if (scene.getCachedMaterial() !== this) {
-                this._effect.bindUniformBuffer(this._uniformBuffer.getBuffer());
-
-                this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
+            
+            if (!this.isFrozen || !this._uniformBuffer.isSync) {
 
                 if (StandardMaterial.FresnelEnabled) {
                     // Fresnel
@@ -909,9 +905,8 @@ module BABYLON {
                 // this._effect.setColor3("vEmissiveColor", this.emissiveColor);
                 this._uniformBuffer.updateColor3("vEmissiveColor", this.emissiveColor);
 
-            }
+                // TODO : this depends on mesh
 
-            if (scene.getCachedMaterial() !== this || !this.isFrozen) {
                 // Diffuse
                 // this._effect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
                 this._uniformBuffer.updateColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
@@ -936,9 +931,16 @@ module BABYLON {
                 if (this.cameraColorCurves) {
                     ColorCurves.Bind(this.cameraColorCurves, this._effect);
                 }
-            }
 
+            }
             this._uniformBuffer.update();
+            
+            if (scene.getCachedMaterial() !== this) {
+                this._effect.bindUniformBuffer(this._uniformBuffer.getBuffer());
+
+                this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
+            }
+
             super.bind(world, mesh);
         }
 

+ 14 - 1
src/Materials/babylon.uniformBuffer.ts

@@ -24,6 +24,10 @@ module BABYLON {
             this._needSync = false;
         }
 
+        public get isSync(): boolean {
+            return this._needSync;
+        }
+
         // Properties
         public isDynamic(): boolean {
             return this._dynamic;
@@ -78,6 +82,15 @@ module BABYLON {
             this._needSync = true;
         }
 
+        public addFloat2(name: string, x: number, y: number) {
+            var temp = [x, y];
+            this.addUniform(name, temp);
+        }
+        public addMatrix(name: string, mat: Matrix) {
+            this.addUniform(name, Array.prototype.slice.call(mat.toArray()));
+        }
+
+
         public addColor3(name: string, color: Color3) {
             var temp = [];
             color.toArray(temp);
@@ -110,7 +123,7 @@ module BABYLON {
                 this._buffer = this._engine.createUniformBuffer(data);
             }
             console.log("ubo creation");
-            
+
             this._needSync = false;
         }