Texture Compression
Texture data is stored in a device's video memory (or VRAM). It is important to ensure that your application does not exhaust VRAM as this can cause undesirable things like browser tab crashes.
The Editor has the ability to apply lossy compression schemes to your textures to dramatically reduce the amount of VRAM used using Basis.
Basis is a 'super-compressed' texture format. It's a platform independent lossy block compression format that can be transcoded to the natively supported hardware compression format at runtime. Supported transcode formats are ASTC, DXT, ETC2, ETC, PVR and ATC (selected in that order where available).
Consider this texture asset:
It's a 512x512 JPG that is 202KB in size. However, JPG is a compressed format and when passed to the graphics engine, it is expanded to an uncompressed RGB8 format that occupies 1.05MB of VRAM (including mipmap levels).
Enabling texture compression achieves the following results:
The compression has achieved a 6 times reduction in VRAM usage. Furthermore, in this case, compression has also reduced download size from 202KB to as little as 46KB using the Default quality setting and ETC Mode.
Below is a side by side comparison of the brick texture on Mac with Chrome:
Here is another example of the PlayCanvas cube with Basis (ETC mode) and without on Mac with Chrome:
Using Basis Texture Compression
Once the texture has been imported into the Editor, select it and scroll down in the inspector to find the Compression section.
- Tick BASIS.
- Click on Import Basis to add the WASM module for the Basis runtime to the project (this only needs to be done once).
- Change mode from 'ETC (smaller size, lower quality)' to 'ASTC (larger size, higher quality)' if you need to reduce compression artifacts on this texture.
- Tick Normals if compressing a normal map.
- Change the quality setting to balance file size vs quality. Lower quality results in smaller file sizes.
- Click on Compress Basis.
The Basis WASM module will add 253KB of extra gzipped data to the preload download size but that should be offset by the texture size savings compared to using the legacy texture compression format files (see below).
To remove Basis compression from a texture:
- Untick BASIS.
- Click on Compress Basis.
If you would no longer want to use Basis, remove Basis compression from all textures and delete the Basis folder from the project.
Basis Limitations
There are some limitations of Basis texture compression in PlayCanvas.
- The PVR format only supports textures that have dimensions that are both square (same width and height) and power of two (e.g. 256, 512, 1024 and so on). Older iOS devices (with an A6 SoC or lower like the iPhone 5 and 5C) and older iOS versions (13.7 and lower) only support PVR. A Basis texture that is non-square or non-power of two cannot be transcoded to PVR format but will instead use a 16-bit 565 pixel format. It will still display correctly, although may occupy more VRAM.
- The maximum texture dimensions supported for Basis compression are 4096x4096. Textures larger than this would take an inordinate amount of time to compress so this is disabled.
Legacy Texture Compression
We strongly recommend using Basis compression where possible as it requires a single texture file to cover all platforms and it is also a much smaller file compared to the legacy formats. Our tests show Basis to be ~50% smaller with minimal difference in quality.
The Legacy Texture schemes are:
- DXT: Typically supported by desktop devices.
- PVR: Typically supported by iOS devices.
- ETC: Typically supported by Android devices.
To use the Legacy Texture Compression options, select the texture and scroll down in the inspector to find the Compression section.
- Tick LEGACY.
- Tick all the formats you wish to use.
- Click on Compress Legacy.
To remove a or several formats:
- Untick all the formats you wish to remove.
- Click on Compress Legacy.
Migrating from Legacy to Basis Texture Compression
If you have a project that is already using the Legacy Texture Compression formats and wish to use Basis, do the following:
- Remove all the legacy texture formats.
- Enable and use Basis.