Преглед на файлове

Add hdr filtering to sandbox

sebavan преди 5 години
родител
ревизия
27cbe29535

+ 1 - 1
inspector/src/components/actionTabs/tabs/toolsTabComponent.tsx

@@ -345,7 +345,7 @@ export class ToolsTabComponent extends PaneComponent {
                             <ButtonLineComponent label="Export to GLB" onClick={() => this.exportGLTF()} />
                             <ButtonLineComponent label="Export to Babylon" onClick={() => this.exportBabylon()} />
                             {
-                                !scene.getEngine().premultipliedAlpha && scene.environmentTexture && (scene.environmentTexture as CubeTexture).isPrefiltered && scene.activeCamera &&
+                                !scene.getEngine().premultipliedAlpha && scene.environmentTexture && scene.environmentTexture._prefiltered && scene.activeCamera &&
                                 <ButtonLineComponent label="Generate .env texture" onClick={() => this.createEnvTexture()} />
                             }
                         </>

+ 8 - 1
sandbox/environment.js

@@ -23,6 +23,13 @@ var readLocaStorageValue = function(key, defautlValue) {
 
 var defaultSkyboxIndex = readLocaStorageValue("defaultSkyboxId", 0);
 
+function loadSkyboxPathTexture(path, scene) {
+    if (path.indexOf(".hdr") === (path.length - 4)) {
+        return new BABYLON.HDRCubeTexture(path, scene, 256, false, true, false, true);
+    }
+    return BABYLON.CubeTexture.CreateFromPrefilteredData(path, scene);
+}
+
 function displayDropdownContentEnv(display) {
     if (display) {
         dropdownContentEnv.classList.remove("hidden");
@@ -57,7 +64,7 @@ addEnvironmentLoader = function(index) {
         }
         else {
             var currentScene = BABYLON.Engine.LastCreatedScene;
-            currentScene.environmentTexture = BABYLON.CubeTexture.CreateFromPrefilteredData(skyboxPath, currentScene);
+            currentScene.environmentTexture = loadSkyboxPathTexture(skyboxPath, currentScene);
             for (var i = 0; i < currentScene.materials.length; i++) {
                 var material = currentScene.materials[i];
                 if (material.name === "skyBox") {

+ 5 - 3
sandbox/index.js

@@ -186,7 +186,7 @@ if (BABYLON.Engine.isSupported()) {
         // Lighting
         if (currentPluginName === "gltf") {
             if (!currentScene.environmentTexture) {
-                currentScene.environmentTexture = BABYLON.CubeTexture.CreateFromPrefilteredData(skyboxPath, currentScene);
+                currentScene.environmentTexture = loadSkyboxPathTexture(skyboxPath, currentScene);
             }
 
             currentSkybox = currentScene.createDefaultSkybox(currentScene.environmentTexture, true, (currentScene.activeCamera.maxZ - currentScene.activeCamera.minZ) / 2, 0.3, false);
@@ -202,7 +202,7 @@ if (BABYLON.Engine.isSupported()) {
 
             if (pbrPresent) {
                 if (!currentScene.environmentTexture) {
-                    currentScene.environmentTexture = BABYLON.CubeTexture.CreateFromPrefilteredData(skyboxPath, currentScene);
+                    currentScene.environmentTexture = loadSkyboxPathTexture(skyboxPath, currentScene);
                 }
             }
             else {
@@ -286,7 +286,9 @@ if (BABYLON.Engine.isSupported()) {
         filesInput = new BABYLON.FilesInput(engine, null, sceneLoaded, null, null, null, startProcessingFiles, null, sceneError);
         filesInput.onProcessFileCallback = (function(file, name, extension) {
             if (filesInput._filesToLoad && filesInput._filesToLoad.length === 1 && extension) {
-                if (extension.toLowerCase() === "dds" || extension.toLowerCase() === "env") {
+                if (extension.toLowerCase() === "dds" ||
+                    extension.toLowerCase() === "env" ||
+                    extension.toLowerCase() === "hdr") {
                     BABYLON.FilesInput.FilesToLoad[name] = file;
                     skyboxPath = "file:" + file.correctName;
                     return false;

+ 3 - 0
src/Materials/Textures/Filtering/hdrFiltering.ts

@@ -148,6 +148,9 @@ export class HDRFiltering {
 
         // Internal Swap
         outputTexture._swapAndDie(texture._texture!);
+
+        texture._prefiltered = true;
+
         return texture;
     }
 

+ 3 - 0
src/Materials/Textures/baseTexture.ts

@@ -329,6 +329,9 @@ export class BaseTexture implements IAnimatable {
         return this._uid;
     }
 
+    /** @hidden */
+    public _prefiltered: boolean = false;
+
     /**
      * Return a string representation of the texture.
      * @returns the texture as a string

+ 0 - 10
src/Materials/Textures/cubeTexture.ts

@@ -104,9 +104,6 @@ export class CubeTexture extends BaseTexture {
     private _format: number;
     private _createPolynomials: boolean;
 
-    /** @hidden */
-    public _prefiltered: boolean = false;
-
     /**
      * Creates a cube texture from an array of image urls
      * @param files defines an array of image urls
@@ -251,13 +248,6 @@ export class CubeTexture extends BaseTexture {
     }
 
     /**
-     * Gets a boolean indicating if the cube texture contains prefiltered mips (used to simulate roughness with PBR)
-     */
-    public get isPrefiltered(): boolean {
-        return this._prefiltered;
-    }
-
-    /**
      * Get the current class name of the texture useful for serialization or dynamic coding.
      * @returns "CubeTexture"
      */