Skip to main content

WebGL Texture Compression Comparison

We’re adding support for compressed textures to Cesium 1.31 via the DXTn/BCnECT1, and PVRTC WebGL extensions. Textures compressed to these formats stay compressed in GPU memory and are decompressed in parallel in hardware on the fly when sampling the texture. The compression algorithms compress at a fixed rate that can be decompressed quickly on random access of the texture. For transmission over the web, these textures can be compressed further with a lossless compression algorithm, like gzip. The transmitted texture size is comparable to the size of an image compressed to the JPEG format.

GPU compressed texture formats are lossy, meaning that texture details are lost when compressed. There is a trade-off between texture compression time and texture quality; longer compression times improve the quality of the compressed textures. The crunch compressed textures have a smaller transmission size but have an increased compression time and a small increase to load time due to the transcoding to DXTn/BCn at runtime.

There is not one format that is universally supported by all devices. DXTn/BCn is supported by most desktops, ETC1 is supported on most Android devices and some desktops, and PVRTC is supported by most iOS devices. For an application to utilize texture compression, it must test for what formats are supported and request the appropriate texture. An application that needs to support as many devices as possible and use texture compression will need to compress each texture to each of the formats. If there is no texture compression support in the device, either the uncompressed texture or DXTn/BCn can be used. The DXTn/BCn texture can be transcoded to RGB565 on load.

The gltf-pipeline project has been updated to include texture compression options (see the various --texcomp.* options) using Cesium- and 3D Tiles-specific extras properties that reference ktx files. We’ll explore some of the compression formats and compare the compressed output given different quality values. The original image is a typical satellite image or 3D Tile texture. It is a 1024x1024 RGB image. Not all of the compression formats support an alpha channel. Luckily, most satellite imagery and 3D Tile textures will not require one. The transmitted size is 476KB (JPEG), but the in memory decompressed size is 3MB. JPEG compression is also a lossy compression format.

The image differences were generated with Resemble.js. Clicking an image will open the full 1024x1024 image in a new browser tab.

In the tables below, CRN is the format output by crunch. It is a highly compressed, lossy format that quickly transcodes to DXT1 or DXT5. KTX is a container format for storing textures. KTX + gzip is the size of the KTX file after compressing with gzip using the standard settings. PSNR is the peak signal-to-noise ratio. A higher PSNR means the image reconstructed from the compressed image is closer to the source image. The PSNR should only be used to compare an image compressed to the same format. Therefore, one should not compare the PSNR of the images compressed with ETC1 with the PSNR of the images compressed with PVRTC.

All compression times were recorded when running on a 3.20 GHz Intel Xeon E5-1650 CPU and Windows 10. Compressing multiple textures in parallel will, of course, improve compression times for an entire scene.

gltf-pipeline uses crunch to compress to CRN and DXTn/BCn, etc2comp to compress to ETC1, and PVRTexTool to compress to PVRTC. gltf-pipeline will compress textures with commands similar to below. The quality set for each compressed texture is the number above each image.

node ./bin/gltf-pipeline.js -i /path/to/gltf -o /path/to/output --texcomp.quality 9 --texcomp.format crunch-dxt1

node ./bin/gltf-pipeline.js -i /path/to/gltf -o /path/to/output --texcomp.quality 1 --texcomp.format etc1

DXT1

The DXT1 compressed texture is 513KB, which is a sixth of the size of the uncompressed image when in GPU memory. DXT1 does not support an alpha channel.

CRN99KB117KB131KB143KB153KB
KTX + gzip159KB193KB218KB240KB258KB
PSNR26.14027.27227.92428.48728.989
Compression Time(s)3.1273.5063.4134.0764.581
                                                                                                                        
CRN164KB174KB183KB192KB200KB
KTX + gzip273KB286KB297KB305KB311KB
PSNR29.46329.88730.31530.70831.085
Compression Time(s)5.4826.3357.4739.28611.528
                                                                                                                        

DXT5

DXT5 does not compress as well as DXT1, but can also store an alpha channel. The DXT5 compressed texture size is 1025KB, about a third of the size of the uncompressed image. There is also an option to use DXT3. DXT3 uses the same compression for the RGB data of texture but uses less bits to store the alpha channel. DXT5 should be preferred for gradient alpha whereas DXT3 should be preferred for sharp alpha changes. DXT3 is also an unsupported crunch format.

CRN122KB139KB151KB162KB171KB
KTX + gzip222KB261KB285KB302KB315KB
PSNR26.95127.85628.44928.94829.343
Compression Time(s)4.8585.4155.4516.4277.355
                                                                                                                        
CRN179KB186KB194KB200KB207KB
KTX + gzip323KB330KB336KB341KB346KB
PSNR29.74530.09130.42030.73731.018
Compression Time(s)7.5658.9339.33810.61913.153
                                                                                                                        

ETC1

ETC1 has a similar compression ratio to DXT1. The ETC1 compressed texture size is 513KB. ETC1 does not support an alpha channel.

KTX + gzip407KB408KB409KB409KB411KB
PSNR38.759438.921638.921639.037939.1980
Compression Time(s)1.3281.9262.4813.1165.372
                                                                                                                        
KTX + gzip                              413KB417KB419KB421KB425KB
PSNR39.280839.389339.445039.479139.5111
Compression Time(s)8.22116.41929.39043.27960.042
                                                                                                                        

PVRTC 2bpp

The PVRTC 2bpp compressed texture size is 257KB.

KTX + gzip209KB210KB218KB219KB219KB
PSNR40.22240.29441.11941.17441.188
Compression Time(s)0.9089541.14979999.376006418.045295334.1600244
                                                                                                                        

PVRTC 4bpp

The PVRTC 4bpp compressed texture size is 513KB.

KTX + gzip357KB383KB418KB422KB423KB
PSNR40.51541.30042.34842.42342.449
Compression Time(s)1.15247991.42987763.82763615.94420229.9473701
                                                                                                                        

Recommendations

For desktops, you will need to use a DXTn/BCn format. If you are going to use crunch, I suggest DXT1 and setting the quality of textures at the root of the tileset to 1 and increase the quality to 10 as you reach the leaf nodes. As you can see in the table above, the quality of crunched textures quickly degrades. The benefit of crunch is the quick load times. The largest crunched texture was still less than half the size of the same texture in the JPEG format.

If you do not want to use crunch, I would suggest DXT1 with the quality set to 1 for all textures. The DXTn/BCn textures that were not crunched are not shown above. The image diffs are very similar to those in the ETC1 table. The lowest quality DXT1 compressed texture has better quality than the highest quality DXT1 crunched texture and is a little faster than the lowest quality crunched texture.

For Android, You will need to use ETC1. I suggest setting the quality to 1. The compression time drastically increases for very little quality gain.

For iOS, you will need to use PVRTC. I suggest using PVRTC 4bpp and setting the quality between 3 and 6. If your app is memory constrained and you can tolerate more error in the compressed texture, you can switch to using PVRTC 2bpp and setting the quality to be between 1 and 4.