Bläddra i källkod

Merge remote-tracking branch 'BabylonJS/master'

MackeyK24 8 år sedan
förälder
incheckning
799e710f73

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1187 - 1177
dist/preview release/babylon.d.ts


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1187 - 1177
dist/preview release/babylon.module.d.ts


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1147 - 1137
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 13 - 13
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 40 - 20
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1147 - 1137
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.module.d.ts


+ 20 - 17
dist/preview release/loaders/babylon.glTF2FileLoader.js

@@ -631,27 +631,30 @@ var BABYLON;
                             verticesStart: vertexData.positions.length,
                             verticesCount: subVertexData.positions.length,
                             indicesStart: vertexData.indices.length,
-                            indicesCount: subVertexData.indices.length
+                            indicesCount: subVertexData.indices.length,
+                            loadMaterial: function () {
+                                if (primitive.material === undefined) {
+                                    babylonMultiMaterial.subMaterials[i] = _this._getDefaultMaterial();
+                                }
+                                else {
+                                    var material = _this._gltf.materials[primitive.material];
+                                    _this.loadMaterial(material, function (babylonMaterial, isNew) {
+                                        if (isNew && _this._parent.onMaterialLoaded) {
+                                            _this._parent.onMaterialLoaded(babylonMaterial);
+                                        }
+                                        _this.addPendingData(material);
+                                        babylonMaterial.forceCompilation(babylonMesh, function (babylonMaterial) {
+                                            babylonMultiMaterial.subMaterials[i] = babylonMaterial;
+                                            _this.removePendingData(material);
+                                        });
+                                    });
+                                }
+                            }
                         });
                         vertexData.merge(subVertexData);
-                        if (primitive.material === undefined) {
-                            babylonMultiMaterial.subMaterials[i] = _this._getDefaultMaterial();
-                        }
-                        else {
-                            var material = _this._gltf.materials[primitive.material];
-                            _this.loadMaterial(material, function (babylonMaterial, isNew) {
-                                if (isNew && _this._parent.onMaterialLoaded) {
-                                    _this._parent.onMaterialLoaded(babylonMaterial);
-                                }
-                                _this.addPendingData(material);
-                                babylonMaterial.forceCompilation(babylonMesh, function (babylonMaterial) {
-                                    babylonMultiMaterial.subMaterials[i] = babylonMaterial;
-                                    _this.removePendingData(material);
-                                });
-                            });
-                        }
                         if (++loadedPrimitives === totalPrimitives) {
                             geometry.setAllVerticesData(vertexData, false);
+                            subMeshInfos.forEach(function (info) { return info.loadMaterial(); });
                             // TODO: optimize this so that sub meshes can be created without being overwritten after setting vertex data.
                             // Sub meshes must be cleared and created after setting vertex data because of mesh._createGlobalSubMesh.
                             babylonMesh.subMeshes = [];

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
dist/preview release/loaders/babylon.glTF2FileLoader.min.js


+ 20 - 17
dist/preview release/loaders/babylon.glTFFileLoader.js

@@ -2789,27 +2789,30 @@ var BABYLON;
                             verticesStart: vertexData.positions.length,
                             verticesCount: subVertexData.positions.length,
                             indicesStart: vertexData.indices.length,
-                            indicesCount: subVertexData.indices.length
+                            indicesCount: subVertexData.indices.length,
+                            loadMaterial: function () {
+                                if (primitive.material === undefined) {
+                                    babylonMultiMaterial.subMaterials[i] = _this._getDefaultMaterial();
+                                }
+                                else {
+                                    var material = _this._gltf.materials[primitive.material];
+                                    _this.loadMaterial(material, function (babylonMaterial, isNew) {
+                                        if (isNew && _this._parent.onMaterialLoaded) {
+                                            _this._parent.onMaterialLoaded(babylonMaterial);
+                                        }
+                                        _this.addPendingData(material);
+                                        babylonMaterial.forceCompilation(babylonMesh, function (babylonMaterial) {
+                                            babylonMultiMaterial.subMaterials[i] = babylonMaterial;
+                                            _this.removePendingData(material);
+                                        });
+                                    });
+                                }
+                            }
                         });
                         vertexData.merge(subVertexData);
-                        if (primitive.material === undefined) {
-                            babylonMultiMaterial.subMaterials[i] = _this._getDefaultMaterial();
-                        }
-                        else {
-                            var material = _this._gltf.materials[primitive.material];
-                            _this.loadMaterial(material, function (babylonMaterial, isNew) {
-                                if (isNew && _this._parent.onMaterialLoaded) {
-                                    _this._parent.onMaterialLoaded(babylonMaterial);
-                                }
-                                _this.addPendingData(material);
-                                babylonMaterial.forceCompilation(babylonMesh, function (babylonMaterial) {
-                                    babylonMultiMaterial.subMaterials[i] = babylonMaterial;
-                                    _this.removePendingData(material);
-                                });
-                            });
-                        }
                         if (++loadedPrimitives === totalPrimitives) {
                             geometry.setAllVerticesData(vertexData, false);
+                            subMeshInfos.forEach(function (info) { return info.loadMaterial(); });
                             // TODO: optimize this so that sub meshes can be created without being overwritten after setting vertex data.
                             // Sub meshes must be cleared and created after setting vertex data because of mesh._createGlobalSubMesh.
                             babylonMesh.subMeshes = [];

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
dist/preview release/loaders/babylon.glTFFileLoader.min.js


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
dist/preview release/loaders/babylon.objFileLoader.min.js


+ 23 - 20
loaders/src/glTF/2.0/babylon.glTFLoader.ts

@@ -374,7 +374,7 @@ module BABYLON.GLTF2 {
             vertexData.positions = [];
             vertexData.indices = [];
 
-            var subMeshInfos: { materialIndex: number, verticesStart: number, verticesCount: number, indicesStart: number, indicesCount: number }[] = [];
+            var subMeshInfos: { materialIndex: number, verticesStart: number, verticesCount: number, indicesStart: number, indicesCount: number, loadMaterial: () => void }[] = [];
 
             var loadedPrimitives = 0;
             var totalPrimitives = mesh.primitives.length;
@@ -395,32 +395,35 @@ module BABYLON.GLTF2 {
                         verticesStart: vertexData.positions.length,
                         verticesCount: subVertexData.positions.length,
                         indicesStart: vertexData.indices.length,
-                        indicesCount: subVertexData.indices.length
-                    });
-
-                    vertexData.merge(subVertexData);
+                        indicesCount: subVertexData.indices.length,
+                        loadMaterial: () => {
+                            if (primitive.material === undefined) {
+                                babylonMultiMaterial.subMaterials[i] = this._getDefaultMaterial();
+                            }
+                            else {
+                                var material = this._gltf.materials[primitive.material];
+                                this.loadMaterial(material, (babylonMaterial, isNew) => {
+                                    if (isNew && this._parent.onMaterialLoaded) {
+                                        this._parent.onMaterialLoaded(babylonMaterial);
+                                    }
 
-                    if (primitive.material === undefined) {
-                        babylonMultiMaterial.subMaterials[i] = this._getDefaultMaterial();
-                    }
-                    else {
-                        var material = this._gltf.materials[primitive.material];
-                        this.loadMaterial(material, (babylonMaterial, isNew) => {
-                            if (isNew && this._parent.onMaterialLoaded) {
-                                this._parent.onMaterialLoaded(babylonMaterial);
+                                    this.addPendingData(material);
+                                    babylonMaterial.forceCompilation(babylonMesh, babylonMaterial => {
+                                        babylonMultiMaterial.subMaterials[i] = babylonMaterial;
+                                        this.removePendingData(material);
+                                    });
+                                });
                             }
+                        }
+                    });
 
-                            this.addPendingData(material);
-                            babylonMaterial.forceCompilation(babylonMesh, babylonMaterial => {
-                                babylonMultiMaterial.subMaterials[i] = babylonMaterial;
-                                this.removePendingData(material);
-                            });
-                        });
-                    }
+                    vertexData.merge(subVertexData);
 
                     if (++loadedPrimitives === totalPrimitives) {
                         geometry.setAllVerticesData(vertexData, false);
 
+                        subMeshInfos.forEach(info => info.loadMaterial());
+
                         // TODO: optimize this so that sub meshes can be created without being overwritten after setting vertex data.
                         // Sub meshes must be cleared and created after setting vertex data because of mesh._createGlobalSubMesh.
                         babylonMesh.subMeshes = [];

+ 16 - 1
src/Materials/PBR/babylon.pbrBaseMaterial.ts

@@ -117,6 +117,8 @@
         public FOG = false;
         public LOGARITHMICDEPTH = false;
 
+        public FORCENORMALFORWARD = false;
+
         constructor() {
             super();
             this.rebuild();
@@ -398,6 +400,12 @@
         protected _forceIrradianceInFragment = false;
 
         /**
+         * Force normal to face away from face.
+         * (Temporary internal fix to remove before 3.1)
+         */
+        protected _forceNormalForward = false;
+
+        /**
          * Default configuration related to image processing available in the PBR Material.
          */
         @serializeAsImageProcessingConfiguration()
@@ -801,6 +809,8 @@
                 this._imageProcessingConfiguration.prepareDefines(defines);
             }
 
+            defines.FORCENORMALFORWARD = this._forceNormalForward;
+
             // Misc.
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
 
@@ -1251,7 +1261,12 @@
                 // Colors
                 scene.ambientColor.multiplyToRef(this._ambientColor, this._globalAmbientColor);
 
-                effect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
+                var eyePosition = scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position;
+                effect.setFloat4("vEyePosition", 
+                    eyePosition.x,
+                    eyePosition.y,
+                    eyePosition.z,
+                    scene._mirroredCameraPosition ? -1 : 1);
                 effect.setColor3("vAmbientColor", this._globalAmbientColor);
             }
 

+ 8 - 0
src/Materials/PBR/babylon.pbrMaterial.ts

@@ -405,6 +405,14 @@
         public environmentBRDFTexture: BaseTexture = null;
 
         /**
+         * Force normal to face away from face.
+         * (Temporary internal fix to remove before 3.1)
+         */
+        @serialize()
+        @expandToProperty("_markAllSubMeshesAsTexturesDirty")
+        public forceNormalForward = false;
+
+        /**
          * Gets the image processing configuration used either in this material.
          */
         public get imageProcessingConfiguration(): ImageProcessingConfiguration {

+ 1 - 1
src/Shaders/ShadersInclude/pbrLightFunctions.fx

@@ -38,7 +38,7 @@ float computeDirectionalLightFalloff(vec3 lightDirection, vec3 directionToLightC
         falloff = exp2(dot(vec4(directionToLightCenterW, 1.0), lightDirectionSpreadSG));
     #else
         float cosAngle = max(0.000000000000001, dot(-lightDirection, directionToLightCenterW));
-        if (cosAngle >= lightAngle)
+        if (cosAngle >= cosHalfAngle)
         {
             falloff = max(0., pow(cosAngle, exponent));
         }

+ 3 - 3
src/Shaders/ShadersInclude/reflectionFunction.fx

@@ -15,7 +15,7 @@
 
 #ifdef REFLECTIONMAP_EQUIRECTANGULAR
 
-	vec3 cameraToVertex = normalize(worldPos.xyz - vEyePosition);
+	vec3 cameraToVertex = normalize(worldPos.xyz - vEyePosition.xyz);
 	vec3 r = reflect(cameraToVertex, worldNormal);
 	float t = clamp(r.y * -0.5 + 0.5, 0., 1.0);
 	float s = atan(r.z, r.x) * RECIPROCAL_PI2 + 0.5;
@@ -36,14 +36,14 @@
 #endif
 
 #ifdef REFLECTIONMAP_PLANAR
-	vec3 viewDir = worldPos.xyz - vEyePosition;
+	vec3 viewDir = worldPos.xyz - vEyePosition.xyz;
 	vec3 coords = normalize(reflect(viewDir, worldNormal));
 
 	return vec3(reflectionMatrix * vec4(coords, 1));
 #endif
 
 #ifdef REFLECTIONMAP_CUBIC
-	vec3 viewDir = worldPos.xyz - vEyePosition;
+	vec3 viewDir = worldPos.xyz - vEyePosition.xyz;
 	vec3 coords = reflect(viewDir, worldNormal);
 #ifdef INVERTCUBICMAP
 	coords.y = 1.0 - coords.y;

+ 15 - 13
src/Shaders/pbr.fragment.fx

@@ -1,4 +1,4 @@
-#if defined(BUMP)|| !defined(NORMAL)
+#if defined(BUMP) || !defined(NORMAL) || defined(FORCENORMALFORWARD)
 #extension GL_OES_standard_derivatives : enable
 #endif
 
@@ -14,7 +14,7 @@ precision highp float;
 
 #include<__decl__pbrFragment>
 
-uniform vec3 vEyePosition;
+uniform vec4 vEyePosition;
 uniform vec3 vAmbientColor;
 uniform vec4 vCameraInfos;
 
@@ -218,26 +218,28 @@ void main(void) {
 
 // _______________________________________________________________________________
 // _____________________________ Geometry Information ____________________________
-	vec3 viewDirectionW = normalize(vEyePosition - vPositionW);
+	vec3 viewDirectionW = normalize(vEyePosition.xyz - vPositionW);
 
 #ifdef NORMAL
 	vec3 normalW = normalize(vNormalW);
 #else
-	vec3 normalW = normalize(cross(dFdx(vPositionW), dFdy(vPositionW)));
-#endif
-
-#ifdef BUMP
-	vec3 originalNormalW = normalW;
+	vec3 normalW = normalize(cross(dFdx(vPositionW), dFdy(vPositionW))) * vEyePosition.w;
 #endif
 
 #include<bumpFragment>
 
-#if defined(TWOSIDEDLIGHTING) && defined(NORMAL) 
-	normalW = gl_FrontFacing ? normalW : -normalW;
-
-	#ifdef BUMP
-		originalNormalW = gl_FrontFacing ? originalNormalW : -originalNormalW;;
+#if defined(FORCENORMALFORWARD) && defined(NORMAL)
+	vec3 faceNormal = normalize(cross(dFdx(vPositionW), dFdy(vPositionW))) * vEyePosition.w;
+	#if defined(TWOSIDEDLIGHTING)
+		faceNormal = gl_FrontFacing ? faceNormal : -faceNormal;
 	#endif
+
+	float comp = sign(dot(normalW, faceNormal));
+    normalW *= -comp;
+#endif
+
+#if defined(TWOSIDEDLIGHTING) && defined(NORMAL)
+	normalW = gl_FrontFacing ? normalW : -normalW;
 #endif
 
 // _____________________________ Albedo Information ______________________________

BIN
tests/validation/ReferenceImages/Flat2009.png


+ 1 - 1
tests/validation/config.json

@@ -209,7 +209,7 @@
     {
       "title": "MultiSample render targets",
       "renderCount": 10,
-      "playgroundId": "#12MKMN",
+      "playgroundId": "#12MKMN#0",
       "referenceImage": "MultiSample render targets.png"
     },            
     {

+ 1 - 1
tests/validation/validation.js

@@ -196,7 +196,7 @@ runTest(index) {
             }
         }
 
-        xmlHttp.open("GET", snippetUrl + "/" + test.playgroundId.replace("#", "/"));
+        xmlHttp.open("GET", snippetUrl + test.playgroundId.replace(/#/g, "/"));
         xmlHttp.send();
     } else {
         // Fix references