Sunday, August 21, 2022
HomeGame Developmenttextures - Clean 2.2 KB sized PNG prices 2.1 MB in Unity?...

textures – Clean 2.2 KB sized PNG prices 2.1 MB in Unity? What does this characterize? What to do?


PNG compression works by predicting the following pixel from the pixels that got here earlier than.

If the picture is totally clean, ie. each pixel is precisely the identical because the pixel that got here earlier than, then that prediction is very straightforward, so you will get tiny file sizes even for high-resolution photos. That makes it a deceptive benchmark to make use of right here.

The difficulty is, GPUs can not learn PNGs. They want to have the ability to search to totally different spots within the texture at random, however to try this with a PNG, you’d must learn and do calculations on the information for all pixels earlier than the one you are attempting to learn earlier than you might decide its color.

So PNG textures must be decompressed to make use of for rendering. A technique to try this is to unpack them to literal RGBA8: 8 bits per color channel, 32 bits per pixel (bpp).

Working that out on your picture, that is 1490 x 376 pixels x 32 bpp = 17 928 680 bits = 2 240 960 bytes = 2.137 MiB.

This appears to point that since you’ve set the feel sort to “Editor GUI and Legacy GUI”, Unity is assuming you want lossless dealing with of this picture, so choosing “Automated” beneath the import format choices is defaulting to RGBA8.

That 2.137 MiB is the quantity of video RAM it’s going to take to make use of this texture in your scene. If you could edit the feel from a C# script, then you definitely’ll additionally want a corresponding 2.137 MiB of essential RAM for the CPU-side copy of the feel.

There are additionally GPU compression codecs that work in another way – sometimes utilizing a set variety of bits per pixel (bpp). That is necessary for realtime rendering – the mounted bitwidth of every block of pixels means you’ll be able to calculate precisely what reminiscence offset to hunt to if you need to pattern a particular a part of the feel, quite than needing to scan and decompress all of the pixels resulting in that one as PNG does. This implies we will work with them straight from their compressed format, quite than decompressing them to full 32 bpp RGBA information.

For example, if we retailer this texture in DXT-5, it’s going to break the picture into 4×4 blocks, rounding your picture measurement as much as 1492×376, then compress every block to eight bits per pixel. That is about 547.84 kiB, or a couple of quarter of the scale as uncompressed. You’ll be able to play with the choices within the format and compression drop-downs to search out the precise trade-off between reminiscence measurement and visible high quality on your wants.

Rising the rendered measurement of this texture by displaying it on a scaled-up sprite doesn’t enhance the quantity of RAM it takes to retailer. So lowering decision is a good way to avoid wasting on texture reminiscence – SDF textures make nice use of this, by serving to you get crisp strains even on scaled-up textures, if you need a flat-colour/gradient vector artwork look.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments