Texture

Texture Compression

KTX2 (Khronos Texture Container version 2.0) is the latest texture compression scheme launched by Khronos. KTX2 will transcode runtime to the corresponding format of compressed texture (BC/PVRTC/ETC/ASTC) based on the device platform support. Using ktx2 in glTF requires including the KHR_texture_basisu extension. Galacean has supported KTX2 since version 1.1.

Editor Usage

Global configuration can be done during project export. KTX2 indicates enabling texture compression, while Original indicates no compression.

You can also configure different compression formats for individual texture resources. Check overwrite under the texture panel in the editor to override the global configuration:

After choosing KTX2, you can select different compression formats.

FormatDescription
ETC1SSmall size, very low memory, but lower quality, suitable for albedo, specular maps. You can set the compression quality through Quality (the higher the value, the better the rendering quality)
UASTCLarge size, high quality, suitable for normal maps

Script Usage

Simply use resourceManager to load:

engine.resourceManager.load("xxx.ktx2");
// Or
engine.resourceManager
  .load<Texture2D>({
    type: AssetType.KTX2,
    url: "xxx.ktx2"
  })
  .then((tex) => {
    material.baseTexture = tex;
  });

Compatibility

Special attention is needed:

  • KTX2 transcoding uses WebAssembly technology, which requires ensuring the use of Chrome 57+ and iOS 11.3+ (there is a WebAssembly bug in versions 11.0 ~ 11.2).

  • The engine will default to enabling worker parsing of KTX2 files, but on IOS systems below version 16, there is a chance of no return when loading necessary KTX2 parsing files via worker. This can be bypassed by not using worker on IOS:

// Determine if the system is IOS
const isIOS = SystemInfo.platform === Platform.IPhone || SystemInfo.platform === Platform.IPad;
// Set the number of workers to 0 in IOS environment
webGlEngine.create({ canvas: "canvas", ktx2Loader: { workerCount: isIOS ? 0 : 4 } });

Was this page helpful?