Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Why use crunch compression?

Discussion in 'General Graphics' started by NestorAlgieri, Nov 11, 2018.

  1. NestorAlgieri

    NestorAlgieri

    Joined:
    Sep 11, 2011
    Posts:
    299
    I noticed that if my textures are in an asset bundle they already get compressed. The different b/t crunched and not crunched doesn't make my file much different in size. So if the only advantage is for the slightly smaller size

    - Are there any other advantages?
    - Does it use less RAM at runtime? From my profiling, crunch compression makes no difference.
    - From what I have read, it will cause SOME CPU overhead.

    If anyone else can confirm this that'd be great!
     
    Last edited: Nov 11, 2018
    Helllllllo likes this.
  2. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    2,960
    Maximum compression for individual files is probably best, as any good compression algorithm will simply store already compressed data (since the gains will be zero or sometimes practically zero). So heavily compressed data is really just stored without the outer compression, which gives you quick access, and decompression is split into smaller operations. This improves perceived load-time for large games.

    You'll likely save more overall if different file types use different algorithms for their types of data too. One for textures, another for sound and perhaps a specialised one for text if you're really hardcore about squeezing out every byte :p

    Even if the decompression is slower per byte it'll likely be quicker when you're not simply loading every texture you have all at once. For the final product this is definitely what you want, but during testing it's up to you if you want to sit through the build process if compression is taking longer.
     
    NestorAlgieri likes this.
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    11,818
    The benefit of crunched textures is two fold.

    One is shipping on disk / download size. Crunched textures use less disk space than basic texture compression using the usual GPU friendly image compression formats alone.

    The second benefit is loading time. A crunched image decompresses directly into DXT1 or DXT5 with no additional steps, and decompresses quickly. The idea is a crunched texture can be read from the disk and decompressed into a DXT5 faster than reading a DXT5 straight.

    PNG or JPG images are smaller, but are actually quite slow to decode, and way slower to compress into a GPU friendly format if that's possible at all. So reading a PNG from disk into memory might be faster than a crunched texture, but the crunched texture be in a GPU friendly format ready to be used, and likey even uploaded to the GPU, before the PNG has even finished decoding.

    Images generally don't compress well using general purpose compression algorithms alone, which is why there are so many image compressiom formats out there: you need an algorithm that is designed for images specifically to get the most benefit. However most image formats are slow to decompress, or don’t give that much compression. GPU friendly compression formats are designed to give a constant compression ratio and fast decompression rather than the best compression or quality possible. This is because GPUs need to be able to quickl get the color value of any texel without having to decode the entire image first. PNG and JPG are designed around getting the smallest image possible either losslessly or lossy, but you have to decode the entire image to get the color of any pixel which makes them ill suited for GPU usage. The speed of decoding also wasn’t a huge factor as when the formats were written the expectation was your computer would decompress them as it was slowly downloaded over a modem.

    Crunched textures are essentially a DXT1 or DXT5 texture that's been tweaked so that it can compress better using essentially a general purpose compression algorithm. The result is an image that isn't quite as good as straight DXT5 can do in terms of image quality, and not as small as a JPG on disk, but gets you some of the benefits of each.


    Note, if it wasn’t clear from the above, once a crunched texture is read from disk, it exists in memory using the exact same amount of space as the DXT1 or DXT5 you might otherwise use as at that’s point it is just a DXT1 or DXT5 texture.
     
  4. NestorAlgieri

    NestorAlgieri

    Joined:
    Sep 11, 2011
    Posts:
    299
    Thx for the detailed explanation. But will this benefit carry over to Android devices or will there be more disadvantages due to Android not using DXT?
     
    Holoday likes this.
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    11,818
    Unity added support for crunched ETC, so the benefit is still available. DXTC isn't supported by a lot of Android devices, and so crunched DXTC assets get loaded normally, then converted to uncompressed textures before being uploaded to the GPU.
     
    NestorAlgieri likes this.
unityunity