Terrain Compression
I wanted to see if any of the terrain data can be compressed down, mostly to reduce GPU memory usage. I implemented some fast texture compression algorithms for BC1, BC3, BC4, BC5, and BC7 compression. BC6 and BC7 are not terribly useful in this situation because they involve a complex lookup table, so data from different textures can't be mixed and matched. I found two areas where texture compression could be used, in alpha layers and normal maps. I implemented BC3 compression for terrain alpha and could not see any artifacts. The compression is very fast, always less than one second even with the biggest textures I would care to use (4096 x 4096).
For normals, BC1 (DXT1 and BC3 (DXT5) produce artifacts: (I accidentally left tessellation turned on high in these shots, which is why the framerate is low):
BC5 gives a better appearance on this bumpy area and closely matches the original uncompressed normals. BC5 takes 1 byte per pixel, one quarter the size of uncomompressed RGBA. However, it only supports two channels, so we need one texture for normals and another for tangents, leaving us with a total 50% reduced size.
Here are the results:
2048 x 2048 Uncompressed Terrain:
- Heightmap = 2048 * 2048 * 2 = 8388608
- Normal / tangents map = 16777216
- Secret sauce = 67108864
- Secret sauce 2 = 16777216
- Total = 104 MB
2048 x 2048 Compressed Terrain:
- Heightmap = 2048 * 2048 * 2 = 8388608
- Normal map = 4194304
- Tangents = 4194304
- Secret sauce = 16777216
- Secret sauce 2 = 16777216
- Total = 48 MB
Additionally, for editable terrain an extra 32 MB of data needs to be stored, but this can be dumped once the terrain is made static. There are other things you can do to reduce the file size but it would not change the memory usage, and processing time is very high for "super-compression" techniques. I investigated this thoroughly and found the best compression methods for this situation that are pretty much instantaneous with no noticeable loss of quality, so I am satisfied.
- 5
1 Comment
Recommended Comments