KTX Compressed textures too dark(no gamma)

We are trying to compressed our textures suing batch files babylon provide and pvrtextool but generated compressed textures are too dark as gamma space is being removed. Here is the playground link with Linear-RGB: https://www.babylonjs-playground.com/#5FLDS#13
So according to docs, we should be compressing texture with Linear-RGB but for testing purposes we tried sRGB encoding but excepted results is only working inside desktop. ‘astc.ktx’ are still dark when running inside iOS or android. Here is the link with sRGB compressed textures : https://www.babylonjs-playground.com/#5FLDS#14

Is this a pvrtextool issue as according to one of their devs, only their GUI display is broken.

Let us know what we are doing wrong here,


Welcome aboard!

If your albedo texture is in linear space, you should instruct the system because by default it expects this texture to be in gamma space. Simply do newMat.baseTexture.gammaSpace = false to tell the texture is in linear space. That way, your first PG will produce the same result than your second PG.

Note however it’s a mistake to encode the metallic/roughness and normal textures in sRGB space: those ones should always be in linear space.


Thanks for reply and detailed explanation.
That certainly helps with basecolor texture but we are still seeing irregularities with metallic/roughness and normal textures. This is the result without using compression textures and its a same results we are seeing inside substance designer : https://www.babylonjs-playground.com/#5FLDS#19
Roughness is very dark or reflective with compressed textures as compared to raw texture.
We are exporting as ‘raw’ from substance designer/painter. Should be export in linear space?


Yes, roughness and normal maps should be in linear space.

However, I don’t know substance, so can’t help in this matter.

Have you tried ktx2 instead of ktx, to see if there’s a difference between both?

No, haven’t tried that as it still in experimental stage. I tried exporting the greyscale 127,127,127 from photoshop and tried to compressed that but pvrtextool is converting those values to 54,54,54 so whatever format I create the texture in, its always converting those values. I also tried bringing that texture inside unreal engine as unreal also likes the metallic/roughness to be in linear space. Texture value inside ue4 kept it 127,127,127. Even the texture is already in linear space, its does the conversion which is converting values to be low.
Is there a setting inside pvrtextool that can keep those values same ?


The KTX2 loader is not in experimental stage anymore in Babylon, it’s a new feature of the 4.2 release.

I don’t know the tool but I have just downloaded it: have you tried the Edit => Encode page to encode the file with a codec in linear space?

Also, for ktx tools, you have GitHub - KhronosGroup/KTX-Software: KTX (Khronos Texture) Library and Tools. Maybe you will have the options you need here.

So as ktx2 fixed the issue regarding non-color textures mentioned in this post : glTF Extensions in Babylon.js. The mission for Babylon.js is to create… | by Babylon.js | Medium

Yes, I did tried both Edit-Encode and CLI tool to generate but got the same results.

Thanks again for figuring out this issue. Our target application is little big so texture compression is really important for our project.


1 Like

Want to clarify couple of things regarding ktx2 format. So is ktx2 format same as .basis format ? Is there a tutorial or documentation from where i can create ktx2 format ? Is ktx2 supported on all platform?


Here’s a detailed explanation of KTX2 from @bghgary: Basis loader doesn't correctly load alpha channel texture on Android

1 Like