Benjamin Guignabert 8 лет назад
Родитель
Сommit
b59af4f12e

Разница между файлами не показана из-за своего большого размера
+ 2595 - 2594
dist/preview release/babylon.d.ts


Разница между файлами не показана из-за своего большого размера
+ 2595 - 2594
dist/preview release/babylon.module.d.ts


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

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

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

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

+ 1 - 1
src/Lights/babylon.light.ts

@@ -207,7 +207,7 @@
             return Vector3.Zero();
         }
 
-        public transferToEffect(effect: Effect, uniformName0?: string, uniformName1?: string): void {
+        public transferToEffect(effect: Effect, lightIndex: number): void {
         }
 
         public _getWorldMatrix(): Matrix {

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

@@ -69,11 +69,13 @@
          * Sets the passed Effect "effect" with the PointLight transformed position (or position, if none) and passed name (string).  
          * Returns the PointLight.  
          */
-        public transferToEffect(effect: Effect): PointLight {
+        public transferToEffect(effect: Effect, lightIndex: number): PointLight {
+            var useUbo = this._uniformBuffer.useUbo;
+
             if (this.parent && this.parent.getWorldMatrix) {
                 this.computeTransformedPosition();
 
-                this._uniformBuffer.updateFloat4("vLightData",
+                this._uniformBuffer.updateFloat4(useUbo ? "vLightData" : "vLightData" + lightIndex,
                     this.transformedPosition.x,
                     this.transformedPosition.y,
                     this.transformedPosition.z,
@@ -81,7 +83,7 @@
                 return this;
             }
 
-            this._uniformBuffer.updateFloat4("vLightData", this.position.x, this.position.y, this.position.z, 0);
+            this._uniformBuffer.updateFloat4(useUbo ? "vLightData" : "vLightData" + lightIndex, this.position.x, this.position.y, this.position.z, 0);
             return this;
         }
         /**

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

@@ -129,7 +129,9 @@
          * Sets the passed Effect object with the SpotLight transfomed position (or position if not parented) and normalized direction.  
          * Return the SpotLight.   
          */
-        public transferToEffect(effect: Effect): SpotLight {
+        public transferToEffect(effect: Effect, lightIndex: number): SpotLight {
+            var useUbo = this._uniformBuffer.useUbo;
+
             var normalizeDirection;
 
             if (this.parent && this.parent.getWorldMatrix) {
@@ -141,7 +143,7 @@
                 
                 Vector3.TransformNormalToRef(this.direction, this.parent.getWorldMatrix(), this._transformedDirection);
 
-                this._uniformBuffer.updateFloat4("vLightData",
+                this._uniformBuffer.updateFloat4(useUbo ? "vLightData" : "vLightData" + lightIndex,
                     this.transformedPosition.x,
                     this.transformedPosition.y,
                     this.transformedPosition.z,
@@ -149,7 +151,7 @@
 
                 normalizeDirection = Vector3.Normalize(this._transformedDirection);
             } else {
-                this._uniformBuffer.updateFloat4("vLightData",
+                this._uniformBuffer.updateFloat4(useUbo ? "vLightData" : "vLightData" + lightIndex,
                     this.position.x,
                     this.position.y,
                     this.position.z,
@@ -158,7 +160,7 @@
                 normalizeDirection = Vector3.Normalize(this.direction);
             }
 
-            this._uniformBuffer.updateFloat4("vLightDirection",
+            this._uniformBuffer.updateFloat4(useUbo ? "vLightDirection" : "vLightDirection" + lightIndex,
                 normalizeDirection.x,
                 normalizeDirection.y,
                 normalizeDirection.z,

+ 12 - 0
src/Materials/babylon.effect.ts

@@ -378,9 +378,21 @@
                             }
 
                             for (var i = minIndex; i < maxIndex; i++) {
+                                if (this._engine.webGLVersion === 1) {
+                                    // Ubo replacement
+                                    sourceIncludeContent = sourceIncludeContent.replace(/light\{X\}.(\w*)/g, (str: string, p1: string) => {
+                                        return p1 + "{X}";
+                                    });
+                                }
                                 includeContent += sourceIncludeContent.replace(/\{X\}/g, i) + "\n";
                             }
                         } else {
+                            if (this._engine.webGLVersion === 1) {
+                                // Ubo replacement
+                                sourceIncludeContent = sourceIncludeContent.replace(/light\{X\}.(\w*)/g, (str: string, p1: string) => {
+                                    return p1 + "{X}";
+                                });
+                            }
                             includeContent = includeContent.replace(/\{X\}/g, indexString);
                         }
                     }

+ 12 - 4
src/Materials/babylon.materialHelper.ts

@@ -197,7 +197,13 @@
                 }
 
                 uniformsList.push(
-                    "lightMatrix" + lightIndex
+                    "vLightData" + lightIndex,
+                    "vLightDiffuse" + lightIndex,
+                    "vLightSpecular" + lightIndex,
+                    "vLightDirection" + lightIndex,
+                    "vLightGround" + lightIndex,
+                    "lightMatrix" + lightIndex,
+                    "shadowsInfo" + lightIndex
                 );
                 uniformBuffersList.push("Light" + lightIndex);
 
@@ -300,7 +306,7 @@
         }
 
         public static BindLightProperties(light: Light, effect: Effect, lightIndex: number): void {
-                light.transferToEffect(effect);
+            light.transferToEffect(effect, lightIndex);
         }
 
         public static BindLights(scene: Scene, mesh: AbstractMesh, effect: Effect, defines: MaterialDefines, maxSimultaneousLights = 4) {
@@ -308,15 +314,17 @@
             var depthValuesAlreadySet = false;
 
             for (var light of mesh._lightSources) {
+                var useUbo = light._uniformBuffer.useUbo;
+
                 light._uniformBuffer.bindToEffect(effect, "Light" + lightIndex);
 
                 MaterialHelper.BindLightProperties(light, effect, lightIndex);
 
                 light.diffuse.scaleToRef(light.intensity, Tmp.Color3[0]);
-                light._uniformBuffer.updateColor4("vLightDiffuse", Tmp.Color3[0], light.range);
+                light._uniformBuffer.updateColor4(useUbo ? "vLightDiffuse" : "vLightDiffuse" + lightIndex, Tmp.Color3[0], light.range);
                 if (defines["SPECULARTERM"]) {
                     light.specular.scaleToRef(light.intensity, Tmp.Color3[1]);
-                    light._uniformBuffer.updateColor3("vLightSpecular", Tmp.Color3[1]);
+                    light._uniformBuffer.updateColor3(useUbo ? "vLightSpecular" : "vLightSpecular" + lightIndex, Tmp.Color3[1]);
                 }
 
                 // Shadows

+ 6 - 0
src/Materials/babylon.pushMaterial.ts

@@ -32,6 +32,12 @@
             this._activeEffect.setMatrix("world", world);
         }
 
+        public bindViewProjection(effect: Effect): void {
+            if (this.getScene().getEngine().webGLVersion === 1) {
+                effect.setMatrix("viewProjection", this.getScene().getTransformMatrix());
+            }
+        }
+
         public bind(world: Matrix, mesh?: Mesh): void {
             if (!mesh) {
                 return;

+ 7 - 4
src/Materials/babylon.standardMaterial.ts

@@ -699,11 +699,13 @@ module BABYLON {
                 }
 
                 var join = defines.toString();
-                var uniforms = ["world", "view", "vEyePosition", "vLightsType",
-                    "vFogInfos", "vFogColor",
+                var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vDiffuseColor", "vSpecularColor", "vEmissiveColor",
+                    "vFogInfos", "vFogColor", "pointSize",
+                    "vDiffuseInfos", "vAmbientInfos", "vOpacityInfos", "vReflectionInfos", "vEmissiveInfos", "vSpecularInfos", "vBumpInfos", "vLightmapInfos", "vRefractionInfos",
                     "mBones",
-                    "vClipPlane",
+                    "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix", "lightmapMatrix", "refractionMatrix",
                     "depthValues",
+                    "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor", "refractionLeftColor", "refractionRightColor",
                     "logarithmicDepthConstant"
                 ];
 
@@ -817,7 +819,8 @@ module BABYLON {
             if (this._mustRebind(scene, effect)) {
                 this._uniformBuffer.bindToEffect(effect, "Material");
                 
-                if (!this.isFrozen || !this._uniformBuffer.isSync) {
+                this.bindViewProjection(effect);
+                if (!this._uniformBuffer.useUbo || !this.isFrozen || !this._uniformBuffer.isSync) {
 
                     if (StandardMaterial.FresnelEnabled && defines.FRESNEL) {
                         // Fresnel

+ 34 - 13
src/Materials/babylon.uniformBuffer.ts

@@ -30,13 +30,10 @@ module BABYLON {
             this._uniformLocationPointer = 0;
             this._needSync = false;
 
-            if (this._noUbo) {
-                this._backPort();
-            }
         }
 
-        private _backPort(): void {
-            
+        public get useUbo(): boolean {
+            return !this._noUbo;
         }
         
         public get isSync(): boolean {
@@ -154,6 +151,9 @@ module BABYLON {
         }
 
         public create(): void {
+            if (this._noUbo) {
+                return;
+            }
             if (this._buffer) {
                 return; // nothing to do
             }
@@ -222,7 +222,9 @@ module BABYLON {
 
         public updateFloat(name: string, x: number) {
             if (this._noUbo) {
-                this._currentEffect.setFloat(name, x);
+                if (this._currentEffect) {
+                    this._currentEffect.setFloat(name, x);
+                }
                 return;
             }
 
@@ -232,7 +234,9 @@ module BABYLON {
 
         public updateFloat2(name: string, x: number, y: number) {
             if (this._noUbo) {
-                this._currentEffect.setFloat2(name, x, y);
+                if (this._currentEffect) {
+                    this._currentEffect.setFloat2(name, x, y);
+                }
                 return;
             }
 
@@ -243,7 +247,9 @@ module BABYLON {
 
         public updateFloat3(name: string, x: number, y: number, z: number) {
             if (this._noUbo) {
-                this._currentEffect.setFloat3(name, x, y, z);
+                if (this._currentEffect) {
+                    this._currentEffect.setFloat3(name, x, y, z);
+                }
                 return;
             }
 
@@ -255,7 +261,9 @@ module BABYLON {
 
         public updateFloat4(name: string, x: number, y: number, z: number, w: number) {
             if (this._noUbo) {
-                this._currentEffect.setFloat4(name, x, y, z, w);
+                if (this._currentEffect) {
+                    this._currentEffect.setFloat4(name, x, y, z, w);
+                }
                 return;
             }
 
@@ -268,7 +276,9 @@ module BABYLON {
 
         public updateMatrix(name: string, mat: Matrix) {
             if (this._noUbo) {
-                this._currentEffect.setMatrix(name, mat);
+                if (this._currentEffect) {
+                    this._currentEffect.setMatrix(name, mat);
+                }
                 return;
             }
 
@@ -277,7 +287,9 @@ module BABYLON {
 
         public updateVector3(name: string, vector: Vector3) {
             if (this._noUbo) {
-                this._currentEffect.setVector3(name, vector);
+                if (this._currentEffect) {
+                    this._currentEffect.setVector3(name, vector);
+                }
                 return;
             }
             vector.toArray(_tempBuffer);
@@ -286,7 +298,9 @@ module BABYLON {
 
         public updateColor3(name: string, color: Color3) {
             if (this._noUbo) {
-                this._currentEffect.setColor3(name, color);
+                if (this._currentEffect) {
+                    this._currentEffect.setColor3(name, color);
+                }
                 return;
             }
             color.toArray(_tempBuffer);
@@ -295,7 +309,9 @@ module BABYLON {
 
         public updateColor4(name: string, color: Color3, alpha: number) {
             if (this._noUbo) {
-                this._currentEffect.setColor4(name, color, alpha);
+                if (this._currentEffect) {
+                    this._currentEffect.setColor4(name, color, alpha);
+                }
                 return;
             }
             color.toArray(_tempBuffer);
@@ -311,6 +327,11 @@ module BABYLON {
 
         public bindToEffect(effect: Effect, name: string): void {
             this._currentEffect = effect;
+
+            if (this._noUbo) {
+                return;
+            }
+            
             effect.bindUniformBuffer(this._buffer, name);
         }
 

+ 0 - 10
src/Shaders/ShadersInclude/defaultVertexDeclaration.fx

@@ -36,16 +36,6 @@ uniform vec3 vBumpInfos;
 uniform mat4 bumpMatrix;
 #endif
 
-// Output
-varying vec3 vPositionW;
-#ifdef NORMAL
-varying vec3 vNormalW;
-#endif
-
-#ifdef VERTEXCOLOR
-varying vec4 vColor;
-#endif
-
 #ifdef POINTSIZE
 	uniform float pointSize;
 #endif