Browse Source

Create default skybox

Sebastien Vandenberghe 8 năm trước cách đây
mục cha
commit
223125a67a

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 725 - 712
dist/preview release/babylon.d.ts


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 31 - 31
dist/preview release/babylon.js


+ 88 - 26
dist/preview release/babylon.max.js

@@ -15186,6 +15186,27 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        Object.defineProperty(Scene.prototype, "environmentTexture", {
+            /**
+             * Texture used in all pbr material as the reflection texture.
+             * As in the majority of the scene they are the same (excpetion for multi room and so on),
+             * this is easier to reference from here than from all the materials.
+             */
+            get: function () {
+                return this._environmentTexture;
+            },
+            /**
+             * Texture used in all pbr material as the reflection texture.
+             * As in the majority of the scene they are the same (excpetion for multi room and so on),
+             * this is easier to set here than in all the materials.
+             */
+            set: function (value) {
+                this._environmentTexture = value;
+                this.markAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
+            },
+            enumerable: true,
+            configurable: true
+        });
         Object.defineProperty(Scene.prototype, "forcePointsCloud", {
             get: function () {
                 return this._forcePointsCloud;
@@ -17881,6 +17902,44 @@ var BABYLON;
                 this.activeCamera = camera;
             }
         };
+        Scene.prototype.createDefaultSkybox = function (environmentTexture, pbr) {
+            if (pbr === void 0) { pbr = false; }
+            if (environmentTexture) {
+                this.environmentTexture = environmentTexture;
+            }
+            if (!this.environmentTexture) {
+                BABYLON.Tools.Warn("Can not create default skybox without environment texture.");
+                return;
+            }
+            if (!this.environmentTexture) {
+                BABYLON.Tools.Warn("Can not create default skybox without environment texture.");
+                return;
+            }
+            // Skybox
+            var hdrSkybox = BABYLON.Mesh.CreateBox("hdrSkyBox", 1000.0, this);
+            if (pbr) {
+                var hdrSkyboxMaterial = new BABYLON.PBRMaterial("skyBox", this);
+                hdrSkyboxMaterial.backFaceCulling = false;
+                hdrSkyboxMaterial.reflectionTexture = environmentTexture.clone();
+                hdrSkyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
+                hdrSkyboxMaterial.microSurface = 1.0;
+                hdrSkyboxMaterial.disableLighting = true;
+                hdrSkybox.infiniteDistance = true;
+                hdrSkybox.material = hdrSkyboxMaterial;
+            }
+            else {
+                var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", this);
+                skyboxMaterial.backFaceCulling = false;
+                skyboxMaterial.reflectionTexture = environmentTexture.clone();
+                skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
+                skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
+                skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
+                skyboxMaterial.disableLighting = true;
+                hdrSkybox.infiniteDistance = true;
+                hdrSkybox.material = skyboxMaterial;
+            }
+            return hdrSkybox;
+        };
         // Tags
         Scene.prototype._getByTags = function (list, tagsQuery, forEach) {
             if (tagsQuery === undefined) {
@@ -29383,16 +29442,17 @@ var BABYLON;
                         this._defines.OPACITYRGB = true;
                     }
                 }
-                if (this._reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
-                    if (!this._reflectionTexture.isReady()) {
+                var reflectionTexture = this._reflectionTexture || scene.environmentTexture;
+                if (reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
+                    if (!reflectionTexture.isReady()) {
                         return false;
                     }
                     this._defines.REFLECTION = true;
-                    if (this._reflectionTexture.coordinatesMode === BABYLON.Texture.INVCUBIC_MODE) {
+                    if (reflectionTexture.coordinatesMode === BABYLON.Texture.INVCUBIC_MODE) {
                         this._defines.INVERTCUBICMAP = true;
                     }
-                    this._defines.REFLECTIONMAP_3D = this._reflectionTexture.isCube;
-                    switch (this._reflectionTexture.coordinatesMode) {
+                    this._defines.REFLECTIONMAP_3D = reflectionTexture.isCube;
+                    switch (reflectionTexture.coordinatesMode) {
                         case BABYLON.Texture.CUBIC_MODE:
                         case BABYLON.Texture.INVCUBIC_MODE:
                             this._defines.REFLECTIONMAP_CUBIC = true;
@@ -29422,9 +29482,9 @@ var BABYLON;
                             this._defines.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = true;
                             break;
                     }
-                    if (this._reflectionTexture instanceof BABYLON.HDRCubeTexture && this._reflectionTexture) {
+                    if (reflectionTexture instanceof BABYLON.HDRCubeTexture && reflectionTexture) {
                         this._defines.USESPHERICALFROMREFLECTIONMAP = true;
-                        if (this._reflectionTexture.isPMREM) {
+                        if (reflectionTexture.isPMREM) {
                             this._defines.USEPMREMREFLECTION = true;
                         }
                     }
@@ -29838,20 +29898,22 @@ var BABYLON;
                             this._uniformBuffer.updateFloat2("vOpacityInfos", this._opacityTexture.coordinatesIndex, this._opacityTexture.level);
                             this._uniformBuffer.updateMatrix("opacityMatrix", this._opacityTexture.getTextureMatrix());
                         }
-                        if (this._reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
-                            this._microsurfaceTextureLods.x = Math.round(Math.log(this._reflectionTexture.getSize().width) * Math.LOG2E);
-                            this._uniformBuffer.updateMatrix("reflectionMatrix", this._reflectionTexture.getReflectionTextureMatrix());
-                            this._uniformBuffer.updateFloat2("vReflectionInfos", this._reflectionTexture.level, 0);
+                        var reflectionTexture = this._reflectionTexture || this._myScene.environmentTexture;
+                        ;
+                        if (reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
+                            this._microsurfaceTextureLods.x = Math.round(Math.log(reflectionTexture.getSize().width) * Math.LOG2E);
+                            this._uniformBuffer.updateMatrix("reflectionMatrix", reflectionTexture.getReflectionTextureMatrix());
+                            this._uniformBuffer.updateFloat2("vReflectionInfos", reflectionTexture.level, 0);
                             if (this._defines.USESPHERICALFROMREFLECTIONMAP) {
-                                this._effect.setFloat3("vSphericalX", this._reflectionTexture.sphericalPolynomial.x.x, this._reflectionTexture.sphericalPolynomial.x.y, this._reflectionTexture.sphericalPolynomial.x.z);
-                                this._effect.setFloat3("vSphericalY", this._reflectionTexture.sphericalPolynomial.y.x, this._reflectionTexture.sphericalPolynomial.y.y, this._reflectionTexture.sphericalPolynomial.y.z);
-                                this._effect.setFloat3("vSphericalZ", this._reflectionTexture.sphericalPolynomial.z.x, this._reflectionTexture.sphericalPolynomial.z.y, this._reflectionTexture.sphericalPolynomial.z.z);
-                                this._effect.setFloat3("vSphericalXX", this._reflectionTexture.sphericalPolynomial.xx.x, this._reflectionTexture.sphericalPolynomial.xx.y, this._reflectionTexture.sphericalPolynomial.xx.z);
-                                this._effect.setFloat3("vSphericalYY", this._reflectionTexture.sphericalPolynomial.yy.x, this._reflectionTexture.sphericalPolynomial.yy.y, this._reflectionTexture.sphericalPolynomial.yy.z);
-                                this._effect.setFloat3("vSphericalZZ", this._reflectionTexture.sphericalPolynomial.zz.x, this._reflectionTexture.sphericalPolynomial.zz.y, this._reflectionTexture.sphericalPolynomial.zz.z);
-                                this._effect.setFloat3("vSphericalXY", this._reflectionTexture.sphericalPolynomial.xy.x, this._reflectionTexture.sphericalPolynomial.xy.y, this._reflectionTexture.sphericalPolynomial.xy.z);
-                                this._effect.setFloat3("vSphericalYZ", this._reflectionTexture.sphericalPolynomial.yz.x, this._reflectionTexture.sphericalPolynomial.yz.y, this._reflectionTexture.sphericalPolynomial.yz.z);
-                                this._effect.setFloat3("vSphericalZX", this._reflectionTexture.sphericalPolynomial.zx.x, this._reflectionTexture.sphericalPolynomial.zx.y, this._reflectionTexture.sphericalPolynomial.zx.z);
+                                this._effect.setFloat3("vSphericalX", reflectionTexture.sphericalPolynomial.x.x, reflectionTexture.sphericalPolynomial.x.y, reflectionTexture.sphericalPolynomial.x.z);
+                                this._effect.setFloat3("vSphericalY", reflectionTexture.sphericalPolynomial.y.x, reflectionTexture.sphericalPolynomial.y.y, reflectionTexture.sphericalPolynomial.y.z);
+                                this._effect.setFloat3("vSphericalZ", reflectionTexture.sphericalPolynomial.z.x, reflectionTexture.sphericalPolynomial.z.y, reflectionTexture.sphericalPolynomial.z.z);
+                                this._effect.setFloat3("vSphericalXX", reflectionTexture.sphericalPolynomial.xx.x, reflectionTexture.sphericalPolynomial.xx.y, reflectionTexture.sphericalPolynomial.xx.z);
+                                this._effect.setFloat3("vSphericalYY", reflectionTexture.sphericalPolynomial.yy.x, reflectionTexture.sphericalPolynomial.yy.y, reflectionTexture.sphericalPolynomial.yy.z);
+                                this._effect.setFloat3("vSphericalZZ", reflectionTexture.sphericalPolynomial.zz.x, reflectionTexture.sphericalPolynomial.zz.y, reflectionTexture.sphericalPolynomial.zz.z);
+                                this._effect.setFloat3("vSphericalXY", reflectionTexture.sphericalPolynomial.xy.x, reflectionTexture.sphericalPolynomial.xy.y, reflectionTexture.sphericalPolynomial.xy.z);
+                                this._effect.setFloat3("vSphericalYZ", reflectionTexture.sphericalPolynomial.yz.x, reflectionTexture.sphericalPolynomial.yz.y, reflectionTexture.sphericalPolynomial.yz.z);
+                                this._effect.setFloat3("vSphericalZX", reflectionTexture.sphericalPolynomial.zx.x, reflectionTexture.sphericalPolynomial.zx.y, reflectionTexture.sphericalPolynomial.zx.z);
                             }
                         }
                         if (this._emissiveTexture && BABYLON.StandardMaterial.EmissiveTextureEnabled) {
@@ -29891,7 +29953,7 @@ var BABYLON;
                             }
                             this._uniformBuffer.updateFloat4("vRefractionInfos", this._refractionTexture.level, this._indexOfRefraction, depth, this._invertRefractionY ? -1 : 1);
                         }
-                        if ((this._reflectionTexture || this._refractionTexture)) {
+                        if ((reflectionTexture || this._refractionTexture)) {
                             this._uniformBuffer.updateFloat2("vMicrosurfaceTextureLods", this._microsurfaceTextureLods.x, this._microsurfaceTextureLods.y);
                         }
                     }
@@ -29937,12 +29999,12 @@ var BABYLON;
                     if (this._opacityTexture && BABYLON.StandardMaterial.OpacityTextureEnabled) {
                         this._uniformBuffer.setTexture("opacitySampler", this._opacityTexture);
                     }
-                    if (this._reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
-                        if (this._reflectionTexture.isCube) {
-                            this._uniformBuffer.setTexture("reflectionCubeSampler", this._reflectionTexture);
+                    if (reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
+                        if (reflectionTexture.isCube) {
+                            this._uniformBuffer.setTexture("reflectionCubeSampler", reflectionTexture);
                         }
                         else {
-                            this._uniformBuffer.setTexture("reflection2DSampler", this._reflectionTexture);
+                            this._uniformBuffer.setTexture("reflection2DSampler", reflectionTexture);
                         }
                     }
                     if (this._emissiveTexture && BABYLON.StandardMaterial.EmissiveTextureEnabled) {
@@ -29990,7 +30052,7 @@ var BABYLON;
                     BABYLON.PBRMaterial.BindLights(this._myScene, mesh, this._effect, this._defines, this._useScalarInLinearSpace, this._maxSimultaneousLights, this._usePhysicalLightFalloff);
                 }
                 // View
-                if (this._myScene.fogEnabled && mesh.applyFog && this._myScene.fogMode !== BABYLON.Scene.FOGMODE_NONE || this._reflectionTexture) {
+                if (this._myScene.fogEnabled && mesh.applyFog && this._myScene.fogMode !== BABYLON.Scene.FOGMODE_NONE || reflectionTexture) {
                     this.bindView(effect);
                 }
                 // Fog

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 725 - 712
dist/preview release/babylon.module.d.ts


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 31 - 31
dist/preview release/babylon.worker.js


+ 5 - 20
materialsLibrary/test/addpbrmetallicroughness.js

@@ -4,32 +4,17 @@ window.preparePBRMetallicRoughness = function() {
 	pbr.baseTexture = new BABYLON.Texture("../assets/textures/amiga.jpg", scene);
 	pbr.baseTexture.uScale = 5;
 	pbr.baseTexture.vScale = 5;
-    
-    var hdrTexture = new BABYLON.HDRCubeTexture("../assets/textures/hdr/environment.hdr", scene, 512);
+	pbr.metallic = 0.5;
+	pbr.roughness = 0.1;
 
     // Uncomment for PMREM Generation
+    var hdrTexture = new BABYLON.HDRCubeTexture("../assets/textures/hdr/environment.hdr", scene, 512);
     // var hdrTexture = new BABYLON.HDRCubeTexture("textures/hdr/environment.hdr", scene, 128, false, true, false, true);
-    pbr.environmentTexture = hdrTexture;
 
-	pbr.metallic = 0.5;
-	pbr.roughness = 0.1;
-    
     // Skybox
-    var hdrSkybox = BABYLON.Mesh.CreateBox("hdrSkyBox", 1000.0, scene);
-    var hdrSkyboxMaterial = new BABYLON.PBRMaterial("skyBox", scene);
-    hdrSkyboxMaterial.backFaceCulling = false;
-    hdrSkyboxMaterial.reflectionTexture = hdrTexture.clone();
-    hdrSkyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
-    hdrSkyboxMaterial.microSurface = 1;
-    hdrSkyboxMaterial.specularColor = new BABYLON.Color3(1, 1, 1);
-    hdrSkyboxMaterial.disableLighting = true;
-    hdrSkyboxMaterial.cameraExposure = 0.6;
-    hdrSkyboxMaterial.cameraContrast = 1.6;
-    hdrSkyboxMaterial.directIntensity = 0;
-    hdrSkybox.material = hdrSkyboxMaterial;
-    hdrSkybox.infiniteDistance = true;
+    var hdrSkybox = scene.createDefaultSkybox(hdrTexture, true);
     hdrSkybox.setEnabled(false);
-    
+
     registerRangeUI("pbrmetallicroughness", "alpha", 0, 1, function(value) {
 		pbr.alpha = value;
 	}, function() {

+ 4 - 19
materialsLibrary/test/addpbrspecularglossiness.js

@@ -4,30 +4,15 @@ window.preparePBRSpecularGlossiness = function() {
 	pbr.diffuseTexture = new BABYLON.Texture("../assets/textures/amiga.jpg", scene);
 	pbr.diffuseTexture.uScale = 5;
 	pbr.diffuseTexture.vScale = 5;
-    
-    var hdrTexture = new BABYLON.HDRCubeTexture("../assets/textures/hdr/environment.hdr", scene, 512);
+	pbr.specularColor = new BABYLON.Color3(0.3, 0.3, 0.3);
+	pbr.glossiness = 0.9;
 
     // Uncomment for PMREM Generation
+    var hdrTexture = new BABYLON.HDRCubeTexture("../assets/textures/hdr/environment.hdr", scene, 512);
     // var hdrTexture = new BABYLON.HDRCubeTexture("textures/hdr/environment.hdr", scene, 128, false, true, false, true);
-    pbr.environmentTexture = hdrTexture;
 
-	pbr.specularColor = new BABYLON.Color3(0.3, 0.3, 0.3);
-	pbr.glossiness = 0.9;
-    
     // Skybox
-    var hdrSkybox = BABYLON.Mesh.CreateBox("hdrSkyBox", 1000.0, scene);
-    var hdrSkyboxMaterial = new BABYLON.PBRMaterial("skyBox", scene);
-    hdrSkyboxMaterial.backFaceCulling = false;
-    hdrSkyboxMaterial.reflectionTexture = hdrTexture.clone();
-    hdrSkyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
-    hdrSkyboxMaterial.microSurface = 1;
-    hdrSkyboxMaterial.specularColor = new BABYLON.Color3(1, 1, 1);
-    hdrSkyboxMaterial.disableLighting = true;
-    hdrSkyboxMaterial.cameraExposure = 0.6;
-    hdrSkyboxMaterial.cameraContrast = 1.6;
-    hdrSkyboxMaterial.directIntensity = 0;
-    hdrSkybox.material = hdrSkyboxMaterial;
-    hdrSkybox.infiniteDistance = true;
+    var hdrSkybox = scene.createDefaultSkybox(hdrTexture, true);
     hdrSkybox.setEnabled(false);
     
     registerRangeUI("pbrspecularglossiness", "alpha", 0, 1, function(value) {

+ 46 - 44
src/Materials/PBR/babylon.pbrBaseMaterial.ts

@@ -586,20 +586,21 @@
                     }
                 }
 
-                if (this._reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
-                    if (!this._reflectionTexture.isReady()) {
+                var reflectionTexture = this._reflectionTexture || scene.environmentTexture;
+                if (reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
+                    if (!reflectionTexture.isReady()) {
                         return false;
                     }
                     
                     this._defines.REFLECTION = true;
 
-                    if (this._reflectionTexture.coordinatesMode === Texture.INVCUBIC_MODE) {
+                    if (reflectionTexture.coordinatesMode === Texture.INVCUBIC_MODE) {
                         this._defines.INVERTCUBICMAP = true;
                     }
 
-                    this._defines.REFLECTIONMAP_3D = this._reflectionTexture.isCube;
+                    this._defines.REFLECTIONMAP_3D = reflectionTexture.isCube;
 
-                    switch (this._reflectionTexture.coordinatesMode) {
+                    switch (reflectionTexture.coordinatesMode) {
                         case Texture.CUBIC_MODE:
                         case Texture.INVCUBIC_MODE:
                             this._defines.REFLECTIONMAP_CUBIC = true;
@@ -630,10 +631,10 @@
                             break;                                
                     }
 
-                    if (this._reflectionTexture instanceof HDRCubeTexture && (<HDRCubeTexture>this._reflectionTexture)) {
+                    if (reflectionTexture instanceof HDRCubeTexture && (<HDRCubeTexture>reflectionTexture)) {
                         this._defines.USESPHERICALFROMREFLECTIONMAP = true;
 
-                        if ((<HDRCubeTexture>this._reflectionTexture).isPMREM) {
+                        if ((<HDRCubeTexture>reflectionTexture).isPMREM) {
                             this._defines.USEPMREMREFLECTION = true;
                         }
                     }
@@ -1152,39 +1153,40 @@
                             this._uniformBuffer.updateMatrix("opacityMatrix", this._opacityTexture.getTextureMatrix());
                         }
 
-                        if (this._reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
-                            this._microsurfaceTextureLods.x = Math.round(Math.log(this._reflectionTexture.getSize().width) * Math.LOG2E);
-                            this._uniformBuffer.updateMatrix("reflectionMatrix", this._reflectionTexture.getReflectionTextureMatrix());
-                            this._uniformBuffer.updateFloat2("vReflectionInfos", this._reflectionTexture.level, 0);
+                        var reflectionTexture = this._reflectionTexture || this._myScene.environmentTexture;;
+                        if (reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
+                            this._microsurfaceTextureLods.x = Math.round(Math.log(reflectionTexture.getSize().width) * Math.LOG2E);
+                            this._uniformBuffer.updateMatrix("reflectionMatrix", reflectionTexture.getReflectionTextureMatrix());
+                            this._uniformBuffer.updateFloat2("vReflectionInfos", reflectionTexture.level, 0);
 
                             if (this._defines.USESPHERICALFROMREFLECTIONMAP) {
-                                this._effect.setFloat3("vSphericalX", (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.x.x,
-                                    (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.x.y,
-                                    (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.x.z);
-                                this._effect.setFloat3("vSphericalY", (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.y.x,
-                                    (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.y.y,
-                                    (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.y.z);
-                                this._effect.setFloat3("vSphericalZ", (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.z.x,
-                                    (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.z.y,
-                                    (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.z.z);
-                                this._effect.setFloat3("vSphericalXX", (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.xx.x,
-                                    (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.xx.y,
-                                    (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.xx.z);
-                                this._effect.setFloat3("vSphericalYY", (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.yy.x,
-                                    (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.yy.y,
-                                    (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.yy.z);
-                                this._effect.setFloat3("vSphericalZZ", (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.zz.x,
-                                    (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.zz.y,
-                                    (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.zz.z);
-                                this._effect.setFloat3("vSphericalXY", (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.xy.x,
-                                    (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.xy.y,
-                                    (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.xy.z);
-                                this._effect.setFloat3("vSphericalYZ", (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.yz.x,
-                                    (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.yz.y,
-                                    (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.yz.z);
-                                this._effect.setFloat3("vSphericalZX", (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.zx.x,
-                                    (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.zx.y,
-                                    (<HDRCubeTexture>this._reflectionTexture).sphericalPolynomial.zx.z);
+                                this._effect.setFloat3("vSphericalX", (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.x.x,
+                                    (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.x.y,
+                                    (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.x.z);
+                                this._effect.setFloat3("vSphericalY", (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.y.x,
+                                    (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.y.y,
+                                    (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.y.z);
+                                this._effect.setFloat3("vSphericalZ", (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.z.x,
+                                    (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.z.y,
+                                    (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.z.z);
+                                this._effect.setFloat3("vSphericalXX", (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.xx.x,
+                                    (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.xx.y,
+                                    (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.xx.z);
+                                this._effect.setFloat3("vSphericalYY", (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.yy.x,
+                                    (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.yy.y,
+                                    (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.yy.z);
+                                this._effect.setFloat3("vSphericalZZ", (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.zz.x,
+                                    (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.zz.y,
+                                    (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.zz.z);
+                                this._effect.setFloat3("vSphericalXY", (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.xy.x,
+                                    (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.xy.y,
+                                    (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.xy.z);
+                                this._effect.setFloat3("vSphericalYZ", (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.yz.x,
+                                    (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.yz.y,
+                                    (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.yz.z);
+                                this._effect.setFloat3("vSphericalZX", (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.zx.x,
+                                    (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.zx.y,
+                                    (<HDRCubeTexture>reflectionTexture).sphericalPolynomial.zx.z);
                             }
                         }
 
@@ -1233,7 +1235,7 @@
                             this._uniformBuffer.updateFloat4("vRefractionInfos", this._refractionTexture.level, this._indexOfRefraction, depth, this._invertRefractionY ? -1 : 1);
                         }
 
-                        if ((this._reflectionTexture || this._refractionTexture)) {
+                        if ((reflectionTexture || this._refractionTexture)) {
                             this._uniformBuffer.updateFloat2("vMicrosurfaceTextureLods", this._microsurfaceTextureLods.x, this._microsurfaceTextureLods.y);
                         }
                     }
@@ -1291,11 +1293,11 @@
                         this._uniformBuffer.setTexture("opacitySampler", this._opacityTexture);
                     }
 
-                    if (this._reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
-                        if (this._reflectionTexture.isCube) {
-                            this._uniformBuffer.setTexture("reflectionCubeSampler", this._reflectionTexture);
+                    if (reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
+                        if (reflectionTexture.isCube) {
+                            this._uniformBuffer.setTexture("reflectionCubeSampler", reflectionTexture);
                         } else {
-                            this._uniformBuffer.setTexture("reflection2DSampler", this._reflectionTexture);
+                            this._uniformBuffer.setTexture("reflection2DSampler", reflectionTexture);
                         }
                     }
 
@@ -1355,7 +1357,7 @@
                 }
 
                 // View
-                if (this._myScene.fogEnabled && mesh.applyFog && this._myScene.fogMode !== Scene.FOGMODE_NONE || this._reflectionTexture) {
+                if (this._myScene.fogEnabled && mesh.applyFog && this._myScene.fogMode !== Scene.FOGMODE_NONE || reflectionTexture) {
                     this.bindView(effect);
                 }
 

+ 61 - 0
src/babylon.scene.ts

@@ -189,6 +189,25 @@
         public clearColor: Color4 = new Color4(0.2, 0.2, 0.3, 1.0);
         public ambientColor = new Color3(0, 0, 0);
 
+        protected _environmentTexture: BaseTexture;
+        /**
+         * Texture used in all pbr material as the reflection texture.
+         * As in the majority of the scene they are the same (excpetion for multi room and so on),
+         * this is easier to reference from here than from all the materials.
+         */
+        public get environmentTexture(): BaseTexture {
+            return this._environmentTexture;
+        }
+        /**
+         * Texture used in all pbr material as the reflection texture.
+         * As in the majority of the scene they are the same (excpetion for multi room and so on),
+         * this is easier to set here than in all the materials.
+         */
+        public set environmentTexture(value: BaseTexture) {
+            this._environmentTexture = value;
+            this.markAllMaterialsAsDirty(Material.TextureDirtyFlag);
+        }
+
         public forceWireframe = false;
         private _forcePointsCloud = false;
         public set forcePointsCloud(value : boolean) {
@@ -3675,6 +3694,48 @@
             }
         }
 
+        public createDefaultSkybox(environmentTexture?: BaseTexture, pbr = false): Mesh {
+            if (environmentTexture) {
+                this.environmentTexture = environmentTexture;
+            }
+
+            if (!this.environmentTexture) {
+                Tools.Warn("Can not create default skybox without environment texture.");
+                return;
+            }
+
+            if (!this.environmentTexture) {
+                Tools.Warn("Can not create default skybox without environment texture.");
+                return;
+            }
+
+            // Skybox
+            var hdrSkybox = BABYLON.Mesh.CreateBox("hdrSkyBox", 1000.0, this);
+            if (pbr) {
+                let hdrSkyboxMaterial = new BABYLON.PBRMaterial("skyBox", this);
+                hdrSkyboxMaterial.backFaceCulling = false;
+                hdrSkyboxMaterial.reflectionTexture = environmentTexture.clone();
+                hdrSkyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
+                hdrSkyboxMaterial.microSurface = 1.0;
+                hdrSkyboxMaterial.disableLighting = true;
+                hdrSkybox.infiniteDistance = true;
+                hdrSkybox.material = hdrSkyboxMaterial;
+            }
+            else {
+                let skyboxMaterial = new BABYLON.StandardMaterial("skyBox", this);
+                skyboxMaterial.backFaceCulling = false;
+                skyboxMaterial.reflectionTexture = environmentTexture.clone();
+                skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
+                skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
+                skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
+                skyboxMaterial.disableLighting = true;
+                hdrSkybox.infiniteDistance = true;
+                hdrSkybox.material = skyboxMaterial;
+            }
+
+            return hdrSkybox;
+        }
+
         // Tags
         private _getByTags(list: any[], tagsQuery: string, forEach?: (item: any) => void): any[] {
             if (tagsQuery === undefined) {