KTX / ASTC / ETC support

Hello community :slight_smile: !

CONTEXT

I’m currently using gltf-transform to transform my textures to KTX / using etc1s conversion using on my glb :

gltf-transform etc1s output1.glb output2.glb --quality 255 --verbose

The KTX2Loader return as compressed format supports :

astc / etc2 / pvrtc

So naturally the basis module transcode the textures to any supported format. it works.

PROBLEM

There is a particular phone I had feedbacks on, Iphone 13 pro max, which get supports from ASTC and ETC1
But, We can also see that etc1 support is set to false when using webGL2, even if the format is supported for some design reasons.

In this setup the file converted using ETC1 does not run and uses fallback :

‘THREE.KTX2Loader: No suitable compressed texture format found. Decoding to RGBA32.’

Im reading on the discussion here : WebGLTextures: Use `gl.texStorage2D()` with compressed textures. by Mugen87 · Pull Request #22928 · mrdoob/three.js · GitHub that etc1 on webgl2 cannot work by design.

QUESTIONS

There are a lot questionnement :

1 ) Is there a universal KTX compression format that would transcode to any format the system support ? ASTC produces way higher texture sizes and gets really heavy and not suitable for the application I’m working on. Like 1 file for all other than ASTC ?
Am I stuck with producing an ASTC file for the Iphone 13 pro max particular setup ?

2 ) On a second point, I’ll need some memory back, unless I forgot everything, and being completely wrong, I think I remember using .basis format file just standalone back in days ( like years ago ), using a basistextureloader that could handle the conversion from a basis file to any supported format, even ASTC ? ( unless I’m completely wrong of course )

3 ) “when using gl.texStorage2D() ETC1 is not supported”, is the issue that cuts down the support for ETC1 in webGL2.
Is there a way around this ?
I’m really not aware of the usage of texImage2D vs texStorage2D, and not aware at all of the current design of threejs around this, can someone explain ? :slight_smile:

Thank you a lot

In short, no. texImage2D() is problematic for many reasons and you can read about that in the following issue (also check out the links in the first comment).

Yes, and keep in mind that ASTC is actually the better format. For mobile devices, you want ASTC by default and fall back to ETC1/2. Do you mind explaining in more detail why you experience issues with ASTC output? Can you also share the exact format that is going to be produced? It should be something like RGBA_ASTC_4x4_Format.

There was a BasisTextureLoader but it has been deprecated and removed in favor of KTX2Loader. You can read more about the deprecation here:

Thanks a lot for the answers.

Problem is,
Model before ASTC : 10mb
After ASTC : 50mb

Where ETC stays the same or get lower like 6mb.

I’m trying to solve both network bandwidth, and GPU memory usage.

ETC solves them both, but ASTC is really big.

Yes, RGBA_ASTC_4x4_Format is the format produced using ASTC.

@Mugen87 from the earlier thread, I think my expectation was that ETC1 support should be possible in WebGL 2 in the not-too-distant future. Possibly that was blocked on the ANGLE/Metal backend for Webkit. ETC1 is probably the most basic and common compression option for a mobile device, so it’s a shame to not support it in WebGL 2 … if gl.texStorage2D() simply isn’t compatible, maybe that’s something we can flag to browser vendors? :confused:

I’m really sorry for asking dumb questions.

I just digged up a very old project ( 4 years ago ) and was checking it was using .basis file exported from basisu.

Apart from the container KTX, what would be the difference between today’s KTX / ASTC / ETC compression, and this .BASIS universal file that was handling all transcoding just alone.

Wouldn’t it be beneficial to still get 1 file that handle all formats / transcoding ?
( really dumb question, I’m sorry )

Probably worth giving a try. I would also like to know why the extension is in general not available and not just on certain platforms.

1 Like

This is definitely the goal. ETC1 failing in WebGL2 is a browser environment problem, and our current workaround for that is not ideal.

No difference in .ktx2 vs. .basis here. The .basis file contains exactly the same data, but we never added any workaround in BasisTextureLoader for WebGL2 bugs. If the .basis file is working, then it might be that newer iOS versions have fixed this WebGL2 problem and we can safely remove the workaround in KTX2Loader, but we’ll have to test it.

It makes all sense.

Thank you very much for the explanation