瀏覽代碼

Step 3 all good with decode to texture

sebastien 7 年之前
父節點
當前提交
c1bea6f6e8

+ 2 - 2
src/Engine/babylon.engine.ts

@@ -2446,13 +2446,13 @@
                 if (!requiredWidth) {
                     requiredWidth = texture.width;
                     if (lodLevel) {
-                        requiredWidth = requiredWidth / (2 * lodLevel);
+                        requiredWidth = requiredWidth / Math.pow(2, lodLevel);
                     }
                 }
                 if (!requiredHeight) {
                     requiredHeight = texture.height;
                     if (lodLevel) {
-                        requiredHeight = requiredHeight / (2 * lodLevel);
+                        requiredHeight = requiredHeight / Math.pow(2, lodLevel);
                     }
                 }
 

+ 5 - 4
src/Materials/Textures/babylon.baseTexture.ts

@@ -301,10 +301,11 @@
 
             if (this._texture.isCube) {
                 if (level != 0) {
-                    for (var u = 0; u < level; u++) {
-                        width = Math.round(width / 2);
-                        height = Math.round(height / 2);
-                    }
+                    width = width / Math.pow(2, level);
+                    height = height / Math.pow(2, level);
+
+                    width = Math.round(width);
+                    height = Math.round(height);
                 }
 
                 return engine._readTexturePixels(this._texture, width, height, faceIndex, level);

+ 17 - 8
src/Tools/babylon.environmentTextureTools.ts

@@ -243,10 +243,11 @@ module BABYLON {
             let rgbmPostProcess: Nullable<PostProcess> = null;
             let cubeRtt: Nullable<InternalTexture> = null;
 
-            if (engine.getCaps().textureHalfFloatRender) {
+            var canRenderToHalfFloat = engine.getCaps().textureHalfFloatRender;
+            if (canRenderToHalfFloat) {
                 textureType = Engine.TEXTURETYPE_HALF_FLOAT;
                 expandTexture = true;
-                rgbmPostProcess = new PostProcess("rgbmDecode", "rgbmDecode", null, null, 1, null, Texture.NEAREST_SAMPLINGMODE, engine, false, undefined, textureType, undefined, null, false);
+                rgbmPostProcess = new PostProcess("rgbmDecode", "rgbmDecode", null, null, 1, null, Texture.TRILINEAR_SAMPLINGMODE, engine, false, undefined, textureType, undefined, null, false);
                 texture._isRGBM = false;
                 texture.invertY = false;
                 cubeRtt = engine.createRenderTargetCubeTexture(texture.width, {
@@ -274,9 +275,19 @@ module BABYLON {
                     const imageData = specularInfo.mipmaps[i * 6 + face];
                     let bytes = new Uint8Array(arrayBuffer, specularInfo.specularDataPosition! + imageData.position, imageData.length);
                     //construct image element from bytes
+                    var blob = new Blob([bytes], { type: 'image/png' });
+                    let url = URL.createObjectURL(blob);
+                    
+                    // let a: any = document.createElement("a");
+                    //     document.body.appendChild(a);
+                    //     a.style = "display: none";
+                    
+                    // a.href = url;
+                    // a.download = "env_" + i + "_" + face + ".png";
+                    // a.click();
+
                     let image = new Image();
-                    let src = URL.createObjectURL(new Blob([bytes], { type: 'image/png' }));
-                    image.src = src;
+                    image.src = url;
 
                     // Enqueue promise to upload to the texture.
                     let promise = new Promise<void>((resolve, reject) => {;
@@ -291,14 +302,12 @@ module BABYLON {
                                 rgbmPostProcess!.getEffect().executeWhenCompiled(() => {
                                     rgbmPostProcess!.onApply = (effect) => {
                                         effect._bindTexture("textureSampler", tempTexture);
-                                        // TODO
-                                        if (i) {
-                                            effect.setFloat2("scale", i + 1, i + 1);
-                                        }
+                                        effect.setFloat2("scale", 1, 1);
                                     }
                                     engine.scenes[0].postProcessManager.directRender([rgbmPostProcess!], cubeRtt, true, face, i);
                                     engine.restoreDefaultFramebuffer();
                                     tempTexture.dispose();
+                                    window.URL.revokeObjectURL(url);
                                     resolve();
                                 });
                             }