How to create ktx2 correctly

Hi guys,

first of all I would like to say big thank you to @donmccurdy for many usefull advices on this forum. I would like to ask, if you can tell me what am I doing wrong regards to KTX2 files generation. What I do is following:

  1. Download the following application Release v4.0.0 · KhronosGroup/KTX-Software · GitHub
  2. Based on the documentation Khronos Texture Tools: toktx I take my JPG file and generate KTX2 file: toktx --t2 Atlas1.ktx2 Atlas1.jpg
  3. Upload the file to CDN
  4. Prepare Three.js project with KTX2Loader (three.js docs) and Basis Universal GPU Texture Compression ( downloaded from three.js/examples/js/libs/basis at dev · mrdoob/three.js · GitHub
  5. When I tried to load the texture created by the described tool set I received:
    Error: THREE.KTX2Loader: .transcodeImage failed.
    at transcode (7ca89d84-a942-4a9a-bbc6-3923efc8d57e:107:23)
    at 7ca89d84-a942-4a9a-bbc6-3923efc8d57e:46:103

I assumed that the problem is on my script but it was not true. I tested my script with textures found on Three.js Github and all 3 of them are working correctly:

  • sample_etc1s.ktx2
  • sample_uastc.ktx2
  • sample_uastc_zstd.ktx2

All 3 of them are correctly loaded in my project. So I assume that the problem is not in JS/TS but in the KTX2 file that I generated. I also tried to compress the KTX2 file via ktxsc tool: ktxsc --encode etc1s --clevel 5 -qlevel 255 -o Atlas1.ktx2 Atlas1.ktx2

But without any possitive result. So I would like to ask if you can give me some advice what am I doing wrong. This is the list of all files:


Hi @Dominik_Halvonik! As far as I can tell your file is OK, and it passes the KTX2 validation tool. I’m not sure why there would be a transcoding error. Sometimes errors happen if the input dimensions are invalid — dimensions must be multiples of 4, and sometimes must be powers of two — but this file is fine on both counts. Testing the KTX2 file in it looks OK to me, and testing it with the code from the webgl / loader / ktx2 example also works. If this isn’t working on your device with the same texture and the same code, I think you may need to share the code and details about your device, browser, and GPU.

Aside — you might want to include the --genmipmap if this texture will be shown on a 3D mesh. It adds some to the file size but eliminates flickering when the mesh or camera move. But that shouldn’t be causing the error here.