Texture sizes in unity

Hi
I have a 2048 tex that windows reports as been only 348kb in size but in unity it shows as 16mb and 5.7mb compressed what is the reason for these differences and is the texture really as big as that in unity when in windows its so small?

You might want to take a look at this post:

… and perhaps this one too:

1 Like

Different kinds of image compression exist for different purposes.

That image is likely a .png file. That type of compression is great for images because it is lossless (the uncompressed image looks exactly the same as the original), and can shrink the size of a texture significantly which is great for memory, disk space, and network usage. But it’s relatively expensive to decompress and different images compress to different sizes. More specifically different parts of an image compress to different amounts, which is bad for real time rendering.

GPUs can’t render a png directly. Even when rendered in your web browser on a web page, or by windows itself, it’s decompressing the image and sending the full, uncompressed version to the GPU to render, so that 348kb png is taking 16mb on the GPU’s RAM, and an additional 16mb of CPU RAM, on top of that 348kb.

Why can’t a GPU use the png directly? Because of that variable compression I mentioned. When a GPU is rendering a pixel on the screen, to render that pixel the color of a texture it first calculates which texel (pixel of a texture) it needs, then reads that texel, and uses that color. With an uncompressed texture you can easily find that texel in the texture data with a little math. If you have a 4x4 texture and want the texel at the first pixel on the right, second from the top, you know that’s pixel 8 out of 16, so you can read the image data starting at 8/16ths (or half) of the way through and you’re done. With a png texture depending on the contents of the image that data for that pixel might be at 8/16, but it might not. It could be in the first few bits, or the last, or anywhere in between. For an image that’s 4x4 pixels it’s not that big of a deal to just decompress that every time, but for a 2048x2048 texture the cost of decompressing over and over adds up. To make this worse, because of the highly parallel nature of GPUs, that work to decompress the PNG might not be shared between two pixels on screen rendering the same texture, so both pixels have to entirely decompress the image every frame. Thus it’s faster to just decompress it once before hand and upload the uncompressed version.

So instead of png or other variable length compression types, GPUs use fixed compression ratio formats. A texture of X size and Y color type will be exactly the same size regardless of the content, at some ratio smaller than the original uncompressed image. More to the point, the color of texel 8/16 will always be in the same place in the image data. Actually, a common technique GPU texture formats use is what’s referred to as blocks, often in 4x4 texels. To get the color of a texel you can easily figure out which block it lives in, decompress that block by itself, and get the texel color you need.

So, that was a complicated way to say windows is showing the size of the compressed png. Unity is showing the size of the uncompressed image (a bmp or tga file’s size will roughly match the uncompressed size) or the size of the image when using a specific GPU compression. Different image compression types compress an image by different amounts, and with different goals.