Objective

The main objective of this blog post is to give you an idea about Optimizing Graphics in Unity Games

 

This blog post is part of our ongoing Latest Optimization Initiative for Unity Games.

If you would like to learn how to optimize your games, you can check out this blog post:

Why is my game build size so high?

Why does my mobile feel like a scorching volcano?

Why is my game loading time so high?

Even if my game graphics are basic then why is it lagging so much?

How can I reduce my game size?

Oh yes, these are just a few common questions we come across when we are just about to cross the finish line (THE LAUNCH TIME).

Imagine a case where you launched your game just at the time when your biggest competitor decided to take you on! (Damn! He has a big grudge against you)

Here your game size was 50mb and his game was 20mb.

After a week, you found that your competitor’s game is thriving in the market with 100s of thousands of downloads, and here you are with a few hundred! (Even though you think you had better gameplay and better features)

Yes trust me on this one; mobile market is crazy and very competitive. You may be pushed down in no time if you don’t control your game size! None of your customers like waiting and spending on data charge! (In this case, I would rather wish RIP to your game)

Wait, no need to get your hopes down yet. RIP does not always mean REST IN PEACE in sometimes means RETURN IF POSSIBLE

So let’s discuss the comeback plan!

I AGREE, BUT HOW CAN I REDUCE MY GAME BUILD SIZE?

  • Well, there are many things that we can focus on, but first, let’s see what eats up most of the size. To check this, first we need to open Editor Log.

If you do not know how to open the editor log visit the following link:

As stated in the Unity’s official documentation,

  • "The log provides a summary of assets broken down by type and then lists all the individual assets in order of size contribution. Typically, things like textures, music and videos will take up the most storage while scripts, levels, and shaders are often negligible."

Which is clearly visible from the below picture:

Details

This data is actually picked up from one of our developed 2D game. As shown above, Textures/Graphics take up most of the size in a game!

Hence, Graphics Compression should be on the top of your checklist.

OK, IT WAS OBVIOUS, BUT WHAT SHOULD I DO ABOUT IT?

  • Luckily for us, there is a concept known as Texture Compression

So, what is Texture Compression?

The definition As it is stated in Wiki,

  • "Texture compression is a specialized form of image compression designed for storing texture maps in 3D computer graphics rendering systems. Unlike conventional image compression algorithms, texture compression algorithms are optimized for random access."

Went over your head? Don’t worry; the same thing happened with me too ;)

The not so difficult definition:

  • Popular compressed formats like PNG and JPG (that we normally use in our games) cannot be decoded directly by the GPU. Hence, first, they need to be decompressed before copying them to the GPU memory. Decompressing the textures takes time and leads to increased loading times.
  • A better option is to use hardware accelerated formats. These formats are lossy but have the advantage of being designed for the GPU.
  • This means that they do not need to be decompressed before being copied and results in decreased loading times for the player and may even lead to increased performance due to hardware optimizations.
  • There are many types of compressions like ETC1, ASTC, DXT1, DXT5, PVRTC, ATC and many more. This process of converting common compressed formats to hardware accelerated formats is known as Texture compression. Easy to understand now right? :D
  • I found a very nice link (given below) that might help you understand Texture Compression and its importance in detail. Do check that out

Basically, these hardware accelerated formats help improve performance, battery life and reduce heating of the device, requiring less bandwidth while also consuming less energy.

So it’s clearly very important for you and me! I hope your competitor is prepared for the blow ;)

OHH, TEXTURE COMPRESSION IS THE ANSWER,
BUT WHAT KIND OF COMPRESSION SHOULD I USE?

  • Well, that depends on which devices you are targeting. Not all hardware compressed formats are supported by all devices.
  • Let us first see the table that shows which formats are supported by different devices.

There are two categories of hardware accelerated formats, they are standard and proprietary.

Following are the standard formats:

ETC1 Supported on all Android devices with OpenGL ES 2.0 and above. Does not support alpha channel.
ETC2 Requires OpenGL ES 3.0 and above.
ASTC Higher quality than ETC1 and ETC2. Supported with the Android Extension Pack.

Following are the proprietary formats:

ATC Available with Adreno GPU.
PVRTC Available with a PowerVR GPU.
DXT1 S3 DXT1 texture compression. Supported on devices running Nvidia Tegra platform.
S3TC S3 texture compression, nonspecific to DXT variant. Supported on devices running Nvidia Tegra platform.

Let’s first take an example to understand compressions better and how it’s actually performed; I’ll focus on UI as always

My UI looks something like the image below:

start-playing

I’ll just focus on the background image, On selecting background image I will be able to see something like the image below (on the inspector).

This size is by default (without compression set as true color):

Background

Here the size is showing 8.0mb.

Inspector shows settings as the picture below:

Inspector

Now set Texture Type as Advanced. Deselect the Generate Mip Maps Check box. Select Override for Android check box (this will allow custom compression) and select format as RGBA Compressed DXT5

Now again have a look at the image below:

Compressed Background

The Image size went down from 8.0mb to 2.0mb.

That’s good, right? Now let’s try ETC Compression

Select format as RGB Compressed ETC 4 bits:

Compressed Background 1mb

Again went down to 1.0mb wow!

Notes

  1. Size compression does not only depend on the format but also on the type of image.
  2. Lower size does not necessarily mean optimization (I will shade some light on this later in the post)
  3. If you are using mipmaps, then the storage will be about a third larger than the single image. (I recommend not using mipmaps for UI related images)
  4. Most compression formats require file resolution as Power of 2 (just like the one I used in the example I.e. 2048 x 1024) for efficient compression

If you are focused on reducing build size you can also refer the following link:

The formula for the total image storage size is width * height * bpp where bpp refers to bytes per pixel

So you can select compression format depending on the device that you are targeting in this way.

Who the hell targets a specific device?
I want my game supported on all devices!!!

  • And it’s obvious, why would we leave even 1% of the market out? Right?
  • Fortunately, we do not have to worry much about iOS devices as PVRTC is the compressed texture format used in all generations of the iPhone, iPod Touch, and iPad.
  • Hence, just compress to PVRTC format and it’s done!

But what about Android devices?

There are different GPUs on different Android devices.

There is one issue with Unity as stated in its documentation,

  • "Although Unity Android does support DXT/PVRTC/ATC textures, Unity will decompress the textures into RGB(A) format at runtime if those compression methods are not supported by the particular device in use. This could have an impact on the GPU rendering speed"

Now for example, if you compress to DXT5 format and run on a non-supporting device, the textures will be uncompressed to RGBA 32 and stored in memory along with the compressed ones.

So in this case, you lose time decompressing textures and lose memory storing them twice. It will surely have a very negative impact on rendering performance.

So, the solution would be to use ETC1 format instead (which is standard format) and is supported by all GPUs. A Piece of cake isn’t?

But wait! All’s not good as ETC1 does not support alpha channel! That’s bad as most games have textures or 2D sprites with alpha in it, what to do now?

  • According to Unity guys we have two options:

    1) It is possible to create separate Android distribution archives (.apk) for each of the DXT/PVRTC/ATC formats and let the Android Market’s filtering system select the correct archives for different devices.

    Or

    2) Convert to RGBA 16-bit which will sometimes be the best trade-off between size, quality and rendering speed where alpha is required. With a combination of ETC1 where alpha is not required.

Personally, I prefer the second option, but as I said before IT DEPENDS.

CONQUER THE MARKET!!!

"Yes, you can now! I hope that it’s clear now that the graphics have the power to tranquilize your game. Graphics Optimization is the must, and there is no way out."

"The Tradeoff between quality and size is here to stay (for now), and it’s upon you that how smartly can you optimize graphics."

"Smartness only comes with knowledge, and I hope I did shed some light on the topic. That’s it for now, and do not forget to send your opponent a bouquet of white flowers ;)"

"If you have any better idea on the topic feel free to share with us, Drop off a comment below if you have any queries, I will get back to you at the earliest. Don’t forget to stay connected, more blog posts are on the way :D"

This blog post is part of our ongoing Latest Optimization Initiative for Unity Games.

If you would like to learn how to optimize your games, you can check out this blog post:

Got an Idea of Game Development? What are you still waiting for? Contact us now and see the Idea live soon. Our company has been named as one of the best Unity 3D Game Development Company in India.

Talented Game Developer as well as a player with a mania for video games and the game industry. Always Ready to take up challenging Projects. Proud to be making with the TheAppGuruz Team

face mask Belial The Demon Headgear Pocket Staff Magic