Jelajahi Sumber

simplified some light code

Benjamin Guignabert 8 tahun lalu
induk
melakukan
1e50ce94df

File diff ditekan karena terlalu besar
+ 5842 - 5842
dist/preview release/babylon.d.ts


File diff ditekan karena terlalu besar
+ 5842 - 5842
dist/preview release/babylon.module.d.ts


+ 3 - 1
index.html

@@ -66,10 +66,12 @@
 								sphere.position.x = - squareSize / 4 + i / 2;
 								sphere.position.x = - squareSize / 4 + i / 2;
 								sphere.position.y = - squareSize / 4 + k / 2;
 								sphere.position.y = - squareSize / 4 + k / 2;
 								sphere.material = new BABYLON.StandardMaterial("test");
 								sphere.material = new BABYLON.StandardMaterial("test");
+								sphere.material.diffuseTexture = new BABYLON.Texture("test.jpeg", scene);
+								sphere.material.bumpTexture = new BABYLON.Texture("test.jpeg", scene);
 								sphere.material.diffuseColor = new BABYLON.Color3(Math.random(), Math.random(), Math.random());
 								sphere.material.diffuseColor = new BABYLON.Color3(Math.random(), Math.random(), Math.random());
 								sphere.material.specularColor = new BABYLON.Color3(Math.random() < 0.8 ? 0 : 1, Math.random() < 0.8 ? 0 : 1, Math.random() < 0.8 ? 0 : 1);
 								sphere.material.specularColor = new BABYLON.Color3(Math.random() < 0.8 ? 0 : 1, Math.random() < 0.8 ? 0 : 1, Math.random() < 0.8 ? 0 : 1);
 								sphere.material.emissiveColor = new BABYLON.Color3(0, 0, 0);
 								sphere.material.emissiveColor = new BABYLON.Color3(0, 0, 0);
-								// sphere.material.freeze();
+								sphere.material.freeze();
 								sphere.freezeWorldMatrix();
 								sphere.freezeWorldMatrix();
 								spheres.push(sphere);
 								spheres.push(sphere);
 							}
 							}

+ 3 - 3
src/Lights/babylon.directionalLight.ts

@@ -173,16 +173,16 @@ module BABYLON {
          * Sets the passed Effect object with the DirectionalLight transformed position (or position if not parented) and the passed name.  
          * Sets the passed Effect object with the DirectionalLight transformed position (or position if not parented) and the passed name.  
          * Returns the DirectionalLight.  
          * Returns the DirectionalLight.  
          */
          */
-        public transferToEffect(effect: Effect, directionUniformName: string): DirectionalLight {
+        public transferToEffect(effect: Effect): DirectionalLight {
             if (this.parent && this.parent.getWorldMatrix) {
             if (this.parent && this.parent.getWorldMatrix) {
                 if (!this._transformedDirection) {
                 if (!this._transformedDirection) {
                     this._transformedDirection = Vector3.Zero();
                     this._transformedDirection = Vector3.Zero();
                 }
                 }
                 Vector3.TransformNormalToRef(this.direction, this.parent.getWorldMatrix(), this._transformedDirection);
                 Vector3.TransformNormalToRef(this.direction, this.parent.getWorldMatrix(), this._transformedDirection);
-                this._uniformBuffer.updateFloat4(directionUniformName, this._transformedDirection.x, this._transformedDirection.y, this._transformedDirection.z, 1);
+                this._uniformBuffer.updateFloat4("vLightData", this._transformedDirection.x, this._transformedDirection.y, this._transformedDirection.z, 1);
                 return this;
                 return this;
             }
             }
-            this._uniformBuffer.updateFloat4(directionUniformName, this.direction.x, this.direction.y, this.direction.z, 1);
+            this._uniformBuffer.updateFloat4("vLightData", this.direction.x, this.direction.y, this.direction.z, 1);
             return this;
             return this;
         }
         }
 
 

+ 3 - 3
src/Lights/babylon.hemisphericLight.ts

@@ -50,14 +50,14 @@
          * Sets the passed Effect object with the HemisphericLight normalized direction and color and the passed name (string).  
          * Sets the passed Effect object with the HemisphericLight normalized direction and color and the passed name (string).  
          * Returns the HemisphericLight.  
          * Returns the HemisphericLight.  
          */
          */
-        public transferToEffect(effect: Effect, directionUniformName: string, groundColorUniformName: string): HemisphericLight {
+        public transferToEffect(effect: Effect): HemisphericLight {
             var normalizeDirection = Vector3.Normalize(this.direction);
             var normalizeDirection = Vector3.Normalize(this.direction);
-            this._uniformBuffer.updateFloat4(directionUniformName,
+            this._uniformBuffer.updateFloat4("vLightData",
                 normalizeDirection.x,
                 normalizeDirection.x,
                 normalizeDirection.y,
                 normalizeDirection.y,
                 normalizeDirection.z,
                 normalizeDirection.z,
                 0.0);
                 0.0);
-            this._uniformBuffer.updateColor3(groundColorUniformName, this.groundColor.scale(this.intensity));
+            this._uniformBuffer.updateColor3("vLightGround", this.groundColor.scale(this.intensity));
             return this;
             return this;
         }
         }
 
 

+ 3 - 3
src/Lights/babylon.pointLight.ts

@@ -68,11 +68,11 @@
          * Sets the passed Effect "effect" with the PointLight transformed position (or position, if none) and passed name (string).  
          * Sets the passed Effect "effect" with the PointLight transformed position (or position, if none) and passed name (string).  
          * Returns the PointLight.  
          * Returns the PointLight.  
          */
          */
-        public transferToEffect(effect: Effect, positionUniformName: string): PointLight {
+        public transferToEffect(effect: Effect): PointLight {
             if (this.parent && this.parent.getWorldMatrix) {
             if (this.parent && this.parent.getWorldMatrix) {
                 this.computeTransformedPosition();
                 this.computeTransformedPosition();
 
 
-                this._uniformBuffer.updateFloat4(positionUniformName,
+                this._uniformBuffer.updateFloat4("vLightData",
                     this.transformedPosition.x,
                     this.transformedPosition.x,
                     this.transformedPosition.y,
                     this.transformedPosition.y,
                     this.transformedPosition.z,
                     this.transformedPosition.z,
@@ -80,7 +80,7 @@
                 return this;
                 return this;
             }
             }
 
 
-            this._uniformBuffer.updateFloat4(positionUniformName, this.position.x, this.position.y, this.position.z, 0);
+            this._uniformBuffer.updateFloat4("vLightData", this.position.x, this.position.y, this.position.z, 0);
             return this;
             return this;
         }
         }
         /**
         /**

+ 4 - 4
src/Lights/babylon.spotLight.ts

@@ -128,7 +128,7 @@
          * Sets the passed Effect object with the SpotLight transfomed position (or position if not parented) and normalized direction.  
          * Sets the passed Effect object with the SpotLight transfomed position (or position if not parented) and normalized direction.  
          * Return the SpotLight.   
          * Return the SpotLight.   
          */
          */
-        public transferToEffect(effect: Effect, positionUniformName: string, directionUniformName: string): SpotLight {
+        public transferToEffect(effect: Effect): SpotLight {
             var normalizeDirection;
             var normalizeDirection;
 
 
             if (this.parent && this.parent.getWorldMatrix) {
             if (this.parent && this.parent.getWorldMatrix) {
@@ -140,7 +140,7 @@
                 
                 
                 Vector3.TransformNormalToRef(this.direction, this.parent.getWorldMatrix(), this._transformedDirection);
                 Vector3.TransformNormalToRef(this.direction, this.parent.getWorldMatrix(), this._transformedDirection);
 
 
-                this._uniformBuffer.updateFloat4(positionUniformName,
+                this._uniformBuffer.updateFloat4("vLightData",
                     this.transformedPosition.x,
                     this.transformedPosition.x,
                     this.transformedPosition.y,
                     this.transformedPosition.y,
                     this.transformedPosition.z,
                     this.transformedPosition.z,
@@ -148,7 +148,7 @@
 
 
                 normalizeDirection = Vector3.Normalize(this._transformedDirection);
                 normalizeDirection = Vector3.Normalize(this._transformedDirection);
             } else {
             } else {
-                this._uniformBuffer.updateFloat4(positionUniformName,
+                this._uniformBuffer.updateFloat4("vLightData",
                     this.position.x,
                     this.position.x,
                     this.position.y,
                     this.position.y,
                     this.position.z,
                     this.position.z,
@@ -157,7 +157,7 @@
                 normalizeDirection = Vector3.Normalize(this.direction);
                 normalizeDirection = Vector3.Normalize(this.direction);
             }
             }
 
 
-            this._uniformBuffer.updateFloat4(directionUniformName,
+            this._uniformBuffer.updateFloat4("vLightDirection",
                 normalizeDirection.x,
                 normalizeDirection.x,
                 normalizeDirection.y,
                 normalizeDirection.y,
                 normalizeDirection.z,
                 normalizeDirection.z,

+ 1 - 13
src/Materials/babylon.materialHelper.ts

@@ -260,19 +260,7 @@
         }
         }
 
 
         public static BindLightProperties(light: Light, effect: Effect, lightIndex: number): void {
         public static BindLightProperties(light: Light, effect: Effect, lightIndex: number): void {
-            if (light instanceof PointLight) {
-                // Point Light
-                light.transferToEffect(effect, "vLightData");
-            } else if (light instanceof DirectionalLight) {
-                // Directional Light
-                light.transferToEffect(effect, "vLightData");
-            } else if (light instanceof SpotLight) {
-                // Spot Light
-                light.transferToEffect(effect, "vLightData", "vLightDirection");
-            } else if (light instanceof HemisphericLight) {
-                // Hemispheric Light
-                light.transferToEffect(effect, "vLightData", "vLightGround");
-            }
+                light.transferToEffect(effect);
         }
         }
 
 
         public static BindLights(scene: Scene, mesh: AbstractMesh, effect: Effect, defines: MaterialDefines, maxSimultaneousLights = 4) {
         public static BindLights(scene: Scene, mesh: AbstractMesh, effect: Effect, defines: MaterialDefines, maxSimultaneousLights = 4) {