Quellcode durchsuchen

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

Temechon vor 8 Jahren
Ursprung
Commit
f6eb797b44

BIN
Exporters/Blender/Blender2Babylon-5.0.zip


+ 1 - 1
Exporters/Blender/src/__init__.py

@@ -1,7 +1,7 @@
 bl_info = {
     'name': 'Babylon.js',
     'author': 'David Catuhe, Jeff Palmer',
-    'version': (5, 0, 6),
+    'version': (5, 0, 7),
     'blender': (2, 76, 0),
     'location': 'File > Export > Babylon.js (.babylon)',
     'description': 'Export Babylon.js scenes (.babylon)',

+ 1 - 1
Exporters/Blender/src/armature.py

@@ -119,7 +119,7 @@ class Skeleton:
 
         self.dimensions = self.getDimensions()
 
-        bpy.ops.object.mode_set(mode='POSE')
+        bpy.ops.object.mode_set(mode='OBJECT')
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     # do not use .dimensions from blender, it might be including IK bones
     def getDimensions(self):

Datei-Diff unterdrückt, da er zu groß ist
+ 27 - 27
dist/preview release/babylon.core.js


Datei-Diff unterdrückt, da er zu groß ist
+ 1445 - 1441
dist/preview release/babylon.d.ts


Datei-Diff unterdrückt, da er zu groß ist
+ 28 - 28
dist/preview release/babylon.js


Datei-Diff unterdrückt, da er zu groß ist
+ 132 - 156
dist/preview release/babylon.max.js


Datei-Diff unterdrückt, da er zu groß ist
+ 22 - 22
dist/preview release/babylon.noworker.js


+ 2 - 0
dist/preview release/what's new.md

@@ -8,6 +8,8 @@
 - Canvas2D moved to a separate folder in main repo. Now you need to also include babylon.cavans2d.js to get Canvas@D feature ([deltakosh](https://github.com/deltakosh))
 
 ### Updates
+- Added Bone.rotate ([abow](https://github.com/abow))
+- Added Bone.scale ([abow](https://github.com/abow))
 - Added Node.getDirection ([abow](https://github.com/abow))
 - New ```Tools.CreateScreenshot``` function will capture all canvas data. Previous implementation is now called `CreateScreenshotUsingRenderTarget` ([deltakosh](https://github.com/deltakosh)) 
 - Cube textures are now cached by texture cache ([deltakosh](https://github.com/deltakosh)) 

+ 168 - 0
src/Bones/babylon.bone.ts

@@ -13,6 +13,9 @@
         private _invertedAbsoluteTransform = new Matrix();
         private _parent: Bone;
 
+        private _scaleMatrix: Matrix;
+        private _scaleVector: Vector3;
+
         constructor(public name: string, skeleton: Skeleton, parentBone: Bone, matrix: Matrix, restPose?: Matrix) {
             super(name, skeleton.getScene());
             this._skeleton = skeleton;
@@ -161,5 +164,170 @@
             this.animations[0].createRange(rangeName, from + frameOffset, to + frameOffset);
             return true;
         }
+
+        public scale (x: number, y: number, z: number, scaleChildren = false) {
+	
+            var locMat = this.getLocalMatrix();
+            
+            var origLocMat = BABYLON.Tmp.Matrix[0];
+            origLocMat.copyFrom(locMat);
+            
+            var origLocMatInv = BABYLON.Tmp.Matrix[1];
+            origLocMatInv.copyFrom(origLocMat);
+            origLocMatInv.invert();
+            
+            var scaleMat = BABYLON.Tmp.Matrix[2];
+            BABYLON.Matrix.FromValuesToRef(x, 0, 0, 0,
+                                            0, y, 0, 0,
+                                            0, 0, z, 0,
+                                            0, 0, 0, 1, scaleMat);
+                                                
+            this._scaleMatrix.multiplyToRef(scaleMat, this._scaleMatrix);
+            
+            this._scaleVector.x *= x;
+            this._scaleVector.y *= y;
+            this._scaleVector.z *= z;
+                    
+            locMat.multiplyToRef(origLocMatInv, locMat);
+            locMat.multiplyToRef(scaleMat, locMat);
+            locMat.multiplyToRef(origLocMat, locMat);
+            
+            var parent = this.getParent();
+            
+            if (parent) {
+                locMat.multiplyToRef(parent.getAbsoluteTransform(), this.getAbsoluteTransform());
+            } else {
+                this.getAbsoluteTransform().copyFrom(locMat);
+            }
+            
+            var len = this.children.length;
+            
+            for (var i = 0; i < len; i++){
+                
+                var parentAbsMat = this.children[i]._parent.getAbsoluteTransform();
+                
+                this.children[i].getLocalMatrix().multiplyToRef(parentAbsMat, this.children[i].getAbsoluteTransform());
+            
+            }
+            
+            if (this.children[0] && !scaleChildren) {
+
+                scaleMat.invert();
+
+                var cm = this.children[0].getLocalMatrix();
+
+                cm.multiplyToRef(scaleMat, cm);
+                
+                var lm = this.children[0].getLocalMatrix();
+                    
+                lm.m[12] *= this._scaleVector.x;
+                lm.m[13] *= this._scaleVector.y;
+                lm.m[14] *= this._scaleVector.z;
+
+            }
+            
+            this.markAsDirty();
+
+        }
+
+        public rotate (axis: BABYLON.Vector3, amount: number, space = BABYLON.Space.LOCAL, mesh: BABYLON.AbstractMesh = null) {
+
+            var lmat = this.getLocalMatrix();
+            
+            var lx = lmat.m[12];
+            var ly = lmat.m[13];
+            var lz = lmat.m[14];
+            
+            var rmat = BABYLON.Tmp.Matrix[0];
+            rmat.m[12] = 0;
+            rmat.m[13] = 0;
+            rmat.m[14] = 0;
+            
+            var parent = this.getParent();
+
+            BABYLON.Matrix.RotationAxisToRef(axis, amount, rmat);
+
+            var parentScale = BABYLON.Tmp.Matrix[1];
+            var parentScaleInv = BABYLON.Tmp.Matrix[2];
+            
+            if (parent) {
+                
+                if (space == BABYLON.Space.WORLD) {
+                    
+                    if (mesh) {
+                        parentScale.copyFrom(mesh.getWorldMatrix());
+                        parent.getAbsoluteTransform().multiplyToRef(parentScale, parentScale);
+                    } else {
+                        parentScale.copyFrom(parent.getAbsoluteTransform());
+                    }
+                    
+                } else {
+                    
+                    parentScale = parent._scaleMatrix;
+                    
+                }
+
+                parentScaleInv.copyFrom(parentScale);
+                parentScaleInv.invert();
+                
+                lmat.multiplyToRef(parentScale, lmat);
+                lmat.multiplyToRef(rmat, lmat);
+                lmat.multiplyToRef(parentScaleInv, lmat);
+                
+            } else {
+                
+                if (space == BABYLON.Space.WORLD && mesh) {
+
+                    parentScale.copyFrom(mesh.getWorldMatrix());
+
+                    parentScaleInv.copyFrom(parentScale);
+                    parentScaleInv.invert();
+                    
+                    lmat.multiplyToRef(parentScale, lmat);
+                    lmat.multiplyToRef(rmat, lmat);
+                    lmat.multiplyToRef(parentScaleInv, lmat);
+                    
+                } else {
+                    
+                    lmat.multiplyToRef(rmat, lmat);
+
+                }
+
+            }
+            
+            lmat.m[12] = lx;
+            lmat.m[13] = ly;
+            lmat.m[14] = lz;
+            
+            if (parent) {
+                var parentAbsMat = this._parent.getAbsoluteTransform();
+                lmat.multiplyToRef(parentAbsMat, this.getAbsoluteTransform());
+            } else {
+                this.getAbsoluteTransform().copyFrom(lmat);
+            }
+            
+            var len = this.children.length;
+            
+            for (var i = 0; i < len; i++){
+                var parentAbsMat = this.children[i]._parent.getAbsoluteTransform();
+                this.children[i].getLocalMatrix().multiplyToRef(parentAbsMat, this.children[i].getAbsoluteTransform());
+            }
+            
+            this.markAsDirty();
+            
+        }
+
+        public getScale(): Vector3 {
+            
+            return this._scaleVector.clone();
+            
+        }
+
+        public getScaleToRef(result:Vector3): void {
+	
+            result.copyFrom(this._scaleVector);
+            
+        }
+
     }
 } 

+ 18 - 46
src/Layer/babylon.highlightlayer.js

@@ -441,21 +441,14 @@ var BABYLON;
          * @param mesh The mesh to exclude from the highlight layer
          */
         HighlightLayer.prototype.addExcludedMesh = function (mesh) {
-            var sourceMesh;
-            if (mesh instanceof BABYLON.InstancedMesh) {
-                sourceMesh = mesh.sourceMesh;
-            }
-            else {
-                sourceMesh = mesh;
-            }
-            var meshExcluded = this._excludedMeshes[sourceMesh.id];
+            var meshExcluded = this._excludedMeshes[mesh.id];
             if (!meshExcluded) {
-                this._excludedMeshes[sourceMesh.id] = {
-                    mesh: sourceMesh,
-                    beforeRender: sourceMesh.onBeforeRenderObservable.add(function (mesh) {
+                this._excludedMeshes[mesh.id] = {
+                    mesh: mesh,
+                    beforeRender: mesh.onBeforeRenderObservable.add(function (mesh) {
                         mesh.getEngine().setStencilBuffer(false);
                     }),
-                    afterRender: sourceMesh.onAfterRenderObservable.add(function (mesh) {
+                    afterRender: mesh.onAfterRenderObservable.add(function (mesh) {
                         mesh.getEngine().setStencilBuffer(true);
                     }),
                 };
@@ -466,19 +459,12 @@ var BABYLON;
           * @param mesh The mesh to highlight
           */
         HighlightLayer.prototype.removeExcludedMesh = function (mesh) {
-            var sourceMesh;
-            if (mesh instanceof BABYLON.InstancedMesh) {
-                sourceMesh = mesh.sourceMesh;
-            }
-            else {
-                sourceMesh = mesh;
-            }
-            var meshExcluded = this._excludedMeshes[sourceMesh.id];
+            var meshExcluded = this._excludedMeshes[mesh.id];
             if (meshExcluded) {
-                sourceMesh.onBeforeRenderObservable.remove(meshExcluded.beforeRender);
-                sourceMesh.onAfterRenderObservable.remove(meshExcluded.afterRender);
+                mesh.onBeforeRenderObservable.remove(meshExcluded.beforeRender);
+                mesh.onAfterRenderObservable.remove(meshExcluded.afterRender);
             }
-            this._excludedMeshes[sourceMesh.id] = undefined;
+            this._excludedMeshes[mesh.id] = undefined;
         };
         /**
          * Add a mesh in the highlight layer in order to make it glow with the chosen color.
@@ -489,23 +475,16 @@ var BABYLON;
         HighlightLayer.prototype.addMesh = function (mesh, color, glowEmissiveOnly) {
             var _this = this;
             if (glowEmissiveOnly === void 0) { glowEmissiveOnly = false; }
-            var sourceMesh;
-            if (mesh instanceof BABYLON.InstancedMesh) {
-                sourceMesh = mesh.sourceMesh;
-            }
-            else {
-                sourceMesh = mesh;
-            }
-            var meshHighlight = this._meshes[sourceMesh.id];
+            var meshHighlight = this._meshes[mesh.id];
             if (meshHighlight) {
                 meshHighlight.color = color;
             }
             else {
-                this._meshes[sourceMesh.id] = {
-                    mesh: sourceMesh,
+                this._meshes[mesh.id] = {
+                    mesh: mesh,
                     color: color,
                     // Lambda required for capture due to Observable this context
-                    observerHighlight: sourceMesh.onBeforeRenderObservable.add(function (mesh) {
+                    observerHighlight: mesh.onBeforeRenderObservable.add(function (mesh) {
                         if (_this._excludedMeshes[mesh.id]) {
                             _this.defaultStencilReference(mesh);
                         }
@@ -513,7 +492,7 @@ var BABYLON;
                             mesh.getScene().getEngine().setStencilFunctionReference(_this._instanceGlowingMeshStencilReference);
                         }
                     }),
-                    observerDefault: sourceMesh.onAfterRenderObservable.add(this.defaultStencilReference),
+                    observerDefault: mesh.onAfterRenderObservable.add(this.defaultStencilReference),
                     glowEmissiveOnly: glowEmissiveOnly
                 };
             }
@@ -524,19 +503,12 @@ var BABYLON;
          * @param mesh The mesh to highlight
          */
         HighlightLayer.prototype.removeMesh = function (mesh) {
-            var sourceMesh;
-            if (mesh instanceof BABYLON.InstancedMesh) {
-                sourceMesh = mesh.sourceMesh;
-            }
-            else {
-                sourceMesh = mesh;
-            }
-            var meshHighlight = this._meshes[sourceMesh.id];
+            var meshHighlight = this._meshes[mesh.id];
             if (meshHighlight) {
-                sourceMesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
-                sourceMesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
+                mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
+                mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
             }
-            this._meshes[sourceMesh.id] = undefined;
+            this._meshes[mesh.id] = undefined;
             this._shouldRender = false;
             for (var meshHighlightToCheck in this._meshes) {
                 if (meshHighlightToCheck) {

+ 22 - 50
src/Layer/babylon.highlightlayer.ts

@@ -635,22 +635,15 @@
          * Add a mesh in the exclusion list to prevent it to impact or being impacted by the highlight layer.
          * @param mesh The mesh to exclude from the highlight layer
          */
-        public addExcludedMesh(mesh: AbstractMesh) {
-            var sourceMesh: Mesh;
-            if (mesh instanceof InstancedMesh) {
-                sourceMesh = (<InstancedMesh>mesh).sourceMesh;
-            } else {
-                sourceMesh = <Mesh>mesh;
-            }
-
-            var meshExcluded = this._excludedMeshes[sourceMesh.id];
+        public addExcludedMesh(mesh: Mesh) {
+            var meshExcluded = this._excludedMeshes[mesh.id];
             if (!meshExcluded) {
-                this._excludedMeshes[sourceMesh.id] = {
-                    mesh: sourceMesh,
-                    beforeRender: sourceMesh.onBeforeRenderObservable.add((mesh: Mesh) => {
+                this._excludedMeshes[mesh.id] = {
+                    mesh: mesh,
+                    beforeRender: mesh.onBeforeRenderObservable.add((mesh: Mesh) => {
                         mesh.getEngine().setStencilBuffer(false);
                     }),
-                    afterRender: sourceMesh.onAfterRenderObservable.add((mesh: Mesh) => {
+                    afterRender: mesh.onAfterRenderObservable.add((mesh: Mesh) => {
                         mesh.getEngine().setStencilBuffer(true);
                     }),
                 }
@@ -661,21 +654,14 @@
           * Remove a mesh from the exclusion list to let it impact or being impacted by the highlight layer.
           * @param mesh The mesh to highlight
           */
-        public removeExcludedMesh(mesh: AbstractMesh) {
-            var sourceMesh: Mesh;
-            if (mesh instanceof InstancedMesh) {
-                sourceMesh = (<InstancedMesh>mesh).sourceMesh;
-            } else {
-                sourceMesh = <Mesh>mesh;
-            }
-
-            var meshExcluded = this._excludedMeshes[sourceMesh.id];
+        public removeExcludedMesh(mesh: Mesh) {
+            var meshExcluded = this._excludedMeshes[mesh.id];
             if (meshExcluded) {
-                sourceMesh.onBeforeRenderObservable.remove(meshExcluded.beforeRender);
-                sourceMesh.onAfterRenderObservable.remove(meshExcluded.afterRender);
+                mesh.onBeforeRenderObservable.remove(meshExcluded.beforeRender);
+                mesh.onAfterRenderObservable.remove(meshExcluded.afterRender);
             }
 
-            this._excludedMeshes[sourceMesh.id] = undefined;
+            this._excludedMeshes[mesh.id] = undefined;
         }
 
         /**
@@ -684,24 +670,17 @@
          * @param color The color of the highlight
          * @param glowEmissiveOnly Extract the glow from the emissive texture
          */
-        public addMesh(mesh: AbstractMesh, color: Color3, glowEmissiveOnly = false) {
-            var sourceMesh: Mesh;
-            if (mesh instanceof InstancedMesh) {
-                sourceMesh = (<InstancedMesh>mesh).sourceMesh;
-            } else {
-                sourceMesh = <Mesh>mesh;
-            }
-
-            var meshHighlight = this._meshes[sourceMesh.id];
+        public addMesh(mesh: Mesh, color: Color3, glowEmissiveOnly = false) {
+            var meshHighlight = this._meshes[mesh.id];
             if (meshHighlight) {
                 meshHighlight.color = color;
             }
             else {
-                this._meshes[sourceMesh.id] = {
-                    mesh: sourceMesh,
+                this._meshes[mesh.id] = {
+                    mesh: mesh,
                     color: color,
                     // Lambda required for capture due to Observable this context
-                    observerHighlight: sourceMesh.onBeforeRenderObservable.add((mesh: Mesh) => {
+                    observerHighlight: mesh.onBeforeRenderObservable.add((mesh: Mesh) => {
                         if (this._excludedMeshes[mesh.id]) {
                             this.defaultStencilReference(mesh);
                         }
@@ -709,7 +688,7 @@
                             mesh.getScene().getEngine().setStencilFunctionReference(this._instanceGlowingMeshStencilReference);
                         }
                     }),
-                    observerDefault: sourceMesh.onAfterRenderObservable.add(this.defaultStencilReference),
+                    observerDefault: mesh.onAfterRenderObservable.add(this.defaultStencilReference),
                     glowEmissiveOnly: glowEmissiveOnly
                 };
             }
@@ -721,21 +700,14 @@
          * Remove a mesh from the highlight layer in order to make it stop glowing.
          * @param mesh The mesh to highlight
          */
-        public removeMesh(mesh: AbstractMesh) {
-            var sourceMesh: Mesh;
-            if (mesh instanceof InstancedMesh) {
-                sourceMesh = (<InstancedMesh>mesh).sourceMesh;
-            } else {
-                sourceMesh = <Mesh>mesh;
-            }
-
-            var meshHighlight = this._meshes[sourceMesh.id];
+        public removeMesh(mesh: Mesh) {
+            var meshHighlight = this._meshes[mesh.id];
             if (meshHighlight) {
-                sourceMesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
-                sourceMesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
+                mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
+                mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
             }
 
-            this._meshes[sourceMesh.id] = undefined;
+            this._meshes[mesh.id] = undefined;
 
             this._shouldRender = false;
             for (var meshHighlightToCheck in this._meshes) {

+ 103 - 103
src/Materials/babylon.pbrMaterial.js

@@ -218,6 +218,10 @@ var BABYLON;
              */
             this.overloadedMicroSurfaceIntensity = 0.0;
             this._overloadedMicroSurface = new BABYLON.Vector3(this.overloadedMicroSurface, this.overloadedMicroSurfaceIntensity, this.overloadedReflectionIntensity);
+            /**
+             * AKA Occlusion Texture Intensity in other nomenclature.
+             */
+            this.ambientTextureStrength = 1.0;
             this.ambientColor = new BABYLON.Color3(0, 0, 0);
             /**
              * AKA Diffuse Color in other nomenclature.
@@ -441,114 +445,111 @@ var BABYLON;
             var needUVs = false;
             this._defines.reset();
             if (scene.texturesEnabled) {
-                // Textures
-                if (scene.texturesEnabled) {
-                    if (scene.getEngine().getCaps().textureLOD) {
-                        this._defines.LODBASEDMICROSFURACE = true;
+                if (scene.getEngine().getCaps().textureLOD) {
+                    this._defines.LODBASEDMICROSFURACE = true;
+                }
+                if (this.albedoTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
+                    if (!this.albedoTexture.isReady()) {
+                        return false;
                     }
-                    if (this.albedoTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
-                        if (!this.albedoTexture.isReady()) {
-                            return false;
-                        }
-                        else {
-                            needUVs = true;
-                            this._defines.ALBEDO = true;
-                        }
+                    else {
+                        needUVs = true;
+                        this._defines.ALBEDO = true;
                     }
-                    if (this.ambientTexture && BABYLON.StandardMaterial.AmbientTextureEnabled) {
-                        if (!this.ambientTexture.isReady()) {
-                            return false;
-                        }
-                        else {
-                            needUVs = true;
-                            this._defines.AMBIENT = true;
-                        }
+                }
+                if (this.ambientTexture && BABYLON.StandardMaterial.AmbientTextureEnabled) {
+                    if (!this.ambientTexture.isReady()) {
+                        return false;
                     }
-                    if (this.opacityTexture && BABYLON.StandardMaterial.OpacityTextureEnabled) {
-                        if (!this.opacityTexture.isReady()) {
-                            return false;
-                        }
-                        else {
-                            needUVs = true;
-                            this._defines.OPACITY = true;
-                            if (this.opacityTexture.getAlphaFromRGB) {
-                                this._defines.OPACITYRGB = true;
-                            }
+                    else {
+                        needUVs = true;
+                        this._defines.AMBIENT = true;
+                    }
+                }
+                if (this.opacityTexture && BABYLON.StandardMaterial.OpacityTextureEnabled) {
+                    if (!this.opacityTexture.isReady()) {
+                        return false;
+                    }
+                    else {
+                        needUVs = true;
+                        this._defines.OPACITY = true;
+                        if (this.opacityTexture.getAlphaFromRGB) {
+                            this._defines.OPACITYRGB = true;
                         }
                     }
-                    if (this.reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
-                        if (!this.reflectionTexture.isReady()) {
-                            return false;
+                }
+                if (this.reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
+                    if (!this.reflectionTexture.isReady()) {
+                        return false;
+                    }
+                    else {
+                        needNormals = true;
+                        this._defines.REFLECTION = true;
+                        if (this.reflectionTexture.coordinatesMode === BABYLON.Texture.INVCUBIC_MODE) {
+                            this._defines.INVERTCUBICMAP = true;
                         }
-                        else {
+                        this._defines.REFLECTIONMAP_3D = this.reflectionTexture.isCube;
+                        switch (this.reflectionTexture.coordinatesMode) {
+                            case BABYLON.Texture.CUBIC_MODE:
+                            case BABYLON.Texture.INVCUBIC_MODE:
+                                this._defines.REFLECTIONMAP_CUBIC = true;
+                                break;
+                            case BABYLON.Texture.EXPLICIT_MODE:
+                                this._defines.REFLECTIONMAP_EXPLICIT = true;
+                                break;
+                            case BABYLON.Texture.PLANAR_MODE:
+                                this._defines.REFLECTIONMAP_PLANAR = true;
+                                break;
+                            case BABYLON.Texture.PROJECTION_MODE:
+                                this._defines.REFLECTIONMAP_PROJECTION = true;
+                                break;
+                            case BABYLON.Texture.SKYBOX_MODE:
+                                this._defines.REFLECTIONMAP_SKYBOX = true;
+                                break;
+                            case BABYLON.Texture.SPHERICAL_MODE:
+                                this._defines.REFLECTIONMAP_SPHERICAL = true;
+                                break;
+                            case BABYLON.Texture.EQUIRECTANGULAR_MODE:
+                                this._defines.REFLECTIONMAP_EQUIRECTANGULAR = true;
+                                break;
+                        }
+                        if (this.reflectionTexture instanceof BABYLON.HDRCubeTexture && this.reflectionTexture) {
+                            this._defines.USESPHERICALFROMREFLECTIONMAP = true;
                             needNormals = true;
-                            this._defines.REFLECTION = true;
-                            if (this.reflectionTexture.coordinatesMode === BABYLON.Texture.INVCUBIC_MODE) {
-                                this._defines.INVERTCUBICMAP = true;
-                            }
-                            this._defines.REFLECTIONMAP_3D = this.reflectionTexture.isCube;
-                            switch (this.reflectionTexture.coordinatesMode) {
-                                case BABYLON.Texture.CUBIC_MODE:
-                                case BABYLON.Texture.INVCUBIC_MODE:
-                                    this._defines.REFLECTIONMAP_CUBIC = true;
-                                    break;
-                                case BABYLON.Texture.EXPLICIT_MODE:
-                                    this._defines.REFLECTIONMAP_EXPLICIT = true;
-                                    break;
-                                case BABYLON.Texture.PLANAR_MODE:
-                                    this._defines.REFLECTIONMAP_PLANAR = true;
-                                    break;
-                                case BABYLON.Texture.PROJECTION_MODE:
-                                    this._defines.REFLECTIONMAP_PROJECTION = true;
-                                    break;
-                                case BABYLON.Texture.SKYBOX_MODE:
-                                    this._defines.REFLECTIONMAP_SKYBOX = true;
-                                    break;
-                                case BABYLON.Texture.SPHERICAL_MODE:
-                                    this._defines.REFLECTIONMAP_SPHERICAL = true;
-                                    break;
-                                case BABYLON.Texture.EQUIRECTANGULAR_MODE:
-                                    this._defines.REFLECTIONMAP_EQUIRECTANGULAR = true;
-                                    break;
-                            }
-                            if (this.reflectionTexture instanceof BABYLON.HDRCubeTexture && this.reflectionTexture) {
-                                this._defines.USESPHERICALFROMREFLECTIONMAP = true;
-                                needNormals = true;
-                                if (this.reflectionTexture.isPMREM) {
-                                    this._defines.USEPMREMREFLECTION = true;
-                                }
+                            if (this.reflectionTexture.isPMREM) {
+                                this._defines.USEPMREMREFLECTION = true;
                             }
                         }
                     }
-                    if (this.lightmapTexture && BABYLON.StandardMaterial.LightmapTextureEnabled) {
-                        if (!this.lightmapTexture.isReady()) {
-                            return false;
-                        }
-                        else {
-                            needUVs = true;
-                            this._defines.LIGHTMAP = true;
-                            this._defines.USELIGHTMAPASSHADOWMAP = this.useLightmapAsShadowmap;
-                        }
+                }
+                if (this.lightmapTexture && BABYLON.StandardMaterial.LightmapTextureEnabled) {
+                    if (!this.lightmapTexture.isReady()) {
+                        return false;
                     }
-                    if (this.emissiveTexture && BABYLON.StandardMaterial.EmissiveTextureEnabled) {
-                        if (!this.emissiveTexture.isReady()) {
-                            return false;
-                        }
-                        else {
-                            needUVs = true;
-                            this._defines.EMISSIVE = true;
-                        }
+                    else {
+                        needUVs = true;
+                        this._defines.LIGHTMAP = true;
+                        this._defines.USELIGHTMAPASSHADOWMAP = this.useLightmapAsShadowmap;
                     }
-                    if (this.reflectivityTexture && BABYLON.StandardMaterial.SpecularTextureEnabled) {
-                        if (!this.reflectivityTexture.isReady()) {
-                            return false;
-                        }
-                        else {
-                            needUVs = true;
-                            this._defines.REFLECTIVITY = true;
-                            this._defines.MICROSURFACEFROMREFLECTIVITYMAP = this.useMicroSurfaceFromReflectivityMapAlpha;
-                            this._defines.MICROSURFACEAUTOMATIC = this.useAutoMicroSurfaceFromReflectivityMap;
-                        }
+                }
+                if (this.emissiveTexture && BABYLON.StandardMaterial.EmissiveTextureEnabled) {
+                    if (!this.emissiveTexture.isReady()) {
+                        return false;
+                    }
+                    else {
+                        needUVs = true;
+                        this._defines.EMISSIVE = true;
+                    }
+                }
+                if (this.reflectivityTexture && BABYLON.StandardMaterial.SpecularTextureEnabled) {
+                    if (!this.reflectivityTexture.isReady()) {
+                        return false;
+                    }
+                    else {
+                        needUVs = true;
+                        this._defines.REFLECTIVITY = true;
+                        this._defines.MICROSURFACEFROMREFLECTIVITYMAP = this.useMicroSurfaceFromReflectivityMapAlpha;
+                        this._defines.MICROSURFACEAUTOMATIC = this.useAutoMicroSurfaceFromReflectivityMap;
                     }
                 }
                 if (scene.getEngine().getCaps().standardDerivatives && this.bumpTexture && BABYLON.StandardMaterial.BumpTextureEnabled && !this.disableBumpMap) {
@@ -558,7 +559,7 @@ var BABYLON;
                     else {
                         needUVs = true;
                         this._defines.BUMP = true;
-                        if (this.useParallax) {
+                        if (this.useParallax && this.albedoTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
                             this._defines.PARALLAX = true;
                             if (this.useParallaxOcclusion) {
                                 this._defines.PARALLAXOCCLUSION = true;
@@ -771,10 +772,6 @@ var BABYLON;
                 BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
                 BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, this._defines);
                 // Legacy browser patch
-                var shaderName = "pbr";
-                if (!scene.getEngine().getCaps().standardDerivatives) {
-                    shaderName = "legacypbr";
-                }
                 var join = this._defines.toString();
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vAlbedoColor", "vReflectivityColor", "vEmissiveColor", "vReflectionColor",
                     "vFogInfos", "vFogColor", "pointSize",
@@ -795,7 +792,7 @@ var BABYLON;
                 BABYLON.ColorCurves.PrepareUniforms(uniforms);
                 BABYLON.ColorGradingTexture.PrepareUniformsAndSamplers(uniforms, samplers);
                 BABYLON.MaterialHelper.PrepareUniformsAndSamplersList(uniforms, samplers, this._defines, this.maxSimultaneousLights);
-                this._effect = scene.getEngine().createEffect(shaderName, attribs, uniforms, samplers, join, fallbacks, this.onCompiled, this.onError, { maxSimultaneousLights: this.maxSimultaneousLights });
+                this._effect = scene.getEngine().createEffect("pbr", attribs, uniforms, samplers, join, fallbacks, this.onCompiled, this.onError, { maxSimultaneousLights: this.maxSimultaneousLights });
             }
             if (!this._effect.isReady()) {
                 return false;
@@ -848,7 +845,7 @@ var BABYLON;
                     }
                     if (this.ambientTexture && BABYLON.StandardMaterial.AmbientTextureEnabled) {
                         this._effect.setTexture("ambientSampler", this.ambientTexture);
-                        this._effect.setFloat2("vAmbientInfos", this.ambientTexture.coordinatesIndex, this.ambientTexture.level);
+                        this._effect.setFloat3("vAmbientInfos", this.ambientTexture.coordinatesIndex, this.ambientTexture.level, this.ambientTextureStrength);
                         this._effect.setMatrix("ambientMatrix", this.ambientTexture.getTextureMatrix());
                     }
                     if (this.opacityTexture && BABYLON.StandardMaterial.OpacityTextureEnabled) {
@@ -1155,6 +1152,9 @@ var BABYLON;
             BABYLON.serializeAsTexture()
         ], PBRMaterial.prototype, "ambientTexture", void 0);
         __decorate([
+            BABYLON.serialize()
+        ], PBRMaterial.prototype, "ambientTextureStrength", void 0);
+        __decorate([
             BABYLON.serializeAsTexture()
         ], PBRMaterial.prototype, "opacityTexture", void 0);
         __decorate([

+ 99 - 100
src/Materials/babylon.pbrMaterial.ts

@@ -261,6 +261,12 @@
         @serializeAsTexture()
         public ambientTexture: BaseTexture;
 
+        /**
+         * AKA Occlusion Texture Intensity in other nomenclature.
+         */
+        @serialize()
+        public ambientTextureStrength: number = 1.0;
+
         @serializeAsTexture()
         public opacityTexture: BaseTexture;
 
@@ -613,120 +619,117 @@
             this._defines.reset();
 
             if (scene.texturesEnabled) {
-                // Textures
-                if (scene.texturesEnabled) {
-                    if (scene.getEngine().getCaps().textureLOD) {
-                        this._defines.LODBASEDMICROSFURACE = true;
-                    }
+                if (scene.getEngine().getCaps().textureLOD) {
+                    this._defines.LODBASEDMICROSFURACE = true;
+                }
 
-                    if (this.albedoTexture && StandardMaterial.DiffuseTextureEnabled) {
-                        if (!this.albedoTexture.isReady()) {
-                            return false;
-                        } else {
-                            needUVs = true;
-                            this._defines.ALBEDO = true;
-                        }
+                if (this.albedoTexture && StandardMaterial.DiffuseTextureEnabled) {
+                    if (!this.albedoTexture.isReady()) {
+                        return false;
+                    } else {
+                        needUVs = true;
+                        this._defines.ALBEDO = true;
                     }
+                }
 
-                    if (this.ambientTexture && StandardMaterial.AmbientTextureEnabled) {
-                        if (!this.ambientTexture.isReady()) {
-                            return false;
-                        } else {
-                            needUVs = true;
-                            this._defines.AMBIENT = true;
-                        }
+                if (this.ambientTexture && StandardMaterial.AmbientTextureEnabled) {
+                    if (!this.ambientTexture.isReady()) {
+                        return false;
+                    } else {
+                        needUVs = true;
+                        this._defines.AMBIENT = true;
                     }
+                }
 
-                    if (this.opacityTexture && StandardMaterial.OpacityTextureEnabled) {
-                        if (!this.opacityTexture.isReady()) {
-                            return false;
-                        } else {
-                            needUVs = true;
-                            this._defines.OPACITY = true;
+                if (this.opacityTexture && StandardMaterial.OpacityTextureEnabled) {
+                    if (!this.opacityTexture.isReady()) {
+                        return false;
+                    } else {
+                        needUVs = true;
+                        this._defines.OPACITY = true;
 
-                            if (this.opacityTexture.getAlphaFromRGB) {
-                                this._defines.OPACITYRGB = true;
-                            }
+                        if (this.opacityTexture.getAlphaFromRGB) {
+                            this._defines.OPACITYRGB = true;
                         }
                     }
+                }
 
-                    if (this.reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
-                        if (!this.reflectionTexture.isReady()) {
-                            return false;
-                        } else {
-                            needNormals = true;
-                            this._defines.REFLECTION = true;
+                if (this.reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
+                    if (!this.reflectionTexture.isReady()) {
+                        return false;
+                    } else {
+                        needNormals = true;
+                        this._defines.REFLECTION = true;
 
-                            if (this.reflectionTexture.coordinatesMode === Texture.INVCUBIC_MODE) {
-                                this._defines.INVERTCUBICMAP = true;
-                            }
+                        if (this.reflectionTexture.coordinatesMode === Texture.INVCUBIC_MODE) {
+                            this._defines.INVERTCUBICMAP = true;
+                        }
 
-                            this._defines.REFLECTIONMAP_3D = this.reflectionTexture.isCube;
-
-                            switch (this.reflectionTexture.coordinatesMode) {
-                                case Texture.CUBIC_MODE:
-                                case Texture.INVCUBIC_MODE:
-                                    this._defines.REFLECTIONMAP_CUBIC = true;
-                                    break;
-                                case Texture.EXPLICIT_MODE:
-                                    this._defines.REFLECTIONMAP_EXPLICIT = true;
-                                    break;
-                                case Texture.PLANAR_MODE:
-                                    this._defines.REFLECTIONMAP_PLANAR = true;
-                                    break;
-                                case Texture.PROJECTION_MODE:
-                                    this._defines.REFLECTIONMAP_PROJECTION = true;
-                                    break;
-                                case Texture.SKYBOX_MODE:
-                                    this._defines.REFLECTIONMAP_SKYBOX = true;
-                                    break;
-                                case Texture.SPHERICAL_MODE:
-                                    this._defines.REFLECTIONMAP_SPHERICAL = true;
-                                    break;
-                                case Texture.EQUIRECTANGULAR_MODE:
-                                    this._defines.REFLECTIONMAP_EQUIRECTANGULAR = true;
-                                    break;
-                            }
+                        this._defines.REFLECTIONMAP_3D = this.reflectionTexture.isCube;
+
+                        switch (this.reflectionTexture.coordinatesMode) {
+                            case Texture.CUBIC_MODE:
+                            case Texture.INVCUBIC_MODE:
+                                this._defines.REFLECTIONMAP_CUBIC = true;
+                                break;
+                            case Texture.EXPLICIT_MODE:
+                                this._defines.REFLECTIONMAP_EXPLICIT = true;
+                                break;
+                            case Texture.PLANAR_MODE:
+                                this._defines.REFLECTIONMAP_PLANAR = true;
+                                break;
+                            case Texture.PROJECTION_MODE:
+                                this._defines.REFLECTIONMAP_PROJECTION = true;
+                                break;
+                            case Texture.SKYBOX_MODE:
+                                this._defines.REFLECTIONMAP_SKYBOX = true;
+                                break;
+                            case Texture.SPHERICAL_MODE:
+                                this._defines.REFLECTIONMAP_SPHERICAL = true;
+                                break;
+                            case Texture.EQUIRECTANGULAR_MODE:
+                                this._defines.REFLECTIONMAP_EQUIRECTANGULAR = true;
+                                break;
+                        }
 
-                            if (this.reflectionTexture instanceof HDRCubeTexture && (<HDRCubeTexture>this.reflectionTexture)) {
-                                this._defines.USESPHERICALFROMREFLECTIONMAP = true;
-                                needNormals = true;
+                        if (this.reflectionTexture instanceof HDRCubeTexture && (<HDRCubeTexture>this.reflectionTexture)) {
+                            this._defines.USESPHERICALFROMREFLECTIONMAP = true;
+                            needNormals = true;
 
-                                if ((<HDRCubeTexture>this.reflectionTexture).isPMREM) {
-                                    this._defines.USEPMREMREFLECTION = true;
-                                }
+                            if ((<HDRCubeTexture>this.reflectionTexture).isPMREM) {
+                                this._defines.USEPMREMREFLECTION = true;
                             }
                         }
                     }
+                }
 
-                    if (this.lightmapTexture && StandardMaterial.LightmapTextureEnabled) {
-                        if (!this.lightmapTexture.isReady()) {
-                            return false;
-                        } else {
-                            needUVs = true;
-                            this._defines.LIGHTMAP = true;
-                            this._defines.USELIGHTMAPASSHADOWMAP = this.useLightmapAsShadowmap;
-                        }
+                if (this.lightmapTexture && StandardMaterial.LightmapTextureEnabled) {
+                    if (!this.lightmapTexture.isReady()) {
+                        return false;
+                    } else {
+                        needUVs = true;
+                        this._defines.LIGHTMAP = true;
+                        this._defines.USELIGHTMAPASSHADOWMAP = this.useLightmapAsShadowmap;
                     }
+                }
 
-                    if (this.emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {
-                        if (!this.emissiveTexture.isReady()) {
-                            return false;
-                        } else {
-                            needUVs = true;
-                            this._defines.EMISSIVE = true;
-                        }
+                if (this.emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {
+                    if (!this.emissiveTexture.isReady()) {
+                        return false;
+                    } else {
+                        needUVs = true;
+                        this._defines.EMISSIVE = true;
                     }
+                }
 
-                    if (this.reflectivityTexture && StandardMaterial.SpecularTextureEnabled) {
-                        if (!this.reflectivityTexture.isReady()) {
-                            return false;
-                        } else {
-                            needUVs = true;
-                            this._defines.REFLECTIVITY = true;
-                            this._defines.MICROSURFACEFROMREFLECTIVITYMAP = this.useMicroSurfaceFromReflectivityMapAlpha;
-                            this._defines.MICROSURFACEAUTOMATIC = this.useAutoMicroSurfaceFromReflectivityMap;
-                        }
+                if (this.reflectivityTexture && StandardMaterial.SpecularTextureEnabled) {
+                    if (!this.reflectivityTexture.isReady()) {
+                        return false;
+                    } else {
+                        needUVs = true;
+                        this._defines.REFLECTIVITY = true;
+                        this._defines.MICROSURFACEFROMREFLECTIVITYMAP = this.useMicroSurfaceFromReflectivityMapAlpha;
+                        this._defines.MICROSURFACEAUTOMATIC = this.useAutoMicroSurfaceFromReflectivityMap;
                     }
                 }
 
@@ -737,7 +740,7 @@
                         needUVs = true;
                         this._defines.BUMP = true;
 
-                        if (this.useParallax) {
+                        if (this.useParallax && this.albedoTexture && StandardMaterial.DiffuseTextureEnabled) {
                             this._defines.PARALLAX = true;
                             if (this.useParallaxOcclusion) {
                                 this._defines.PARALLAXOCCLUSION = true;
@@ -1003,10 +1006,6 @@
                 MaterialHelper.PrepareAttributesForInstances(attribs, this._defines);
 
                 // Legacy browser patch
-                var shaderName = "pbr";
-                if (!scene.getEngine().getCaps().standardDerivatives) {
-                    shaderName = "legacypbr";
-                }
                 var join = this._defines.toString();
                 
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vAlbedoColor", "vReflectivityColor", "vEmissiveColor", "vReflectionColor",
@@ -1031,7 +1030,7 @@
                 ColorGradingTexture.PrepareUniformsAndSamplers(uniforms, samplers); 
                 MaterialHelper.PrepareUniformsAndSamplersList(uniforms, samplers, this._defines, this.maxSimultaneousLights); 
                 
-                this._effect = scene.getEngine().createEffect(shaderName,
+                this._effect = scene.getEngine().createEffect("pbr",
                     attribs, uniforms, samplers,
                     join, fallbacks, this.onCompiled, this.onError, {maxSimultaneousLights: this.maxSimultaneousLights});
             }
@@ -1108,7 +1107,7 @@
                     if (this.ambientTexture && StandardMaterial.AmbientTextureEnabled) {
                         this._effect.setTexture("ambientSampler", this.ambientTexture);
 
-                        this._effect.setFloat2("vAmbientInfos", this.ambientTexture.coordinatesIndex, this.ambientTexture.level);
+                        this._effect.setFloat3("vAmbientInfos", this.ambientTexture.coordinatesIndex, this.ambientTexture.level, this.ambientTextureStrength);
                         this._effect.setMatrix("ambientMatrix", this.ambientTexture.getTextureMatrix());
                     }
 

+ 6 - 3
src/Math/babylon.math.ts

@@ -1074,9 +1074,12 @@
         }
 
         public static TransformNormalToRef(vector: Vector3, transformation: Matrix, result: Vector3): void {
-            result.x = (vector.x * transformation.m[0]) + (vector.y * transformation.m[4]) + (vector.z * transformation.m[8]);
-            result.y = (vector.x * transformation.m[1]) + (vector.y * transformation.m[5]) + (vector.z * transformation.m[9]);
-            result.z = (vector.x * transformation.m[2]) + (vector.y * transformation.m[6]) + (vector.z * transformation.m[10]);
+            var x = (vector.x * transformation.m[0]) + (vector.y * transformation.m[4]) + (vector.z * transformation.m[8]);
+            var y = (vector.x * transformation.m[1]) + (vector.y * transformation.m[5]) + (vector.z * transformation.m[9]);
+            var z = (vector.x * transformation.m[2]) + (vector.y * transformation.m[6]) + (vector.z * transformation.m[10]);
+            result.x = x;
+            result.y = y;
+            result.z = z;
         }
 
         public static TransformNormalFromFloatsToRef(x: number, y: number, z: number, transformation: Matrix, result: Vector3): void {

+ 1 - 1
src/Mesh/babylon.mesh.js

@@ -968,7 +968,7 @@ var BABYLON;
                 engine.setAlphaMode(effectiveMaterial.alphaMode);
             }
             // Draw
-            this._processRendering(subMesh, effect, fillMode, batch, hardwareInstancedRendering, this._onBeforeDraw);
+            this._processRendering(subMesh, effect, fillMode, batch, hardwareInstancedRendering, this._onBeforeDraw, effectiveMaterial);
             // Unbind
             effectiveMaterial.unbind();
             // Outline - step 2

+ 1 - 1
src/Mesh/babylon.mesh.ts

@@ -1067,7 +1067,7 @@
             }
 
             // Draw
-            this._processRendering(subMesh, effect, fillMode, batch, hardwareInstancedRendering, this._onBeforeDraw);
+            this._processRendering(subMesh, effect, fillMode, batch, hardwareInstancedRendering, this._onBeforeDraw, effectiveMaterial);
 
             // Unbind
             effectiveMaterial.unbind();

+ 5 - 10
src/Shaders/ShadersInclude/bumpFragment.fx

@@ -1,24 +1,19 @@
-#ifdef BUMP
-	vec2 bumpUV = vBumpUV;
-#endif
+vec2 uvOffset = vec2(0.0, 0.0);
 
 #if defined(BUMP) || defined(PARALLAX)
-	mat3 TBN = cotangent_frame(normalW * vBumpInfos.y, -viewDirectionW, bumpUV);
+	mat3 TBN = cotangent_frame(normalW * vBumpInfos.y, -viewDirectionW, vBumpUV);
 #endif
 
 #ifdef PARALLAX
 	mat3 invTBN = transposeMat3(TBN);
 
 	#ifdef PARALLAXOCCLUSION
-		vec2 uvOffset = parallaxOcclusion(invTBN * -viewDirectionW, invTBN * normalW, bumpUV, vBumpInfos.z);
+		uvOffset = parallaxOcclusion(invTBN * -viewDirectionW, invTBN * normalW, vBumpUV, vBumpInfos.z);
 	#else
-		vec2 uvOffset = parallaxOffset(invTBN * viewDirectionW, vBumpInfos.z);
+		uvOffset = parallaxOffset(invTBN * viewDirectionW, vBumpInfos.z);
 	#endif
-
-	diffuseUV += uvOffset;
-	bumpUV += uvOffset;
 #endif
 
 #ifdef BUMP
-	normalW = perturbNormal(viewDirectionW, TBN, bumpUV);
+	normalW = perturbNormal(viewDirectionW, TBN, vBumpUV + uvOffset);
 #endif

+ 6 - 10
src/Shaders/default.fragment.fx

@@ -176,14 +176,10 @@ void main(void) {
 	vec3 normalW = vec3(1.0, 1.0, 1.0);
 #endif
 
-#ifdef DIFFUSE
-	vec2 diffuseUV = vDiffuseUV;
-#endif
-
 #include<bumpFragment>
 
 #ifdef DIFFUSE
-	baseColor = texture2D(diffuseSampler, diffuseUV);
+	baseColor = texture2D(diffuseSampler, vDiffuseUV + uvOffset);
 
 #ifdef ALPHATEST
 	if (baseColor.a < 0.4)
@@ -205,7 +201,7 @@ void main(void) {
 	vec3 baseAmbientColor = vec3(1., 1., 1.);
 
 #ifdef AMBIENT
-	baseAmbientColor = texture2D(ambientSampler, vAmbientUV).rgb * vAmbientInfos.y;
+	baseAmbientColor = texture2D(ambientSampler, vAmbientUV + uvOffset).rgb * vAmbientInfos.y;
 #endif
 
 	// Specular map
@@ -214,7 +210,7 @@ void main(void) {
 	vec3 specularColor = vSpecularColor.rgb;
 
 #ifdef SPECULAR
-	vec4 specularMapColor = texture2D(specularSampler, vSpecularUV);
+	vec4 specularMapColor = texture2D(specularSampler, vSpecularUV + uvOffset);
 	specularColor = specularMapColor.rgb;
 #ifdef GLOSSINESS
 	glossiness = glossiness * specularMapColor.a;
@@ -233,7 +229,7 @@ void main(void) {
 	float shadow = 1.;
 
 #ifdef LIGHTMAP
-	vec3 lightmapColor = texture2D(lightmapSampler, vLightmapUV).rgb * vLightmapInfos.y;
+	vec3 lightmapColor = texture2D(lightmapSampler, vLightmapUV + uvOffset).rgb * vLightmapInfos.y;
 #endif
 
 #include<lightFragment>[0..maxSimultaneousLights]
@@ -319,7 +315,7 @@ void main(void) {
 #endif
 
 #ifdef OPACITY
-	vec4 opacityMap = texture2D(opacitySampler, vOpacityUV);
+	vec4 opacityMap = texture2D(opacitySampler, vOpacityUV + uvOffset);
 
 #ifdef OPACITYRGB
 	opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11);
@@ -343,7 +339,7 @@ void main(void) {
 	// Emissive
 	vec3 emissiveColor = vEmissiveColor;
 #ifdef EMISSIVE
-	emissiveColor += texture2D(emissiveSampler, vEmissiveUV).rgb * vEmissiveInfos.y;
+	emissiveColor += texture2D(emissiveSampler, vEmissiveUV + uvOffset).rgb * vEmissiveInfos.y;
 #endif
 
 #ifdef EMISSIVEFRESNEL

+ 0 - 226
src/Shaders/legacydefault.fragment.fx

@@ -1,226 +0,0 @@
-#define MAP_PROJECTION	4.
-
-// Constants
-uniform vec3 vEyePosition;
-uniform vec3 vAmbientColor;
-uniform vec4 vDiffuseColor;
-#ifdef SPECULARTERM
-uniform vec4 vSpecularColor;
-#endif
-uniform vec3 vEmissiveColor;
-
-// Input
-varying vec3 vPositionW;
-varying vec3 vNormalW;
-
-#ifdef VERTEXCOLOR
-varying vec4 vColor;
-#endif
-
-// Lights
-#include<lightFragmentDeclaration>[0..3]
-
-#include<lightsFragmentFunctions>
-#include<shadowsFragmentFunctions>
-
-// Samplers
-#ifdef DIFFUSE
-varying vec2 vDiffuseUV;
-uniform sampler2D diffuseSampler;
-uniform vec2 vDiffuseInfos;
-#endif
-
-#ifdef AMBIENT
-varying vec2 vAmbientUV;
-uniform sampler2D ambientSampler;
-uniform vec2 vAmbientInfos;
-#endif
-
-#ifdef OPACITY	
-varying vec2 vOpacityUV;
-uniform sampler2D opacitySampler;
-uniform vec2 vOpacityInfos;
-#endif
-
-#ifdef REFLECTION
-varying vec3 vReflectionUVW;
-#ifdef REFLECTIONMAP_3D
-uniform samplerCube reflectionCubeSampler;
-#else
-uniform sampler2D reflection2DSampler;
-#endif
-uniform vec2 vReflectionInfos;
-#endif
-
-#ifdef EMISSIVE
-varying vec2 vEmissiveUV;
-uniform vec2 vEmissiveInfos;
-uniform sampler2D emissiveSampler;
-#endif
-
-#if defined(SPECULAR) && defined(SPECULARTERM)
-varying vec2 vSpecularUV;
-uniform vec2 vSpecularInfos;
-uniform sampler2D specularSampler;
-#endif
-
-// Fresnel
-#include<fresnelFunction>
-
-#ifdef DIFFUSEFRESNEL
-uniform vec4 diffuseLeftColor;
-uniform vec4 diffuseRightColor;
-#endif
-
-#ifdef OPACITYFRESNEL
-uniform vec4 opacityParts;
-#endif
-
-#ifdef REFLECTIONFRESNEL
-uniform vec4 reflectionLeftColor;
-uniform vec4 reflectionRightColor;
-#endif
-
-#ifdef EMISSIVEFRESNEL
-uniform vec4 emissiveLeftColor;
-uniform vec4 emissiveRightColor;
-#endif
-
-#include<clipPlaneFragmentDeclaration>
-#include<fogFragmentDeclaration>
-
-void main(void) {
-#include<clipPlaneFragment>
-
-	vec3 viewDirectionW = normalize(vEyePosition - vPositionW);
-
-	// Base color
-	vec4 baseColor = vec4(1., 1., 1., 1.);
-	vec3 diffuseColor = vDiffuseColor.rgb;
-
-#ifdef DIFFUSE
-	baseColor = texture2D(diffuseSampler, vDiffuseUV);
-
-#ifdef ALPHATEST
-	if (baseColor.a < 0.4)
-		discard;
-#endif
-
-	baseColor.rgb *= vDiffuseInfos.y;
-#endif
-
-#ifdef VERTEXCOLOR
-	baseColor.rgb *= vColor.rgb;
-#endif
-
-	// Bump
-	vec3 normalW = normalize(vNormalW);
-
-	// Ambient color
-	vec3 baseAmbientColor = vec3(1., 1., 1.);
-
-#ifdef AMBIENT
-	baseAmbientColor = texture2D(ambientSampler, vAmbientUV).rgb * vAmbientInfos.y;
-#endif
-
-	// Lighting
-	vec3 diffuseBase = vec3(0., 0., 0.);
-	lightingInfo info;
-	float glossiness = 0.;
-#ifdef SPECULARTERM
-	vec3 specularBase = vec3(0., 0., 0.);
-	glossiness = vSpecularColor.a;
-#endif
-	float shadow = 1.;
-
-#include<lightFragment>[0..3]
-
-	// Reflection
-	vec3 reflectionColor = vec3(0., 0., 0.);
-
-#ifdef REFLECTION
-#ifdef REFLECTIONMAP_3D
-		reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW).rgb * vReflectionInfos.x;
-#else
-		vec2 coords = vReflectionUVW.xy;
-
-#ifdef REFLECTIONMAP_PROJECTION
-		coords /= vReflectionUVW.z;
-#endif
-
-		coords.y = 1.0 - coords.y;
-
-		reflectionColor = texture2D(reflection2DSampler, coords).rgb * vReflectionInfos.x;
-#endif
-
-#ifdef REFLECTIONFRESNEL
-	float reflectionFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, reflectionRightColor.a, reflectionLeftColor.a);
-
-	reflectionColor *= reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;
-#endif
-#endif
-
-	// Alpha
-	float alpha = vDiffuseColor.a;
-
-#ifdef OPACITY
-	vec4 opacityMap = texture2D(opacitySampler, vOpacityUV);
-#ifdef OPACITYRGB
-	opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11);
-	alpha *= (opacityMap.x + opacityMap.y + opacityMap.z)* vOpacityInfos.y;
-#else
-	alpha *= opacityMap.a * vOpacityInfos.y;
-#endif
-#endif
-
-#ifdef VERTEXALPHA
-	alpha *= vColor.a;
-#endif
-
-#ifdef OPACITYFRESNEL
-	float opacityFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, opacityParts.z, opacityParts.w);
-
-	alpha += opacityParts.x * (1.0 - opacityFresnelTerm) + opacityFresnelTerm * opacityParts.y;
-#endif
-
-	// Emissive
-	vec3 emissiveColor = vEmissiveColor;
-#ifdef EMISSIVE
-	emissiveColor += texture2D(emissiveSampler, vEmissiveUV).rgb * vEmissiveInfos.y;
-#endif
-
-#ifdef EMISSIVEFRESNEL
-	float emissiveFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, emissiveRightColor.a, emissiveLeftColor.a);
-
-	emissiveColor *= emissiveLeftColor.rgb * (1.0 - emissiveFresnelTerm) + emissiveFresnelTerm * emissiveRightColor.rgb;
-#endif
-
-	// Specular map
-#ifdef SPECULARTERM
-	vec3 specularColor = vSpecularColor.rgb;
-#ifdef SPECULAR
-	specularColor = texture2D(specularSampler, vSpecularUV).rgb * vSpecularInfos.y;
-#endif
-#endif
-
-	// Fresnel
-#ifdef DIFFUSEFRESNEL
-	float diffuseFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, diffuseRightColor.a, diffuseLeftColor.a);
-
-	diffuseBase *= diffuseLeftColor.rgb * (1.0 - diffuseFresnelTerm) + diffuseFresnelTerm * diffuseRightColor.rgb;
-#endif
-
-	// Composition
-	vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + emissiveColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;
-#ifdef SPECULARTERM
-	vec3 finalSpecular = specularBase * specularColor;
-#else
-	vec3 finalSpecular = vec3(0.0);
-#endif
-
-	vec4 color = vec4(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor, alpha);
-
-#include<fogFragment>
-
-	gl_FragColor = color;
-}

+ 0 - 208
src/Shaders/legacydefault.vertex.fx

@@ -1,208 +0,0 @@
-// Attributes
-attribute vec3 position;
-attribute vec3 normal;
-#ifdef UV1
-attribute vec2 uv;
-#endif
-#ifdef UV2
-attribute vec2 uv2;
-#endif
-#ifdef VERTEXCOLOR
-attribute vec4 color;
-#endif
-#include<bonesDeclaration>
-
-// Uniforms
-uniform mat4 world;
-uniform mat4 view;
-uniform mat4 viewProjection;
-
-#ifdef DIFFUSE
-varying vec2 vDiffuseUV;
-uniform mat4 diffuseMatrix;
-uniform vec2 vDiffuseInfos;
-#endif
-
-#ifdef AMBIENT
-varying vec2 vAmbientUV;
-uniform mat4 ambientMatrix;
-uniform vec2 vAmbientInfos;
-#endif
-
-#ifdef OPACITY
-varying vec2 vOpacityUV;
-uniform mat4 opacityMatrix;
-uniform vec2 vOpacityInfos;
-#endif
-
-#ifdef EMISSIVE
-varying vec2 vEmissiveUV;
-uniform vec2 vEmissiveInfos;
-uniform mat4 emissiveMatrix;
-#endif
-
-#if defined(SPECULAR) && defined(SPECULARTERM)
-varying vec2 vSpecularUV;
-uniform vec2 vSpecularInfos;
-uniform mat4 specularMatrix;
-#endif
-
-#ifdef BUMP
-varying vec2 vBumpUV;
-uniform vec2 vBumpInfos;
-uniform mat4 bumpMatrix;
-#endif
-
-// Output
-varying vec3 vPositionW;
-varying vec3 vNormalW;
-
-#ifdef VERTEXCOLOR
-varying vec4 vColor;
-#endif
-
-#include<clipPlaneVertexDeclaration>
-#include<fogVertexDeclaration>
-#include<shadowsVertexDeclaration>[0..maxSimultaneousLights]
-
-#ifdef REFLECTION
-uniform vec3 vEyePosition;
-varying vec3 vReflectionUVW;
-uniform mat4 reflectionMatrix;
-
-vec3 computeReflectionCoords(vec4 worldPos, vec3 worldNormal)
-{
-#ifdef REFLECTIONMAP_SPHERICAL
-	vec3 coords = vec3(view * vec4(worldNormal, 0.0));
-
-	return vec3(reflectionMatrix * vec4(coords, 1.0));
-#endif
-
-#ifdef REFLECTIONMAP_PLANAR
-	vec3 viewDir = worldPos.xyz - vEyePosition;
-	vec3 coords = normalize(reflect(viewDir, worldNormal));
-
-	return vec3(reflectionMatrix * vec4(coords, 1));
-#endif
-
-#ifdef REFLECTIONMAP_CUBIC
-	vec3 viewDir = worldPos.xyz - vEyePosition;
-	vec3 coords = reflect(viewDir, worldNormal);
-#ifdef INVERTCUBICMAP
-	coords.y = 1.0 - coords.y;
-#endif
-	return vec3(reflectionMatrix * vec4(coords, 0));
-#endif
-
-#ifdef REFLECTIONMAP_PROJECTION
-	return vec3(reflectionMatrix * (view * worldPos));
-#endif
-
-#ifdef REFLECTIONMAP_SKYBOX
-	return position;
-#endif
-
-#ifdef REFLECTIONMAP_EXPLICIT
-	return vec3(0, 0, 0);
-#endif
-}
-#endif
-
-void main(void) {
-	mat4 finalWorld = world;
-
-#include<bonesVertex>
-
-	gl_Position = viewProjection * finalWorld * vec4(position, 1.0);
-
-	vec4 worldPos = finalWorld * vec4(position, 1.0);
-	vPositionW = vec3(worldPos);
-	vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));
-
-	// Texture coordinates
-#ifndef UV1
-	vec2 uv = vec2(0., 0.);
-#endif
-#ifndef UV2
-	vec2 uv2 = vec2(0., 0.);
-#endif
-
-#ifdef DIFFUSE
-	if (vDiffuseInfos.x == 0.)
-	{
-		vDiffuseUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));
-	}
-	else
-	{
-		vDiffuseUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));
-	}
-#endif
-
-#ifdef AMBIENT
-	if (vAmbientInfos.x == 0.)
-	{
-		vAmbientUV = vec2(ambientMatrix * vec4(uv, 1.0, 0.0));
-	}
-	else
-	{
-		vAmbientUV = vec2(ambientMatrix * vec4(uv2, 1.0, 0.0));
-	}
-#endif
-
-#ifdef OPACITY
-	if (vOpacityInfos.x == 0.)
-	{
-		vOpacityUV = vec2(opacityMatrix * vec4(uv, 1.0, 0.0));
-	}
-	else
-	{
-		vOpacityUV = vec2(opacityMatrix * vec4(uv2, 1.0, 0.0));
-	}
-#endif
-	
-#ifdef REFLECTION
-	vReflectionUVW = computeReflectionCoords(vec4(vPositionW, 1.0), vNormalW);
-#endif
-
-#ifdef EMISSIVE
-	if (vEmissiveInfos.x == 0.)
-	{
-		vEmissiveUV = vec2(emissiveMatrix * vec4(uv, 1.0, 0.0));
-	}
-	else
-	{
-		vEmissiveUV = vec2(emissiveMatrix * vec4(uv2, 1.0, 0.0));
-	}
-#endif
-
-#if defined(SPECULAR) && defined(SPECULARTERM)
-	if (vSpecularInfos.x == 0.)
-	{
-		vSpecularUV = vec2(specularMatrix * vec4(uv, 1.0, 0.0));
-	}
-	else
-	{
-		vSpecularUV = vec2(specularMatrix * vec4(uv2, 1.0, 0.0));
-	}
-#endif
-
-#ifdef BUMP
-	if (vBumpInfos.x == 0.)
-	{
-		vBumpUV = vec2(bumpMatrix * vec4(uv, 1.0, 0.0));
-	}
-	else
-	{
-		vBumpUV = vec2(bumpMatrix * vec4(uv2, 1.0, 0.0));
-	}
-#endif
-
-#include<clipPlaneVertex>
-#include<fogVertex>
-#include<shadowsVertex>[0..maxSimultaneousLights]
-
-	// Vertex color
-#ifdef VERTEXCOLOR
-	vColor = color;
-#endif
-}

+ 0 - 331
src/Shaders/legacypbr.fragment.fx

@@ -1,331 +0,0 @@
-precision mediump float;
-
-// Constants
-#define RECIPROCAL_PI2 0.15915494
-#define FRESNEL_MAXIMUM_ON_ROUGH 0.25
-
-uniform vec3 vEyePosition;
-uniform vec3 vAmbientColor;
-uniform vec4 vAlbedoColor;
-uniform vec3 vReflectionColor;
-
-// CUSTOM CONTROLS
-uniform vec4 vLightingIntensity;
-uniform vec4 vCameraInfos;
-
-#ifdef OVERLOADEDVALUES
-uniform vec4 vOverloadedIntensity;
-uniform vec3 vOverloadedAmbient;
-uniform vec3 vOverloadedAlbedo;
-uniform vec3 vOverloadedReflectivity;
-uniform vec3 vOverloadedEmissive;
-uniform vec3 vOverloadedReflection;
-uniform vec3 vOverloadedMicroSurface;
-#endif
-
-#ifdef OVERLOADEDSHADOWVALUES
-uniform vec4 vOverloadedShadowIntensity;
-#endif
-
-uniform vec4 vReflectivityColor;
-uniform vec3 vEmissiveColor;
-
-// Input
-varying vec3 vPositionW;
-
-#ifdef NORMAL
-varying vec3 vNormalW;
-#endif
-
-#ifdef VERTEXCOLOR
-varying vec4 vColor;
-#endif
-
-// Lights
-#include<lightFragmentDeclaration>[0..maxSimultaneousLights]
-
-// Samplers
-#ifdef ALBEDO
-varying vec2 vAlbedoUV;
-uniform sampler2D albedoSampler;
-uniform vec2 vAlbedoInfos;
-#endif
-
-#ifdef AMBIENT
-varying vec2 vAmbientUV;
-uniform sampler2D ambientSampler;
-uniform vec2 vAmbientInfos;
-#endif
-
-#ifdef OPACITY	
-varying vec2 vOpacityUV;
-uniform sampler2D opacitySampler;
-uniform vec2 vOpacityInfos;
-#endif
-
-#ifdef EMISSIVE
-varying vec2 vEmissiveUV;
-uniform vec2 vEmissiveInfos;
-uniform sampler2D emissiveSampler;
-#endif
-
-#ifdef LIGHTMAP
-varying vec2 vLightmapUV;
-uniform vec2 vLightmapInfos;
-uniform sampler2D lightmapSampler;
-#endif
-
-#if defined(REFLECTIVITY)
-varying vec2 vReflectivityUV;
-uniform vec2 vReflectivityInfos;
-uniform sampler2D reflectivitySampler;
-#endif
-
-#include<clipPlaneFragmentDeclaration>
-
-#ifdef CAMERACOLORGRADING
-    uniform sampler2D cameraColorGrading2DSampler;
-    uniform vec4 vCameraColorGradingInfos;
-    uniform vec4 vCameraColorGradingScaleOffset;
-#endif
-
-// PBR
-#include<pbrFunctions>
-#include<harmonicsFunctions>
-#include<pbrLightFunctions>
-
-void main(void) {
-#include<clipPlaneFragment>
-
-    vec3 viewDirectionW = normalize(vEyePosition - vPositionW);
-
-    // Base color
-    vec4 surfaceAlbedo = vec4(1., 1., 1., 1.);
-    vec3 surfaceAlbedoContribution = vAlbedoColor.rgb;
-    
-    // Alpha
-    float alpha = vAlbedoColor.a;
-
-    #ifdef ALBEDO
-        surfaceAlbedo = texture2D(albedoSampler, vAlbedoUV);
-        surfaceAlbedo = vec4(toLinearSpace(surfaceAlbedo.rgb), surfaceAlbedo.a);
-
-        #ifdef ALPHATEST
-            if (baseColor.a < 0.4)
-                discard;
-        #endif
-
-        #ifdef ALPHAFROMALBEDO
-            alpha *= surfaceAlbedo.a;
-        #endif
-
-        surfaceAlbedo.rgb *= vAlbedoInfos.y;
-    #else
-        // No Albedo texture.
-        surfaceAlbedo.rgb = surfaceAlbedoContribution;
-        surfaceAlbedoContribution = vec3(1., 1., 1.);
-    #endif
-
-    #ifdef VERTEXCOLOR
-        baseColor.rgb *= vColor.rgb;
-    #endif
-
-    #ifdef OVERLOADEDVALUES
-        surfaceAlbedo.rgb = mix(surfaceAlbedo.rgb, vOverloadedAlbedo, vOverloadedIntensity.y);
-    #endif
-
-    // Bump
-    #ifdef NORMAL
-        vec3 normalW = normalize(vNormalW);
-    #else
-        vec3 normalW = vec3(1.0, 1.0, 1.0);
-    #endif
-
-    // Ambient color
-    vec3 ambientColor = vec3(1., 1., 1.);
-
-    #ifdef AMBIENT
-        ambientColor = texture2D(ambientSampler, vAmbientUV).rgb * vAmbientInfos.y;
-        
-        #ifdef OVERLOADEDVALUES
-            ambientColor.rgb = mix(ambientColor.rgb, vOverloadedAmbient, vOverloadedIntensity.x);
-        #endif
-    #endif
-
-    // Reflectivity map
-    float microSurface = vReflectivityColor.a;
-    vec3 surfaceReflectivityColor = vReflectivityColor.rgb;
-    
-    #ifdef OVERLOADEDVALUES
-        surfaceReflectivityColor.rgb = mix(surfaceReflectivityColor.rgb, vOverloadedReflectivity, vOverloadedIntensity.z);
-    #endif
-
-    #ifdef REFLECTIVITY
-        vec4 surfaceReflectivityColorMap = texture2D(reflectivitySampler, vReflectivityUV);
-        surfaceReflectivityColor = surfaceReflectivityColorMap.rgb;
-        surfaceReflectivityColor = toLinearSpace(surfaceReflectivityColor);
-
-        #ifdef OVERLOADEDVALUES
-            surfaceReflectivityColor = mix(surfaceReflectivityColor, vOverloadedReflectivity, vOverloadedIntensity.z);
-        #endif
-
-        #ifdef MICROSURFACEFROMREFLECTIVITYMAP
-            microSurface = surfaceReflectivityColorMap.a;
-        #else
-            #ifdef MICROSURFACEAUTOMATIC
-                microSurface = computeDefaultMicroSurface(microSurface, surfaceReflectivityColor);
-            #endif
-        #endif
-    #endif
-
-    #ifdef OVERLOADEDVALUES
-        microSurface = mix(microSurface, vOverloadedMicroSurface.x, vOverloadedMicroSurface.y);
-    #endif
-
-    // Compute N dot V.
-    float NdotV = max(0.00000000001, dot(normalW, viewDirectionW));
-
-    // Adapt microSurface.
-    microSurface = clamp(microSurface, 0., 1.) * 0.98;
-
-    // Compute roughness.
-    float roughness = clamp(1. - microSurface, 0.000001, 1.0);
-    
-    // Lighting
-    vec3 lightDiffuseContribution = vec3(0., 0., 0.);
-
-#ifdef OVERLOADEDSHADOWVALUES
-    vec3 shadowedOnlyLightDiffuseContribution = vec3(1., 1., 1.);
-#endif
-
-#ifdef SPECULARTERM
-    vec3 lightSpecularContribution= vec3(0., 0., 0.);
-#endif
-    float notShadowLevel = 1.; // 1 - shadowLevel
-    float NdotL = -1.;
-    lightingInfo info;
-
-#include<pbrLightFunctionsCall>[0..maxSimultaneousLights]
-
-#ifdef SPECULARTERM
-    lightSpecularContribution *= vLightingIntensity.w;
-#endif
-
-#ifdef OPACITY
-    vec4 opacityMap = texture2D(opacitySampler, vOpacityUV);
-
-    #ifdef OPACITYRGB
-        opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11);
-        alpha *= (opacityMap.x + opacityMap.y + opacityMap.z)* vOpacityInfos.y;
-    #else
-        alpha *= opacityMap.a * vOpacityInfos.y;
-    #endif
-
-#endif
-
-#ifdef VERTEXALPHA
-    alpha *= vColor.a;
-#endif
-
-// Reflection
-vec3 environmentRadiance = vReflectionColor.rgb;
-vec3 environmentIrradiance = vReflectionColor.rgb;
-
-#ifdef OVERLOADEDVALUES
-    environmentIrradiance = mix(environmentIrradiance, vOverloadedReflection, vOverloadedMicroSurface.z);
-    environmentRadiance = mix(environmentRadiance, vOverloadedReflection, vOverloadedMicroSurface.z);
-#endif
-
-environmentRadiance *= vLightingIntensity.z;
-environmentIrradiance *= vLightingIntensity.z;
-
-// Compute reflection reflectivity fresnel
-vec3 specularEnvironmentR0 = surfaceReflectivityColor.rgb;
-vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0);
-vec3 specularEnvironmentReflectance = FresnelSchlickEnvironmentGGX(clamp(NdotV, 0., 1.), specularEnvironmentR0, specularEnvironmentR90, sqrt(microSurface));
-
-// Apply Energy Conservation taking in account the environment level only if the environment is present.
-float reflectance = max(max(surfaceReflectivityColor.r, surfaceReflectivityColor.g), surfaceReflectivityColor.b);
-surfaceAlbedo.rgb = (1. - reflectance) * surfaceAlbedo.rgb;
-environmentRadiance *= specularEnvironmentReflectance;
-
-// Emissive
-vec3 surfaceEmissiveColor = vEmissiveColor;
-#ifdef EMISSIVE
-    vec3 emissiveColorTex = texture2D(emissiveSampler, vEmissiveUV).rgb;
-    surfaceEmissiveColor = toLinearSpace(emissiveColorTex.rgb) * surfaceEmissiveColor * vEmissiveInfos.y;
-#endif
-
-#ifdef OVERLOADEDVALUES
-    surfaceEmissiveColor = mix(surfaceEmissiveColor, vOverloadedEmissive, vOverloadedIntensity.w);
-#endif
-
-// Composition
-#ifdef EMISSIVEASILLUMINATION
-    vec3 finalDiffuse = max(lightDiffuseContribution * surfaceAlbedoContribution + vAmbientColor, 0.0) * surfaceAlbedo.rgb;
-    
-    #ifdef OVERLOADEDSHADOWVALUES
-        shadowedOnlyLightDiffuseContribution = max(shadowedOnlyLightDiffuseContribution * surfaceAlbedoContribution + vAmbientColor, 0.0) * surfaceAlbedo.rgb;
-    #endif
-#else
-    #ifdef LINKEMISSIVEWITHALBEDO
-        vec3 finalDiffuse = max((lightDiffuseContribution + surfaceEmissiveColor) * surfaceAlbedoContribution + vAmbientColor, 0.0) * surfaceAlbedo.rgb;
-
-        #ifdef OVERLOADEDSHADOWVALUES
-            shadowedOnlyLightDiffuseContribution = max((shadowedOnlyLightDiffuseContribution + surfaceEmissiveColor) * surfaceAlbedoContribution + vAmbientColor, 0.0) * surfaceAlbedo.rgb;
-        #endif
-    #else
-        vec3 finalDiffuse = max(lightDiffuseContribution * surfaceAlbedoContribution + surfaceEmissiveColor + vAmbientColor, 0.0) * surfaceAlbedo.rgb;
-
-        #ifdef OVERLOADEDSHADOWVALUES
-            shadowedOnlyLightDiffuseContribution = max(shadowedOnlyLightDiffuseContribution * surfaceAlbedoContribution + surfaceEmissiveColor + vAmbientColor, 0.0) * surfaceAlbedo.rgb;
-        #endif
-    #endif
-#endif
-
-#ifdef OVERLOADEDSHADOWVALUES
-    finalDiffuse = mix(finalDiffuse, shadowedOnlyLightDiffuseContribution, (1.0 - vOverloadedShadowIntensity.y));
-#endif
-
-#ifdef SPECULARTERM
-    vec3 finalSpecular = lightSpecularContribution * surfaceReflectivityColor;
-#else
-    vec3 finalSpecular = vec3(0.0);
-#endif
-
-#ifdef SPECULAROVERALPHA
-    alpha = clamp(alpha + getLuminance(finalSpecular), 0., 1.);
-#endif
-
-#ifdef RADIANCEOVERALPHA
-    alpha = clamp(alpha + getLuminance(environmentRadiance), 0., 1.);
-#endif
-
-// Composition
-// Reflection already includes the environment intensity.
-#ifdef EMISSIVEASILLUMINATION
-    vec4 finalColor = vec4(finalDiffuse * ambientColor * vLightingIntensity.x + surfaceAlbedo.rgb * environmentIrradiance + finalSpecular * vLightingIntensity.x + environmentRadiance + surfaceEmissiveColor * vLightingIntensity.y, alpha);
-#else
-    vec4 finalColor = vec4(finalDiffuse * ambientColor * vLightingIntensity.x + surfaceAlbedo.rgb * environmentIrradiance + finalSpecular * vLightingIntensity.x + environmentRadiance, alpha);
-#endif
-
-    finalColor = max(finalColor, 0.0);
-
-#ifdef CAMERATONEMAP
-    finalColor.rgb = toneMaps(finalColor.rgb);
-#endif
-
-    finalColor.rgb = toGammaSpace(finalColor.rgb);
-
-#ifdef CAMERACONTRAST
-    finalColor = contrasts(finalColor);
-#endif
-
-    finalColor.rgb = clamp(finalColor.rgb, 0., 1.);
-    
-#ifdef CAMERACOLORGRADING
-    finalColor = colorGrades(finalColor, cameraColorGrading2DSampler, vCameraColorGradingInfos, vCameraColorGradingScaleOffset);
-#endif
-
-    gl_FragColor = finalColor;
-}

+ 0 - 142
src/Shaders/legacypbr.vertex.fx

@@ -1,142 +0,0 @@
-precision mediump float;
-
-// Attributes
-attribute vec3 position;
-attribute vec3 normal;
-#ifdef UV1
-attribute vec2 uv;
-#endif
-#ifdef UV2
-attribute vec2 uv2;
-#endif
-#ifdef VERTEXCOLOR
-attribute vec4 color;
-#endif
-#include<bonesDeclaration>
-
-// Uniforms
-uniform mat4 world;
-uniform mat4 view;
-uniform mat4 viewProjection;
-
-#ifdef ALBEDO
-varying vec2 vAlbedoUV;
-uniform mat4 albedoMatrix;
-uniform vec2 vAlbedoInfos;
-#endif
-
-#ifdef AMBIENT
-varying vec2 vAmbientUV;
-uniform mat4 ambientMatrix;
-uniform vec2 vAmbientInfos;
-#endif
-
-#ifdef OPACITY
-varying vec2 vOpacityUV;
-uniform mat4 opacityMatrix;
-uniform vec2 vOpacityInfos;
-#endif
-
-#ifdef EMISSIVE
-varying vec2 vEmissiveUV;
-uniform vec2 vEmissiveInfos;
-uniform mat4 emissiveMatrix;
-#endif
-
-#if defined(REFLECTIVITY)
-varying vec2 vReflectivityUV;
-uniform vec2 vReflectivityInfos;
-uniform mat4 reflectivityMatrix;
-#endif
-
-// Output
-varying vec3 vPositionW;
-varying vec3 vNormalW;
-
-#ifdef VERTEXCOLOR
-varying vec4 vColor;
-#endif
-
-#include<clipPlaneVertexDeclaration>
-
-void main(void) {
-    mat4 finalWorld = world;
-
-#include<bonesVertex>
-
-	gl_Position = viewProjection * finalWorld * vec4(position, 1.0);
-
-	vec4 worldPos = finalWorld * vec4(position, 1.0);
-	vPositionW = vec3(worldPos);
-	vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));
-
-	// Texture coordinates
-#ifndef UV1
-	vec2 uv = vec2(0., 0.);
-#endif
-#ifndef UV2
-	vec2 uv2 = vec2(0., 0.);
-#endif
-
-#ifdef ALBEDO
-	if (vAlbedoInfos.x == 0.)
-	{
-		vAlbedoUV = vec2(albedoMatrix * vec4(uv, 1.0, 0.0));
-	}
-	else
-	{
-		vAlbedoUV = vec2(albedoMatrix * vec4(uv2, 1.0, 0.0));
-	}
-#endif
-
-#ifdef AMBIENT
-	if (vAmbientInfos.x == 0.)
-	{
-		vAmbientUV = vec2(ambientMatrix * vec4(uv, 1.0, 0.0));
-	}
-	else
-	{
-		vAmbientUV = vec2(ambientMatrix * vec4(uv2, 1.0, 0.0));
-	}
-#endif
-
-#ifdef OPACITY
-	if (vOpacityInfos.x == 0.)
-	{
-		vOpacityUV = vec2(opacityMatrix * vec4(uv, 1.0, 0.0));
-	}
-	else
-	{
-		vOpacityUV = vec2(opacityMatrix * vec4(uv2, 1.0, 0.0));
-	}
-#endif
-
-#ifdef EMISSIVE
-	if (vEmissiveInfos.x == 0.)
-	{
-		vEmissiveUV = vec2(emissiveMatrix * vec4(uv, 1.0, 0.0));
-	}
-	else
-	{
-		vEmissiveUV = vec2(emissiveMatrix * vec4(uv2, 1.0, 0.0));
-	}
-#endif
-
-#if defined(REFLECTIVITY)
-	if (vReflectivityInfos.x == 0.)
-	{
-		vReflectivityUV = vec2(reflectivityMatrix * vec4(uv, 1.0, 0.0));
-	}
-	else
-	{
-		vReflectivityUV = vec2(reflectivityMatrix * vec4(uv2, 1.0, 0.0));
-	}
-#endif
-
-#include<clipPlaneVertex>
-
-	// Vertex color
-#ifdef VERTEXCOLOR
-	vColor = color;
-#endif
-}

+ 18 - 16
src/Shaders/pbr.fragment.fx

@@ -66,7 +66,7 @@ uniform vec2 vAlbedoInfos;
 #ifdef AMBIENT
 varying vec2 vAmbientUV;
 uniform sampler2D ambientSampler;
-uniform vec2 vAmbientInfos;
+uniform vec3 vAmbientInfos;
 #endif
 
 #ifdef OPACITY	
@@ -171,6 +171,7 @@ uniform mat4 reflectionMatrix;
 #include<harmonicsFunctions>
 #include<pbrLightFunctions>
 
+#include<helperFunctions>
 #include<bumpFragmentFunctions>
 #include<clipPlaneFragmentDeclaration>
 #include<logDepthDeclaration>
@@ -183,6 +184,15 @@ void main(void) {
 
 	vec3 viewDirectionW = normalize(vEyePosition - vPositionW);
 
+	// Bump
+	#ifdef NORMAL
+		vec3 normalW = normalize(vNormalW);
+	#else
+		vec3 normalW = vec3(1.0, 1.0, 1.0);
+	#endif
+
+	#include<bumpFragment>
+
 	// Albedo
 	vec4 surfaceAlbedo = vec4(1., 1., 1., 1.);
 	vec3 surfaceAlbedoContribution = vAlbedoColor.rgb;
@@ -191,7 +201,7 @@ void main(void) {
 	float alpha = vAlbedoColor.a;
 
 #ifdef ALBEDO
-	surfaceAlbedo = texture2D(albedoSampler, vAlbedoUV);
+	surfaceAlbedo = texture2D(albedoSampler, vAlbedoUV + uvOffset);
 	surfaceAlbedo = vec4(toLinearSpace(surfaceAlbedo.rgb), surfaceAlbedo.a);
 
 #ifndef LINKREFRACTIONTOTRANSPARENCY
@@ -220,20 +230,12 @@ void main(void) {
 	surfaceAlbedo.rgb = mix(surfaceAlbedo.rgb, vOverloadedAlbedo, vOverloadedIntensity.y);
 #endif
 
-	// Bump
-#ifdef NORMAL
-	vec3 normalW = normalize(vNormalW);
-#else
-	vec3 normalW = vec3(1.0, 1.0, 1.0);
-#endif
-
-#include<bumpFragment>
-
 	// Ambient color
 	vec3 ambientColor = vec3(1., 1., 1.);
 
 #ifdef AMBIENT
-	ambientColor = texture2D(ambientSampler, vAmbientUV).rgb * vAmbientInfos.y;
+	ambientColor = texture2D(ambientSampler, vAmbientUV + uvOffset).rgb * vAmbientInfos.y;
+	ambientColor = vec3(1., 1., 1.) - ((vec3(1., 1., 1.) - ambientColor) * vAmbientInfos.z);
 
 #ifdef OVERLOADEDVALUES
 	ambientColor.rgb = mix(ambientColor.rgb, vOverloadedAmbient, vOverloadedIntensity.x);
@@ -249,7 +251,7 @@ void main(void) {
 #endif
 
 #ifdef REFLECTIVITY
-	vec4 surfaceReflectivityColorMap = texture2D(reflectivitySampler, vReflectivityUV);
+	vec4 surfaceReflectivityColorMap = texture2D(reflectivitySampler, vReflectivityUV + uvOffset);
 	surfaceReflectivityColor = surfaceReflectivityColorMap.rgb;
 	surfaceReflectivityColor = toLinearSpace(surfaceReflectivityColor);
 
@@ -293,7 +295,7 @@ void main(void) {
 	float notShadowLevel = 1.; // 1 - shadowLevel
 
 	#ifdef LIGHTMAP
-  		vec3 lightmapColor = texture2D(lightmapSampler, vLightmapUV).rgb * vLightmapInfos.y;
+  		vec3 lightmapColor = texture2D(lightmapSampler, vLightmapUV + uvOffset).rgb * vLightmapInfos.y;
   	#endif
 
 	float NdotL = -1.;
@@ -315,7 +317,7 @@ void main(void) {
 #endif
 
 #ifdef OPACITY
-	vec4 opacityMap = texture2D(opacitySampler, vOpacityUV);
+	vec4 opacityMap = texture2D(opacitySampler, vOpacityUV + uvOffset);
 
 #ifdef OPACITYRGB
 	opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11);
@@ -531,7 +533,7 @@ void main(void) {
 	// Emissive
 	vec3 surfaceEmissiveColor = vEmissiveColor;
 #ifdef EMISSIVE
-	vec3 emissiveColorTex = texture2D(emissiveSampler, vEmissiveUV).rgb;
+	vec3 emissiveColorTex = texture2D(emissiveSampler, vEmissiveUV + uvOffset).rgb;
 	surfaceEmissiveColor = toLinearSpace(emissiveColorTex.rgb) * surfaceEmissiveColor * vEmissiveInfos.y;
 #endif
 

+ 1 - 1
src/Shaders/pbr.vertex.fx

@@ -32,7 +32,7 @@ uniform vec2 vAlbedoInfos;
 #ifdef AMBIENT
 varying vec2 vAmbientUV;
 uniform mat4 ambientMatrix;
-uniform vec2 vAmbientInfos;
+uniform vec3 vAmbientInfos;
 #endif
 
 #ifdef OPACITY

+ 8 - 4
src/babylon.scene.js

@@ -1801,6 +1801,7 @@ var BABYLON;
             var stencilState = this._engine.getStencilBuffer();
             var renderhighlights = false;
             if (this.renderTargetsEnabled && this.highlightLayers && this.highlightLayers.length > 0) {
+                this._intermediateRendering = true;
                 for (var i = 0; i < this.highlightLayers.length; i++) {
                     var highlightLayer = this.highlightLayers[i];
                     if (highlightLayer.shouldRender() &&
@@ -1808,13 +1809,16 @@ var BABYLON;
                             (highlightLayer.camera.cameraRigMode === BABYLON.Camera.RIG_MODE_NONE && camera === highlightLayer.camera) ||
                             (highlightLayer.camera.cameraRigMode !== BABYLON.Camera.RIG_MODE_NONE && highlightLayer.camera._rigCameras.indexOf(camera) > -1))) {
                         renderhighlights = true;
-                        needsRestoreFrameBuffer = true;
-                        this._intermediateRendering = true;
                         var renderTarget = highlightLayer._mainTexture;
-                        renderTarget.render(false, false);
-                        this._intermediateRendering = false;
+                        if (renderTarget._shouldRender()) {
+                            this._renderId++;
+                            renderTarget.render(false, false);
+                            needsRestoreFrameBuffer = true;
+                        }
                     }
                 }
+                this._intermediateRendering = false;
+                this._renderId++;
             }
             if (needsRestoreFrameBuffer) {
                 engine.restoreDefaultFramebuffer();

+ 10 - 6
src/babylon.scene.ts

@@ -2146,6 +2146,7 @@
             var stencilState = this._engine.getStencilBuffer();
             var renderhighlights = false;
             if (this.renderTargetsEnabled && this.highlightLayers && this.highlightLayers.length > 0) {
+                this._intermediateRendering = true;
                 for (let i = 0; i < this.highlightLayers.length; i++) {
                     let highlightLayer = this.highlightLayers[i];
 
@@ -2155,15 +2156,18 @@
                             (highlightLayer.camera.cameraRigMode !== Camera.RIG_MODE_NONE && highlightLayer.camera._rigCameras.indexOf(camera) > -1))) {
 
                         renderhighlights = true;
-                        needsRestoreFrameBuffer = true;
-                        this._intermediateRendering = true;
-
+                        
                         var renderTarget = (<RenderTargetTexture>(<any>highlightLayer)._mainTexture);
-                        renderTarget.render(false, false);
-
-                        this._intermediateRendering = false;
+                        if (renderTarget._shouldRender()) {
+                            this._renderId++;
+                            renderTarget.render(false, false);
+                            needsRestoreFrameBuffer = true;
+                        }
                     }
                 }
+
+                this._intermediateRendering = false;
+                this._renderId++;
             }
 
             if (needsRestoreFrameBuffer) {