mirror of
https://github.com/galacean/engine.git
synced 2026-05-14 06:27:55 +08:00
61 lines
2.8 KiB
Plaintext
61 lines
2.8 KiB
Plaintext
---
|
|
order: 4
|
|
title: Texture Compression
|
|
type: Graphics
|
|
group: Texture
|
|
label: Graphics/Texture
|
|
---
|
|
|
|
<Callout>
|
|
**[KTX2](https://www.khronos.org/ktx/)** (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](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md) extension. Galacean has supported KTX2 since version 1.1.
|
|
</Callout>
|
|
|
|
## Editor Usage
|
|
|
|
Global configuration can be done during [project export](/docs/platform/platform/). **KTX2** indicates enabling texture compression, while **Original** indicates no compression.
|
|
|
|
<Image src="https://gw.alipayobjects.com/zos/OasisHub/ea6cf83b-e55c-4ff5-ae3b-c37073636df7/image-20250603113737512.png" style={{zoom: "50%"}}/>
|
|
|
|
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:
|
|
|
|
<Image src="https://gw.alipayobjects.com/zos/OasisHub/b8627078-4aeb-4b03-947e-c48e96a05528/image-20250603114018740.png" style={{zoom: "50%"}} />
|
|
|
|
After choosing **KTX2**, you can select different compression formats.
|
|
|
|
| Format | Description |
|
|
| ------ | ------------------------------------------------------------ |
|
|
| ETC1S | Small 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) |
|
|
| UASTC | Large size, high quality, suitable for normal maps |
|
|
|
|
## Script Usage
|
|
|
|
Simply use `resourceManager` to load:
|
|
|
|
```typescript
|
|
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](https://bugs.webkit.org/show_bug.cgi?id=181781) 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:
|
|
|
|
```typescript
|
|
// 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 } });
|
|
```
|