Browse Source

Helper createDefault

Sebastien Vandenberghe 8 years ago
parent
commit
6b1b17c74c
2 changed files with 27 additions and 4 deletions
  1. 5 1
      src/Shaders/pbr.fragment.fx
  2. 22 3
      src/babylon.scene.ts

+ 5 - 1
src/Shaders/pbr.fragment.fx

@@ -452,7 +452,11 @@ void main(void) {
 		reflectionCoords.y = 1.0 - reflectionCoords.y;
 	#endif
 	
-	float reflectionLOD = getLodFromAlphaG(vReflectionMicrosurfaceInfos.x, alphaG, NdotV);
+	#ifdef REFLECTIONMAP_SKYBOX
+		float reflectionLOD = getLodFromAlphaG(vReflectionMicrosurfaceInfos.x, alphaG, 1.);
+	#else
+		float reflectionLOD = getLodFromAlphaG(vReflectionMicrosurfaceInfos.x, alphaG, NdotV);
+	#endif
 
 	#ifdef LODBASEDMICROSFURACE
 		// Apply environment convolution scale/offset filter tuning parameters to the mipmap LOD selection

+ 22 - 3
src/babylon.scene.ts

@@ -3686,7 +3686,21 @@
         }
 
         // Misc.
-        public createDefaultCameraOrLight(createArcRotateCamera = false) {
+        public createDefaultCameraOrLight(createArcRotateCamera = false, replace = false, attachCameraControls = false) {
+            // Dispose existing camera or light in replace mode.
+            if (replace) {
+                if (this.activeCamera) {
+                    this.activeCamera.dispose();
+                    this.activeCamera = null;
+                }
+
+                if (this.lights) {
+                    for (var i = 0; i < this.lights.length; i++) {
+                        this.lights[i].dispose();
+                    }
+                }
+            }
+
             // Light
             if (this.lights.length === 0) {
                 new HemisphericLight("default light", Vector3.Up(), this);
@@ -3715,10 +3729,14 @@
                 camera.maxZ = radius * 100;
                 camera.speed = radius * 0.2;
                 this.activeCamera = camera;
+
+                if (attachCameraControls) {
+                    camera.attachControl(this.getEngine().getRenderingCanvas());
+                }
             }
         }
 
-        public createDefaultSkybox(environmentTexture?: BaseTexture, pbr = false, scale = 1000): Mesh {
+        public createDefaultSkybox(environmentTexture?: BaseTexture, pbr = false, scale = 1000, blur = 0): Mesh {
             if (environmentTexture) {
                 this.environmentTexture = environmentTexture;
             }
@@ -3735,8 +3753,9 @@
                 hdrSkyboxMaterial.backFaceCulling = false;
                 hdrSkyboxMaterial.reflectionTexture = environmentTexture.clone();
                 hdrSkyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
-                hdrSkyboxMaterial.microSurface = 1.0;
+                hdrSkyboxMaterial.microSurface = 1.0 - blur;
                 hdrSkyboxMaterial.disableLighting = true;
+                hdrSkyboxMaterial.twoSidedLighting = true;
                 hdrSkybox.infiniteDistance = true;
                 hdrSkybox.material = hdrSkyboxMaterial;
             }