Unity common optimization

To develop a game, even if you don't do extreme optimization, you must at least do regular optimization. In this way, your product will perform well in the market. The following introduces a common art resource optimization scheme

(I use Unity 2021.3.6LTS version here)

First of all, we need to understand that GPU rendering of power-of-2 size is the fastest.

For example: 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, pictures of these sizes are all powers of 2, as long as your resource pictures are of this size. It is best to optimize the picture of this size.

Therefore, all the resources we develop the game should preferably be quadratic textures, which can be used in 2D/3D games.

After making sure your image size is a quadratic texture, you need to set the texture like this in UnityEngine

Before setting:

 

After setting:

According to this setting, we found that this Normal texture has been reduced from 128KB to 48.6KB, and the quality of the picture looks good. But in fact there is damage, but as long as it looks OK.

Check Use Crunch Compression, and the Compressor Quality below can be adjusted according to the actual effect. Generally, 50 is very good, and the lower the value, the more compression. As long as the visual effect is OK. And some art resources can be re-cropped into quadratic textures in Photoshop even if they are not quadratic.

As shown in the picture:

 Compare the compression of the two sizes in Unity:

You can see that the non-quadratic texture cannot be compressed and is 45.1KB, while the quadratic texture is compressed to 3.4KB. It is compressed by nearly 90%. This compression ratio can be exchanged for more resource space, and CPU batch processing becomes easier. By the way, in many 3D software (Maya, Blender, Max, C4D, etc.), it is also recommended to use the power of 2 texture for animation rendering, and the calculation will be much faster.

Use of Sprite Atlas:

If you have multiple images, none of which are power-of-two textures, you can also create a Sprite Atlas to wrap them. Sprite Atlas is a bit different from general self-made atlases. It automatically merges atlases when the game is packaged or run in the engine. When editing, I still use scattered resources. 

 

Sprite Atlas can also check Use Crunch Compression to optimize the image. You will find that after the resource is compressed, a 2-dimensional atlas is generated, and the volume is also reduced.

The advantage of this is that the bulk textures that are not originally a power of 2 are also compressed, and the entire game package becomes smaller. The Batches Draw Call is also reduced a lot when running.

But it should be noted that it is better for Unity’s parent and child objects to share resources in the same atlas. If the parent and child objects use 2 atlases and one of the atlases has been used by other objects, the pressure will increase instead. The shared atlas will be rendered again, which adds unnecessary rendering.

Guess you like

Origin blog.csdn.net/chenzyart/article/details/127592682