Browse Source

Fix env creation check

sebavan 4 years ago
parent
commit
4490515ce0
1 changed files with 15 additions and 1 deletions
  1. 15 1
      src/Misc/environmentTextureTools.ts

+ 15 - 1
src/Misc/environmentTextureTools.ts

@@ -154,7 +154,12 @@ export class EnvironmentTextureTools {
 
         let engine = internalTexture.getEngine() as Engine;
 
-        if (texture.textureType === Constants.TEXTURETYPE_UNSIGNED_INT) {
+        if (texture.textureType !== Constants.TEXTURETYPE_HALF_FLOAT &&
+            texture.textureType !== Constants.TEXTURETYPE_FLOAT &&
+            texture.textureType !== Constants.TEXTURETYPE_UNSIGNED_BYTE &&
+            texture.textureType !== Constants.TEXTURETYPE_UNSIGNED_INT &&
+            texture.textureType !== Constants.TEXTURETYPE_UNSIGNED_INTEGER &&
+            texture.textureType !== -1) {
             return Promise.reject("The cube texture should allow HDR (Full Float or Half Float).");
         }
 
@@ -181,6 +186,15 @@ export class EnvironmentTextureTools {
             // All faces of the cube.
             for (let face = 0; face < 6; face++) {
                 let faceData = await texture.readPixels(face, i, undefined, false);
+                if (faceData && faceData.byteLength === (faceData as Uint8Array).length) {
+                    const faceDataFloat = new Float32Array(faceData!.byteLength * 4);
+                    for (let i = 0; i < faceData.byteLength; i++) {
+                        faceDataFloat[i] = (faceData as Uint8Array)[i] / 255;
+                        // Gamma to linear
+                        faceDataFloat[i] = Math.pow(faceDataFloat[i], 2.2);
+                    }
+                    faceData = faceDataFloat;
+                }
 
                 let tempTexture = engine.createRawTexture(faceData, faceWidth, faceWidth, Constants.TEXTUREFORMAT_RGBA, false, true, Constants.TEXTURE_NEAREST_SAMPLINGMODE, null, textureType);