.basis texture compression in inspector

Hi together,

we have been playing around with compressed texture formats recently. And noticed that for .basis files. that the inspector always shows ‘RGBA & Uncompressed’ (.dxt-ktx works as intended).

For further understanding we debugged the code a bit and came to a conclusion. However, we are not super deep into the topic and would like to discuss our findings first.

Thesis
Basis textures are correctly loaded and passed to the GPU in a compressed format (if supported). However, we think the babylon texture object is not updated correctly. The inspector shows the format to be RGBA and uncompressed

What I’ve noticed on my PC:

  • basisTextureLoader.ts
    • loadData
      • line 100 (before TranscodeAsync is called)
        supportedCompressionFormats → s3tc & bc7 = true
      • line 105 (inside the callback before LoadTextureFromTranscodeResult is called)
        → result.format = 6 (BASIS_FORMATS.cTFBC7)
  • basis.ts
    • LoadTextureFromTranscodeResult
      → else path is taken since format is not -1
      → the texture format is determined as TEXTUREFORMAT_COMPRESSED_RGBA_BPTC_UNORM with BasisTools.GetInternalFormatFromBasisFormat
      → gl.texture is created with the correct format (engine._uploadCompressedDataToTextureDirectlygl.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT)
      → texture.format and texture.type is never set.

Conclusion / Discussion
With my limited knowledge about this topic, I would think that it is only a display error and that within the else section of the LoadTextureFromTranscodeResult function the texture.format and texture.type must also be determined and updated.

  • texture.format: should probably be the same as BasisTools.GetInternalFormatFromBasisFormat
  • texture.type: no idea how to define that…

cc @sebavan / @bghgary

It sounds weird indeed, I ll try to have a fix today.

1 Like

Thanks so much!

One additional thing I’ve noticed today, is that the fallback for devices, that don’t support texture compression, might not be working as intended. However, I don’t have such a device and therfore manualy set all settings within the supportedCompressionFormats to false right before basisTextureLoader.ts -> TranscodeAsync is called. The result was a completly black image.

By removing the else part in basis.ts -> GetSupportedTranscodeFormat. I was able to force the fallback option and get an image displayed. But this doesent seem to be a good way to me. First of all it always fallbacks to RGB even if the source image has a alpha channel. And more importantly as soon as I tried to inspect the texure in the babylon inspector it turned black again…

Please let me know if these are not related and if I should create a sperate forum entry for this.

Ok I have a fix for the format, will look into the second part ASAP and let you know. (THANKS A MEGATON for your thorough analysis)

Here is the PR: Fix issues with basis texture and inspector (display format, preview window and broken texture) by sebavan · Pull Request #12853 · BabylonJS/Babylon.js · GitHub

Thanks a lot again as it was actually 4 tiny issues related to each other :slight_smile:

1 Like

Awesome thank you! Looking at the PR is the fallback of a .basis file always a RGB texture without alpha information? Or would it be possible to fallback to a RGBA depending on the source file?

Currently only RGB looks supported with the 565 format but let s add @bghgary to know if Basis supports RGBA fallbacks as well

1 Like