Solved Is it really better to use assetbundles for 2D resources?

SlimerJSpud

Invaluable member
Messages
1,088
Reactions
932
Points
143
There's a new plugin that makes it really easy to put in a panoramic image as a background in a scene. I have several royalty-free HDRIs converted to jpg that work well with this. I see most skyboxes packaged as assetbundles. Is this really the best way to package 2D resources? An assetbundle has to have the whole thing loaded to choose one of them. This plugin lets you browse for an image file. I'm thinking of packaging the image files in Custom/Images. Some of them are rather large: one 16K jpg can be 20 MB. Going through all the Unity process seems like a waste for 2D resources.
 
Solution
Assets packaged as assetbundle should be significantly faster to load. Also it uses less GPU memory, if you choose a hardware compressed texture format, e.g. like DXT. Unity handles that for you, but you have to choose a matching format.
If you use a regular image file instead, since a graphics card doesn't know what a JPG or PNG is, it has to be decompressed on a single core by the CPU and is then stored uncompressed in GPU memory. That takes time. And an uncompressed 8K image is like 96MB, at least. (By the way there is no point in 16K skies by the way...as maximum texture size Unity can handle is 8192x8192)

Hardware compressed textures need more space on disk, but less memory at runtime (like 1/6) and can also render much...
Assets packaged as assetbundle should be significantly faster to load. Also it uses less GPU memory, if you choose a hardware compressed texture format, e.g. like DXT. Unity handles that for you, but you have to choose a matching format.
If you use a regular image file instead, since a graphics card doesn't know what a JPG or PNG is, it has to be decompressed on a single core by the CPU and is then stored uncompressed in GPU memory. That takes time. And an uncompressed 8K image is like 96MB, at least. (By the way there is no point in 16K skies by the way...as maximum texture size Unity can handle is 8192x8192)

Hardware compressed textures need more space on disk, but less memory at runtime (like 1/6) and can also render much faster because of that. Slow memory access is often a reason for performance limitation.

I have not measured anything with VaM, but I would expect the gain in scene loading performance will likely be comparable to the difference between loading regular sounds and assetbundle sounds, which is like 50-100x faster. Of course you would usually only have single sky, not like hundred you have with sounds, so probably takes only a second or two to load, so you may not notice much ;)

When you store multiple skies into one assetbundle, make sure to use chunk-based LZ4 compression or uncompressed, with LZMA compression performance will tank as the whole bundle needs to be extracted. If you can affort the disk space, I recommend uncompressed...because the texture is compressed already anyway, you don't gain that much from compressing a second time, just loosing time when loading it. (not to mention that a VAR would try to compress a third time :D)
 
Upvote 0
Solution
Good info, thanks. It seems like everybody does their HDRI conversions as assetbundles.

Using the plugin I linked to, even a 16K image file loaded in a couple of seconds. I haven't tried 8K yet, but the 16K looked a lot better than a 4K of the same image.
 
Upvote 0
Back
Top Bottom