Forráskód Böngészése

Remove PMREM LeftOver

Sebastien Vandenberghe 7 éve
szülő
commit
c50ca64755

+ 17 - 284
src/Materials/Textures/babylon.hdrCubeTexture.ts

@@ -17,13 +17,10 @@ module BABYLON {
             "back"
         ];
 
-        private _useInGammaSpace = false;
         private _generateHarmonics = true;
         private _noMipmap: boolean;
         private _textureMatrix: Matrix;
         private _size: number;
-        private _usePMREMGenerator: boolean;
-        private _isBABYLONPreprocessed = false;
         private _onLoad: Nullable<() => void> = null;
         private _onError: Nullable<() => void> = null;
 
@@ -37,12 +34,6 @@ module BABYLON {
          */
         public coordinatesMode = Texture.CUBIC_MODE;
 
-        /**
-         * Specifies wether the texture has been generated through the PMREMGenerator tool.
-         * This is usefull at run time to apply the good shader.
-         */
-        public isPMREM = false;
-
         protected _isBlocking: boolean = true;
         /**
          * Sets wether or not the texture is blocking during loading.
@@ -105,13 +96,13 @@ module BABYLON {
          * 
          * @param url The location of the HDR raw data (Panorama stored in RGBE format)
          * @param scene The scene the texture will be used in
-         * @param size The cubemap desired size (the more it increases the longer the generation will be) If the size is omitted this implies you are using a preprocessed cubemap.
+         * @param size The cubemap desired size (the more it increases the longer the generation will be)
          * @param noMipmap Forces to not generate the mipmap if true
          * @param generateHarmonics Specifies whether you want to extract the polynomial harmonics during the generation process
-         * @param useInGammaSpace Specifies if the texture will be use in gamma or linear space (the PBR material requires those texture in linear space, but the standard material would require them in Gamma space)
-         * @param usePMREMGenerator Specifies whether or not to generate the CubeMap through CubeMapGen to avoid seams issue at run time.
+         * @param gammaSpace Specifies if the texture will be use in gamma or linear space (the PBR material requires those texture in linear space, but the standard material would require them in Gamma space)
+         * @param reserved Reserved flag for internal use.
          */
-        constructor(url: string, scene: Scene, size?: number, noMipmap = false, generateHarmonics = true, useInGammaSpace = false, usePMREMGenerator = false, onLoad: Nullable<() => void> = null, onError: Nullable<(message?: string, exception?: any) => void> = null) {
+        constructor(url: string, scene: Scene, size: number, noMipmap = false, generateHarmonics = true, gammaSpace = false, reserved = false, onLoad: Nullable<() => void> = null, onError: Nullable<(message?: string, exception?: any) => void> = null) {
             super(scene);
 
             if (!url) {
@@ -125,28 +116,10 @@ module BABYLON {
             this._textureMatrix = Matrix.Identity();
             this._onLoad = onLoad;
             this._onError = onError;
-            this.gammaSpace = false;
-
-            let caps = scene.getEngine().getCaps();
-
-            if (size) {
-                this._isBABYLONPreprocessed = false;
-                this._noMipmap = noMipmap;
-                this._size = size;
-                this._useInGammaSpace = useInGammaSpace;
-                this._usePMREMGenerator = usePMREMGenerator &&
-                    caps.textureLOD &&
-                    caps.textureFloat &&
-                    !this._useInGammaSpace;
-            }
-            else {
-                this._isBABYLONPreprocessed = true;
-                this._noMipmap = false;
-                this._useInGammaSpace = false;
-                this._usePMREMGenerator = caps.textureLOD && caps.textureFloat &&
-                    !this._useInGammaSpace;
-            }
-            this.isPMREM = this._usePMREMGenerator;
+            this.gammaSpace = gammaSpace;
+
+            this._noMipmap = noMipmap;
+            this._size = size;
 
             this._texture = this._getFromCache(url, this._noMipmap);
 
@@ -160,159 +133,9 @@ module BABYLON {
         }
 
         /**
-         * Occurs when the file is a preprocessed .babylon.hdr file.
-         */
-        private loadBabylonTexture() {
-
-            var mipLevels = 0;
-            var floatArrayView: Nullable<Float32Array> = null;
-            let scene = this.getScene();
-
-            var mipmapGenerator = (!this._useInGammaSpace && scene && scene.getEngine().getCaps().textureFloat) ? (data: ArrayBufferView[]): Array<Array<Float32Array>> => {
-                var mips = new Array<Array<Float32Array>>();
-
-                if (!floatArrayView) {
-                    return mips;
-                }
-                var startIndex = 30;
-                for (var level = 0; level < mipLevels; level++) {
-                    mips.push([]);
-                    // Fill each pixel of the mip level.
-                    var faceSize = Math.pow(this._size >> level, 2) * 3;
-                    for (var faceIndex = 0; faceIndex < 6; faceIndex++) {
-
-                        var faceData = floatArrayView.subarray(startIndex, startIndex + faceSize);
-                        mips[level].push(faceData);
-
-                        startIndex += faceSize;
-                    }
-                }
-
-                return mips;
-            } : null;
-
-            var callback = (buffer: ArrayBuffer) => {
-                let scene = this.getScene();
-
-                if (!scene) {
-                    return null;
-                }
-                // Create Native Array Views
-                var intArrayView = new Int32Array(buffer);
-                floatArrayView = new Float32Array(buffer);
-
-                // Fill header.
-                var version = intArrayView[0]; // Version 1. (MAy be use in case of format changes for backward compaibility)
-                this._size = intArrayView[1]; // CubeMap max mip face size.
-
-                // Update Texture Information.
-                if (!this._texture) {
-                    return null;
-                }
-                this._texture.updateSize(this._size, this._size);
-
-                // Fill polynomial information.
-                var sphericalPolynomial = new SphericalPolynomial();
-                sphericalPolynomial.x.copyFromFloats(floatArrayView[2], floatArrayView[3], floatArrayView[4]);
-                sphericalPolynomial.y.copyFromFloats(floatArrayView[5], floatArrayView[6], floatArrayView[7]);
-                sphericalPolynomial.z.copyFromFloats(floatArrayView[8], floatArrayView[9], floatArrayView[10]);
-                sphericalPolynomial.xx.copyFromFloats(floatArrayView[11], floatArrayView[12], floatArrayView[13]);
-                sphericalPolynomial.yy.copyFromFloats(floatArrayView[14], floatArrayView[15], floatArrayView[16]);
-                sphericalPolynomial.zz.copyFromFloats(floatArrayView[17], floatArrayView[18], floatArrayView[19]);
-                sphericalPolynomial.xy.copyFromFloats(floatArrayView[20], floatArrayView[21], floatArrayView[22]);
-                sphericalPolynomial.yz.copyFromFloats(floatArrayView[23], floatArrayView[24], floatArrayView[25]);
-                sphericalPolynomial.zx.copyFromFloats(floatArrayView[26], floatArrayView[27], floatArrayView[28]);
-                this.sphericalPolynomial = sphericalPolynomial;
-
-                // Fill pixel data.
-                mipLevels = intArrayView[29]; // Number of mip levels.
-                var startIndex = 30;
-                var data = [];
-                var faceSize = Math.pow(this._size, 2) * 3;
-                for (var faceIndex = 0; faceIndex < 6; faceIndex++) {
-                    data.push(floatArrayView.subarray(startIndex, startIndex + faceSize));
-                    startIndex += faceSize;
-                }
-
-                var results = [];
-                var byteArray: Nullable<Uint8Array> = null;
-
-                // Push each faces.
-                for (var k = 0; k < 6; k++) {
-                    var dataFace = null;
-
-                    // To be deprecated.
-                    if (version === 1) {
-                        var j = ([0, 2, 4, 1, 3, 5])[k]; // Transforms +X+Y+Z... to +X-X+Y-Y...
-                        dataFace = data[j];
-                    }
-
-                    // If special cases.
-                    if (!mipmapGenerator && dataFace) {
-                        if (!scene.getEngine().getCaps().textureFloat) {
-                            // 3 channels of 1 bytes per pixel in bytes.
-                            var byteBuffer = new ArrayBuffer(faceSize);
-                            byteArray = new Uint8Array(byteBuffer);
-                        }
-
-                        for (var i = 0; i < this._size * this._size; i++) {
-
-                            // Put in gamma space if requested.
-                            if (this._useInGammaSpace) {
-                                dataFace[(i * 3) + 0] = Math.pow(dataFace[(i * 3) + 0], ToGammaSpace);
-                                dataFace[(i * 3) + 1] = Math.pow(dataFace[(i * 3) + 1], ToGammaSpace);
-                                dataFace[(i * 3) + 2] = Math.pow(dataFace[(i * 3) + 2], ToGammaSpace);
-                            }
-
-                            // Convert to int texture for fallback.
-                            if (byteArray) {
-
-                                var r = Math.max(dataFace[(i * 3) + 0] * 255, 0);
-                                var g = Math.max(dataFace[(i * 3) + 1] * 255, 0);
-                                var b = Math.max(dataFace[(i * 3) + 2] * 255, 0);
-
-                                // May use luminance instead if the result is not accurate.
-                                var max = Math.max(Math.max(r, g), b);
-                                if (max > 255) {
-                                    var scale = 255 / max;
-                                    r *= scale;
-                                    g *= scale;
-                                    b *= scale;
-                                }
-
-                                byteArray[(i * 3) + 0] = r;
-                                byteArray[(i * 3) + 1] = g;
-                                byteArray[(i * 3) + 2] = b;
-                            }
-                        }
-                    }
-
-                    // Fill the array accordingly.
-                    if (byteArray) {
-                        results.push(byteArray);
-                    }
-                    else {
-                        results.push(dataFace);
-                    }
-                }
-
-                return results;
-            }
-
-            if (scene) {
-                this._texture = (<any>scene.getEngine()).createRawCubeTextureFromUrl(this.url, scene, this._size,
-                    Engine.TEXTUREFORMAT_RGB,
-                    scene.getEngine().getCaps().textureFloat ? Engine.TEXTURETYPE_FLOAT : Engine.TEXTURETYPE_UNSIGNED_INT,
-                    this._noMipmap,
-                    callback,
-                    mipmapGenerator, this._onLoad, this._onError);
-            }
-        }
-
-        /**
          * Occurs when the file is raw .hdr file.
          */
-        private loadHDRTexture() {
+        private loadTexture() {
             var callback = (buffer: ArrayBuffer): Nullable<ArrayBufferView[]> => {
                 let scene = this.getScene();
 
@@ -344,11 +167,11 @@ module BABYLON {
                     var dataFace = <Float32Array>((<any>data)[HDRCubeTexture._facesMapping[j]]);
 
                     // If special cases.
-                    if (this._useInGammaSpace || byteArray) {
+                    if (this.gammaSpace || byteArray) {
                         for (var i = 0; i < this._size * this._size; i++) {
 
                             // Put in gamma space if requested.
-                            if (this._useInGammaSpace) {
+                            if (this.gammaSpace) {
                                 dataFace[(i * 3) + 0] = Math.pow(dataFace[(i * 3) + 0], ToGammaSpace);
                                 dataFace[(i * 3) + 1] = Math.pow(dataFace[(i * 3) + 1], ToGammaSpace);
                                 dataFace[(i * 3) + 2] = Math.pow(dataFace[(i * 3) + 2], ToGammaSpace);
@@ -386,48 +209,14 @@ module BABYLON {
                 return results;
             }
 
-            var mipmapGenerator = null;
-
-            // TODO. Implement In code PMREM Generator following the LYS toolset generation.
-            // if (!this._noMipmap &&
-            //     this._usePMREMGenerator) {
-            //     mipmapGenerator = (data: ArrayBufferView[]) => {
-            //         // Custom setup of the generator matching with the PBR shader values.
-            //         var generator = new BABYLON.PMREMGenerator(data,
-            //             this._size,
-            //             this._size,
-            //             0,
-            //             3,
-            //             this.getScene().getEngine().getCaps().textureFloat,
-            //             2048,
-            //             0.25,
-            //             false,
-            //             true);
-
-            //         return generator.filterCubeMap();
-            //     };
-            // }
             let scene = this.getScene();
-
             if (scene) {
                 this._texture = scene.getEngine().createRawCubeTextureFromUrl(this.url, scene, this._size,
                     Engine.TEXTUREFORMAT_RGB,
                     scene.getEngine().getCaps().textureFloat ? Engine.TEXTURETYPE_FLOAT : Engine.TEXTURETYPE_UNSIGNED_INT,
                     this._noMipmap,
                     callback,
-                    mipmapGenerator, this._onLoad, this._onError);
-            }
-        }
-
-        /**
-         * Starts the loading process of the texture.
-         */
-        private loadTexture() {
-            if (this._isBABYLONPreprocessed) {
-                this.loadBabylonTexture();
-            }
-            else {
-                this.loadHDRTexture();
+                    null, this._onLoad, this._onError);
             }
         }
 
@@ -437,9 +226,8 @@ module BABYLON {
                 return this;
             }
 
-            var size = <number>(this._isBABYLONPreprocessed ? null : this._size);
-            var newTexture = new HDRCubeTexture(this.url, scene, size, this._noMipmap,
-                this._generateHarmonics, this._useInGammaSpace, this._usePMREMGenerator);
+            var newTexture = new HDRCubeTexture(this.url, scene, this._size, this._noMipmap,
+                this._generateHarmonics, this.gammaSpace);
 
             // Base texture
             newTexture.level = this.level;
@@ -476,9 +264,8 @@ module BABYLON {
         public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): Nullable<HDRCubeTexture> {
             var texture = null;
             if (parsedTexture.name && !parsedTexture.isRenderTarget) {
-                var size = parsedTexture.isBABYLONPreprocessed ? null : parsedTexture.size;
-                texture = new HDRCubeTexture(rootUrl + parsedTexture.name, scene, size, parsedTexture.noMipmap,
-                    parsedTexture.generateHarmonics, parsedTexture.useInGammaSpace, parsedTexture.usePMREMGenerator);
+                texture = new HDRCubeTexture(rootUrl + parsedTexture.name, scene, parsedTexture.size, parsedTexture.noMipmap,
+                    parsedTexture.generateHarmonics, parsedTexture.useInGammaSpace);
                 texture.name = parsedTexture.name;
                 texture.hasAlpha = parsedTexture.hasAlpha;
                 texture.level = parsedTexture.level;
@@ -511,10 +298,8 @@ module BABYLON {
             serializationObject.level = this.level;
             serializationObject.size = this._size;
             serializationObject.coordinatesMode = this.coordinatesMode;
-            serializationObject.useInGammaSpace = this._useInGammaSpace;
+            serializationObject.useInGammaSpace = this.gammaSpace;
             serializationObject.generateHarmonics = this._generateHarmonics;
-            serializationObject.usePMREMGenerator = this._usePMREMGenerator;
-            serializationObject.isBABYLONPreprocessed = this._isBABYLONPreprocessed;
             serializationObject.customType = "BABYLON.HDRCubeTexture";
             serializationObject.noMipmap = this._noMipmap;
             serializationObject.isBlocking = this._isBlocking;
@@ -522,57 +307,5 @@ module BABYLON {
 
             return serializationObject;
         }
-
-        /**
-         * Saves as a file the data contained in the texture in a binary format.
-         * This can be used to prevent the long loading tie associated with creating the seamless texture as well
-         * as the spherical used in the lighting.
-         * @param url The HDR file url.
-         * @param size The size of the texture data to generate (one of the cubemap face desired width).
-         * @param onError Method called if any error happens during download.
-         * @return The packed binary data.
-         */
-        public static generateBabylonHDROnDisk(url: string, size: number, onError: Nullable<(() => void)> = null): void {
-            var callback = function (buffer: ArrayBuffer) {
-                var data = new Blob([buffer], { type: 'application/octet-stream' });
-
-                // Returns a URL you can use as a href.
-                var objUrl = window.URL.createObjectURL(data);
-
-                // Simulates a link to it and click to dowload.
-                var a = document.createElement("a");
-                document.body.appendChild(a);
-                a.style.display = "none";
-                a.href = objUrl;
-                (<any>a).download = "envmap.babylon.hdr";
-                a.click();
-            };
-
-            HDRCubeTexture.generateBabylonHDR(url, size, callback, onError);
-        }
-
-        /**
-         * Serializes the data contained in the texture in a binary format.
-         * This can be used to prevent the long loading tie associated with creating the seamless texture as well
-         * as the spherical used in the lighting.
-         * @param url The HDR file url.
-         * @param size The size of the texture data to generate (one of the cubemap face desired width).
-         * @param onError Method called if any error happens during download.
-         * @return The packed binary data.
-         */
-        public static generateBabylonHDR(url: string, size: number, callback: ((ArrayBuffer: ArrayBuffer) => void), onError: Nullable<(() => void)> = null): void {
-            // Needs the url tho create the texture.
-            if (!url) {
-                return;
-            }
-
-            // Check Power of two size.
-            if (!Tools.IsExponentOfTwo(size)) { // Need to check engine.needPOTTextures 
-                return;
-            }
-
-            // Coming Back in 3.x.
-            Tools.Error("Generation of Babylon HDR is coming back in 3.2.");
-        }
     }
 }

+ 12 - 12
src/Tools/babylon.assetsManager.ts

@@ -606,8 +606,8 @@ module BABYLON {
          * @param size defines the desired size (the more it increases the longer the generation will be) If the size is omitted this implies you are using a preprocessed cubemap.
          * @param noMipmap defines if mipmaps should not be generated (default is false)
          * @param generateHarmonics specifies whether you want to extract the polynomial harmonics during the generation process (default is true)
-         * @param useInGammaSpace specifies if the texture will be use in gamma or linear space (the PBR material requires those texture in linear space, but the standard material would require them in Gamma space) (default is false)
-         * @param usePMREMGenerator specifies whether or not to generate the CubeMap through CubeMapGen to avoid seams issue at run time (default is false)
+         * @param gammaSpace specifies if the texture will be use in gamma or linear space (the PBR material requires those texture in linear space, but the standard material would require them in Gamma space) (default is false)
+         * @param reserved Internal use only
          */
         constructor(
             /**
@@ -619,9 +619,9 @@ module BABYLON {
              */
             public url: string,
             /**
-             * Defines the desired size (the more it increases the longer the generation will be) If the size is omitted this implies you are using a preprocessed cubemap.
+             * Defines the desired size (the more it increases the longer the generation will be)
              */
-            public size?: number,
+            public size: number,
             /**
              * Defines if mipmaps should not be generated (default is false)
              */
@@ -633,11 +633,11 @@ module BABYLON {
             /**
              * Specifies if the texture will be use in gamma or linear space (the PBR material requires those texture in linear space, but the standard material would require them in Gamma space) (default is false)
              */
-            public useInGammaSpace = false,
+            public gammaSpace = false,
             /**
-             * Specifies whether or not to generate the CubeMap through CubeMapGen to avoid seams issue at run time (default is false)
+             * Internal Use Only
              */
-            public usePMREMGenerator = false) {
+            public reserved = false) {
             super(name);
         }
 
@@ -657,7 +657,7 @@ module BABYLON {
                 onError(message, exception);
             };
 
-            this.texture = new HDRCubeTexture(this.url, scene, this.size, this.noMipmap, this.generateHarmonics, this.useInGammaSpace, this.usePMREMGenerator, onload, onerror);
+            this.texture = new HDRCubeTexture(this.url, scene, this.size, this.noMipmap, this.generateHarmonics, this.gammaSpace, this.reserved, onload, onerror);
         }
     }
 
@@ -821,12 +821,12 @@ module BABYLON {
          * @param size defines the size you want for the cubemap (can be null)
          * @param noMipmap defines if the texture must not receive mipmaps (false by default)
          * @param generateHarmonics defines if you want to automatically generate (true by default)
-         * @param useInGammaSpace defines if the texture must be considered in gamma space (false by default)
-         * @param usePMREMGenerator is a reserved parameter and must be set to false or ignored
+         * @param gammaSpace specifies if the texture will be use in gamma or linear space (the PBR material requires those texture in linear space, but the standard material would require them in Gamma space) (default is false)
+         * @param reserved Internal use only
          * @returns a new {BABYLON.HDRCubeTextureAssetTask} object
          */
-        public addHDRCubeTextureTask(taskName: string, url: string, size?: number, noMipmap = false, generateHarmonics = true, useInGammaSpace = false, usePMREMGenerator = false): HDRCubeTextureAssetTask {
-            var task = new HDRCubeTextureAssetTask(taskName, url, size, noMipmap, generateHarmonics, useInGammaSpace, usePMREMGenerator);
+        public addHDRCubeTextureTask(taskName: string, url: string, size: number, noMipmap = false, generateHarmonics = true, gammaSpace = false, reserved = false): HDRCubeTextureAssetTask {
+            var task = new HDRCubeTextureAssetTask(taskName, url, size, noMipmap, generateHarmonics, gammaSpace, reserved);
             this._tasks.push(task);
 
             return task;