We are using the pvrtextool to compress the KTX textures and both our DXT/KTX textures and our BASISU/KTX2 texture that are supposedly encoded in gamma space. But they are being displayed differently in the Babylon playground where DXT appears to be in linear space(and shows up very dark) but KTX2 are fine out of the box. We do find out that if we set
gammaSpace = false it shows up correctly but wonder why since they were encoded in gamma space. The playground is here https://www.babylonjs-playground.com/#5I4TDH#9 (if you comment out the
compressionTextureFormat you can see the KTX2 looks correctly)
In this case you need to let the engine know your texture are already in linear space I guess: https://www.babylonjs-playground.com/#5I4TDH#10
We’re trying to figure out why the behaviour is inconsistent though - not sure if this is a PVRTex issue, or if it’s on the Babylon side, or of this is simply down to the compression formats being used in some way. In principle, I would expect textures with different compression but the same colour space, to not require different code paths to be loaded, but this is currently not the case.
compressed_textures.zip (5.2 MB)
I’ve attached here the DXT .ktx and the BASISU .ktx2 textures that are being loaded above.
At least PVRTex reports that these are both sRGB textures and loads them up correctly, but in the Babylon example, the BASISU .ktx2 texture loads correctly, whereas the DXT/BC1 .ktx needs
gammaSpace = false to be set. i.e. Babylon is loading this texture in linear space, but it should already be in gamma space, so something weird is happening somewhere.
Adding @bghgary our KTX guru
The issue is that the old .ktx2 files aren’t compressed properly – they’re using a UNORM texture format. So you need to do the conversion to linear space in the shader.
The new .ktx files are compressed properly – they’re properly using an SRGB texture format. Unfortunately, Babylon doesn’t seem to turn off the the shader fallback define (GAMMAALBEDO) in this case.
IMO, Babylon should only turn on the shader fallback define if gammaTexture is true and the texture format provided is not sRGB.
Hey, sorry, I missed this ping. I will look at this soon.
I’m still looking at it. My local fix has some issues, but I should have something soon.
I just merged the PR. Thanks @JasperRLZ for starting it. Once the PR is deployed, this problem should be fixed on the playground. In the meantime, you can test it using this link: https://playground.babylonjs.com/?snapshot=refs/pull/12362/merge#5I4TDH#9