Trevor Baron 6 gadi atpakaļ
vecāks
revīzija
dc0713b13d

+ 1 - 1
dist/preview release/what's new.md

@@ -72,7 +72,7 @@
 - Added support for linking a bone to a transform node ([bghgary](https://github.com/bghgary))
 - Factored out `setDirection` function from `lookAt` for transform node ([bghgary](https://github.com/bghgary))
 - Add support for setting renderingGroupId and creating instances to `AxesViewer` ([bghgary](https://github.com/bghgary))
-- Invert vScale of compressed textures when invertY is set and invertY of ktx textures as they are inverted in the file ([TrevorDev](https://github.com/TrevorDev))
+- Invert vScale of compressed ktx textures as they are inverted in the file and UNPACK_FLIP_Y_WEBGL is not supported by ktx ([TrevorDev](https://github.com/TrevorDev))
 
 ### glTF Loader
 

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

@@ -4279,7 +4279,7 @@ module BABYLON {
             texture.url = url;
             texture.generateMipMaps = !noMipmap;
             texture.samplingMode = samplingMode;
-            texture.invertY = invertY; // Note: texture.invertY may get inverted by the loader, eg. ktx is upsidedown by default
+            texture.invertY = invertY;
 
             if (!this._doNotHandleContextLost) {
                 // Keep a link to the buffer only if we plan to handle context lost
@@ -6182,7 +6182,6 @@ module BABYLON {
 
         private _prepareWebGLTexture(texture: InternalTexture, scene: Nullable<Scene>, width: number, height: number, invertY: boolean, noMipmap: boolean, isCompressed: boolean,
             processFunction: (width: number, height: number, continuationCallback: () => void) => boolean, samplingMode: number = Engine.TEXTURE_TRILINEAR_SAMPLINGMODE): void {
-            invertY = invertY === undefined ? true : invertY;
             var maxTextureSize = this.getCaps().maxTextureSize;
             var potWidth = Math.min(maxTextureSize, this.needPOTTextures ? Tools.GetExponentOfTwo(width, maxTextureSize) : width);
             var potHeight = Math.min(maxTextureSize, this.needPOTTextures ? Tools.GetExponentOfTwo(height, maxTextureSize) : height);
@@ -6202,11 +6201,7 @@ module BABYLON {
             }
 
             this._bindTextureDirectly(gl.TEXTURE_2D, texture, true);
-            if (isCompressed && invertY) {
-                // UNPACK_FLIP_Y_WEBGL is not supported by compressed textures so vScale needs to be inverted
-                texture._invertVScale = true;
-            }
-            this._unpackFlipY(invertY);
+            this._unpackFlipY(invertY === undefined ? true : (invertY ? true : false));
 
             texture.baseWidth = width;
             texture.baseHeight = height;

+ 7 - 2
src/Materials/Textures/Loaders/babylon.ktxTextureLoader.ts

@@ -59,12 +59,16 @@ module BABYLON {
             if (Array.isArray(data)) {
                 return;
             }
-            texture.invertY = !texture.invertY;
+
+            // Need to invert vScale as invertY via UNPACK_FLIP_Y_WEBGL is not supported by compressed texture
+            texture._invertVScale = !texture.invertY;
             var engine = texture.getEngine();
             var ktx = new KhronosTextureContainer(data, 6);
 
             var loadMipmap = ktx.numberOfMipmapLevels > 1 && texture.generateMipMaps;
 
+            engine._unpackFlipY(true);
+
             ktx.uploadLevels(texture, texture.generateMipMaps);
 
             texture.width = ktx.pixelWidth;
@@ -82,7 +86,8 @@ module BABYLON {
          */
         public loadData(data: ArrayBuffer, texture: InternalTexture,
             callback: (width: number, height: number, loadMipmap: boolean, isCompressed: boolean, done: () => void, loadFailed: boolean) => void): void {
-            texture.invertY = !texture.invertY;
+            // Need to invert vScale as invertY via UNPACK_FLIP_Y_WEBGL is not supported by compressed texture
+            texture._invertVScale = !texture.invertY;
             var ktx = new KhronosTextureContainer(data, 1);
 
             callback(ktx.pixelWidth, ktx.pixelHeight, false, true, () => {