Benjamin Guignabert 8 年之前
父節點
當前提交
d22f0f15b0
共有 5 個文件被更改,包括 18833 次插入18841 次删除
  1. 9396 9397
      dist/preview release/babylon.d.ts
  2. 9396 9397
      dist/preview release/babylon.module.d.ts
  3. 29 20
      index.html
  4. 0 1
      src/Materials/babylon.standardMaterial.ts
  5. 12 26
      src/Materials/babylon.uniformBuffer.ts

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


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


+ 29 - 20
index.html

@@ -54,29 +54,38 @@
 					light.intensity = .5;
 
 					// Let's try our built-in 'sphere' shape. Params: name, subdivisions, size, scene
-					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+ 2*i;
-						sphere.material = new BABYLON.StandardMaterial("test");
-						sphere.material.diffuseColor = new BABYLON.Color3(Math.random(), Math.random(), Math.random());
-						sphere.material.emissiveColor = new BABYLON.Color3(Math.random(), Math.random(), Math.random());
-						sphere.material.specularColor = new BABYLON.Color3(Math.random(), Math.random(), Math.random());
-						window.sphere = sphere;
-						// sphere.material.diffuseTexture = new BABYLON.Texture("test.jpeg", scene);
-						var t = 0;
-							// sphere.material.freeze();
-						scene.registerAfterRender(function() {
-							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++;
-							if (t % 120 < 60) {
+					var squareSize = 20;
+					var spheres = []
+					for (var i = 0; i < squareSize; i++) {
+						for (var j = 0; j < squareSize; j++) {
+							for (var k = 0; k < 3; k++) {
+								var sphere = BABYLON.Mesh.CreateSphere("sphere", 16, 0.5, scene);
+
+								// Move the sphere upward 1/2 its height
+								sphere.position.z = - squareSize / 4 + j / 2;
+								sphere.position.x = - squareSize / 4 + i / 2;
+								sphere.position.y = - squareSize / 4 + k / 2;
+								sphere.material = new BABYLON.StandardMaterial("test");
+								sphere.material.diffuseColor = new BABYLON.Color3(Math.random(), Math.random(), Math.random());
+								sphere.material.emissiveColor = new BABYLON.Color3(0, 0, 0);
 								sphere.material.freeze();
-							} else {
-								sphere.material.unfreeze();
+								spheres.push(sphere);
 							}
-						})
+						}
 					}
+							var t = 0;
+							scene.registerAfterRender(function() {
+								for (var i = 0; i < spheres.length; i++) {
+									// spheres[i].material.diffuseColor = new BABYLON.Color3(Math.abs(Math.sin(t/100)), Math.abs(Math.cos(t/200)), Math.abs(Math.sin(t/500)));
+									// if (t % 120 < 60) {
+									// 	spheres[i].material.freeze();
+									// } else {
+									// 	spheres[i].material.unfreeze();
+									// }
+									
+								}
+									t++;
+							});
 
 					// Let's try our built-in 'ground' shape.  Params: name, width, depth, subdivisions, scene
 

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

@@ -748,7 +748,6 @@ module BABYLON {
             this._uniformBuffer.addUniform("vEmissiveInfos", 2);
             this._uniformBuffer.addUniform("vLightmapInfos", 2);
             this._uniformBuffer.addUniform("vSpecularInfos", 2);
-            // this._uniformBuffer.addUniform("fill", 2);
             this._uniformBuffer.addUniform("vBumpInfos", 3);
 
             this._uniformBuffer.addUniform("diffuseMatrix", 16);

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

@@ -41,29 +41,18 @@ module BABYLON {
             return this._buffer;
         }
 
-        // Methods
-        private _adaptSizeToLayout(size: number): number {
-            // std140 layout
-            var uniformSize;
-            if (size <= 2) {
-                uniformSize = size;
-            } else if (size == 2) {
-                uniformSize = Math.ceil(size / 4) * 4;
-            }
-
-            return uniformSize;
-        }
-
         private _fillAlignment(size: number) {
             // std140 layout
+            // This computation is really simple because we only use floats, vectors of 1, 2, 3, 4 components
+            // and 4x4 matrices
+            // TODO : change if other types are used
+            // See https://khronos.org/registry/OpenGL/specs/gl/glspec45.core.pdf#page=159
 
-            // TODO : Debug !!
-            
             var alignment;
             if (size <= 2) {
                 alignment = size;
-            } else if (size == 2) {
-                alignment = Math.ceil(size / 4) * 4;
+            } else {
+                alignment = 4;
             }
 
             if ((this._uniformLocationPointer % alignment) !== 0) {
@@ -88,9 +77,9 @@ module BABYLON {
             var data;
             if (size instanceof Array) {
                 data = size;
-                size = this._adaptSizeToLayout(data.length);
+                size = data.length;
             } else {
-                size = this._adaptSizeToLayout(<number>size);
+                size = <number>size;
                 data = [];
 
                 // Fill with zeros
@@ -100,11 +89,11 @@ module BABYLON {
             }
 
 
+            this._fillAlignment(<number>size);
             this._uniformNames.push(name);
-            this._uniformSizes.push(size);
-            this._fillAlignment(size);
+            this._uniformSizes.push(<number>size);
             this._uniformLocations.push(this._uniformLocationPointer);
-            this._uniformLocationPointer += size;
+            this._uniformLocationPointer += <number>size;
 
 
             for (var i = 0; i < size; i++) {
@@ -154,7 +143,6 @@ module BABYLON {
             } else {
                 this._buffer = this._engine.createUniformBuffer(data);
             }
-            console.log("ubo creation");
 
             this._needSync = false;
         } 
@@ -169,8 +157,6 @@ module BABYLON {
                 return;
             }
 
-            console.log("Effective Update");
-
             this._engine.updateUniformBuffer(this._buffer, this._data);
 
             this._needSync = false;
@@ -188,7 +174,7 @@ module BABYLON {
             }
 
             var location = this._uniformLocations[index];
-            var size = this._adaptSizeToLayout(data.length);
+            var size = data.length;
 
             if (size != this._uniformSizes[index]) {
                 Tools.Error("Wrong uniform size.");