Post tutorial Report RSS Reducing mobile app download size (part 3)

Working with mipmaps, image sizes and shaders to reduce file size.

Posted by on - Basic Other

MipMaps and image sizes

MipMaps are automatically created tilesets, which are used to optimise game performance while playing. The way they are made is by taking the imported texture (for example 2048×2048 pixels) and creating additional, smaller textures, each a quarter the size of the last: So 1024×1024, 512×512, …. 16×16. They are then used when drawing things, which are far away. For example, if you are playing a first person shooter and are looking down the street at a distant door, if the door only takes up 100 pixels on your screen, there is no point in sampling the whole 2048×2048 texture. Instead, an appropriately sized mipmap texture will be used, for example the 32×32 pixel one. As you get closer to the door and it takes up ever more pixels on your screen, different mipmap icons will start to be used. Long story short, there is no reason to use this in a game like Ore Miner.

In Unity’s image import settings, we disabled mipmaps. This however wasn’t enough. Removing mipmaps reduces the file’s size by, at most, 50%. Among the settings, there is also a maximum size setting. Imported files which are larger than that will be shrunk down to the selected size. Most of our icons were of various sizes: from 128×128 to 2048×2048. We went through the files and selected appropriate file sizes, based on how big the icons were in the game. Most of the tiny indicator icons are 128×128, items are 256×256, stones are 512×512 and the spinning background indicators are 1024×1024. We’ll probably tweak this though.

Replacing images with shaders

I’m not an expert in shaders, however when I see that a simple gradient background is taking up 2.5 MB in a mobile game, I have to think there’s a better way. Making a gradient shader is very easy, so I found one on the Internet, realised it didn’t do what I wanted and wrote it myself. Suddenly, the background file was no longer needed and I saved the 2.5 MB it took up previously. Plus I could do cool things with it!

Processing shaders is however a task which requires the phone’s GPU and there is only so much power we can expect to get from that. Processing a shader as simple as this shouldn’t be a problem though.

For the other shader related optimization, I didn’t even need t write my own! Instead I just used Unity’s default sprite renderer. The issue we were having was with stones. There are currently 11 different colours of stone. Each hand-made by our artists, Kaja Lipušček. As you hit the stone, particles fall off in the stone’s colour. As the stone decays, the stone’s sprite is replaced with more damaged versions. All in all there are 10 damage states for stones and 9 different particles – for each of the 11 stone types. Because the stone is quite large on the screen, the stone destruction sizes need to be quite big. In the end, what this meant was that the stones took up about half the total app size used for graphics. More-so, the only difference between the images for different stone types is the stone’s colour.

Unity’s shaders unfortunately don’t come with a colourisation option, they can only add colour to images. Of course I could have written my own shader, but why do that when a decent solution already exists. I took the icon for cobblestone, opened it in Photoshop and made it white. I then selected the outline, made that its own image and also coloured it white. By splitting these into separate images and making them white, I could then select any arbitrary colour combination and create stones of any colour.

I’m a programmer and don’t have the eye needed to affirmatively say something looks good enough. So to test whether this new approach with stones looked good enough, I created a scene with all 11 stones, side by side. Old version on the left, new (shader powered) version on the right. Then I called over the original game designer, Domen Koneski and asked which version is current. When he chose the new ones, I knew they were good enough. It may be a sample size of one, but it’s the sample which mattered.

With the ability to arbitrarily change the colour of the background and stones, I reduced the APK file size by about 4MB – which was less than expected. Most of it came from removing the background. We can now change how the game looks quite a bit though and make things like this:



Matevž Baloh, programmer

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: