Performance optimization resource optimization

Resource optimization

We all know that when making game applications, performance optimization is always a common issue. Perhaps we may consider positioning from the perspective of CPU (complex calculations, physical simulations), GPU (excessive vertex calculations, etc.), but the actual optimization must be determined based on the specific conditions of the project, and during the optimization process, we need to understand Make good use of tools, such as Unity Profiler, UWA, URP and other related performance tools. In addition, we have to stay away from those strange ideas. We feel that performance optimization should be the last link in game applications, so it will make us feel particularly painful and powerless when optimizing actual projects. For example, the optimization involves the modification of art resources, and Once the art resources need to be modified, it is equivalent to facing the cost of redoing the resources. Therefore, project optimization should start from the project requirements design, asset production process, architecture design and other links, and verify the core gameplay performance as early as possible in order to achieve a Excellent product for applications.

Performance critical detection process.

Insert image description here

A brief analysis of art rule constraints based on Unity3D

1. Model level

1. Model proportions must be strictly followed between models and model scenes. The proportions between model scenes must be correctly unified (units and proportions), and the model coordinates must be unified as the origin.
2. The face reduction operation is mainly to remove the faces that have no impact on the shape of the model, and use as few faces as possible to express the structure and shape of the model clearly. For example: non-joint points of objects and the back and interior surfaces of objects that cannot be seen are deleted.
3. Reduce the number of model vertices . The number of model vertices will affect the performance of the GPU. All objects should not exceed 20,000 triangular faces. The number of faces of the human model should be controlled to 3000-4000. The number of single human bones on the mobile terminal should be controlled to 30~ About 50.
4. Merge models , merge small non-interactive static objects within the same small range, and merge the textures of small objects at the same time. This can reduce the number of Draw Calls. For example, a group of grasses of different sizes, a group of stones of different sizes and shapes, a bookshelf and many books placed on it, etc. Combine these small objects into one Object, and the textures into one texture.
5. Reuse of models . Multiple identical objects are copied and used in Unity. The copied objects are counted as one object in engine calculations. But don’t copy too many copies, as too many copies will put a lot of pressure on the memory. There are too many identical objects. It is recommended to merge several into a group as one Object, make several more groups, and then copy them.
6. Reduce the number of UV seams and hard edges of the model .
7. Reduce the number of Materials . In fact, a model requires at least one texture. If possible, multiple textures can be combined into one texture, so that multiple models can share the same Material.
8,Minimize the use of pixel lights, shadows, and reflections as much as possible . These functions will cause the model to be rendered multiple times and increase the burden on the CPU.
9. Terrain optimization . If the terrain is made with Unity’s own terrain tool, you can use the T4M plug-in to convert it into T4M format terrain. After setting a vertex value for conversion, the terrain can be optimized a lot. T4M can also set Lod models.
10. There are too many vertices in the FBX resource. Please check whether it is necessary. Custom Parameters: VertexCountLimit: 500 (the number of vertices is generally limited to 500). Try to reduce the number of vertices as much as possible while satisfying the artistic effect.
11. Check the file Mesh read/write flag , which is turned off by default. Insert image description here
12. Resources are based on domestic standards (refer to UWA): it is recommended that the total number of panels for low-end, mid-range, and high-end equipment be controlled at 30w, 40w, and 50w. Unity Mobile Game Performance White Paper

2. Texture level

1. Texture size . The maximum size of textures on mobile devices should be controlled at 1024 and 512. Textures of 2048 size can be used sparingly, mainly 1024 and 512 size textures, and other non-main images such as normals. , shading, and self-illumination images can be set smaller.
2. The use of repeated textures . Use 1-3 textures to cover a large area of ​​the same material alternately and repeatedly, breaking the repetitive feeling of textures through changes in light and shadow.
3. The texture uses Bitmap texture type, and the size is mainly 2 to the Nth power . Check the Inspector -> Advanced -> Non-Power of 2 option. It is recommended to use a map with an original size that is a power of 2. Texture resources whose size is not a power of 2 will not be able to use the ETC1 and PVRTC compression formats. Automatically scaling to a power of 2 when importing may also cause memory usage or texture quality issues.
4. Use less transparent textures . If you can’t use them, don’t use them. Transparent maps consume a lot of GPU resources. And the textures with Alpha channel are stored in tga or png format, and _al must be added when naming to distinguish them.
5. Texture compression. Compressing textures in PVRT (iOS) or ETC (Android) format can reduce a large amount of memory consumption . It is recommended that the scene materials can be converted into .sbsar format materials using the Substance material system. Substance materials can greatly compress the size of texture data without losing texture quality.
6. Check the Mipmap flag and check the Inspector -> Advanced -> Generate Mip Maps option. Enabling the Mipmap flag for uncompressed texture resources will increase memory usage.
Application restriction: Uncompressed texture resources should have mipmap disabled. Texture resources of type Sprite should have mipmap disabled. Mipmap will increase the size of the game package and occupy a certain amount of memory, but the rendering of Mipmap in the game can reduce the memory bandwidth and reduce the rendering pressure. As the camera moves farther away, the texture will switch to a low-pixel texture, thus saving money. Resource expenditures. Excessive use of mipmaps will put a lot of pressure on memory, so it is recommended to only set mipmaps for large objects. Insert image description here
7. Check the texture read/write flag and check the Inspector -> Advanced -> Read/Write Enabled option. It must be turned off by default. Turning on the read/write flag of the texture resource will cause double the memory usage. Insert image description here8. Check the filter mode of the texture resource and check the Inspector -> Filter Mode option. It is generally not recommended to use Trilinear as the filter mode of the texture, which will occupy higher computing resources.
Insert image description here

3. Animation level

1. View the animation resource compression method in Inspector -> Animation Tab -> Anim. Compression option. Using the best compression method for animation resources can improve loading efficiency. off : Indicates no compression processing. keyframe Reduction : Use keyframes for processing (old version unity: keyframe, reduction and compression means keyframe reduction and compression). Optimal : (new version of unity) automatically selects an optimal compression method. Insert image description here
2. Check the Optimize Game Objects option of the animation resource and view the Inspector -> Rig Tab -> Optimize Game Objects option. The animation resource should check the Optimize Game Objects option to reduce CPU consumption.
Insert image description here

3. Animation frame rate and frame number control, generally 10 frames per second, and an animation is completed within 1 second.
4. The naming of animation models is unified to the basic model name ➕@➕ (animation prefix anim_) animation name, which is unified and standardized. At the same time, the animation will be automatically named as the name after @. All names must be in English or Pinyin, and must be in lowercase letters. No Chinese characters may appear. For example, robot standby animation (export FBX files with animated skeletons to provide technology), C_RobotQ@anim_daiji. In this way, Unity can automatically standardize the name of the anim clip.Insert image description here

4. Sound level: (General audio settings)

Force To Mono : This option is used to force mono. In order to pursue quality, many sounds will be set to dual channels, causing the sounds to take up twice as much space in the package and memory. However, more than 95% of the sounds have two channels. It's exactly the same data. Therefore, it is recommended to check this option for projects that are not very sensitive to sound to reduce memory usage.
Compression Format : Different platforms have different support for different sound formats. IOS has hardware support for MP3, and Android has no hardware support for the time being. It is recommended that IOS is suitable for using ADPCM and MP3 format, and Android is suitable for using Vorbis format.
Load Type : Check Inspector -> (Platform Tab) -> Load Type option, audio loading type, determines the existence form of sound in memory: Decompress
On Load : When Audio Clip is loaded, decompress the sound data, suitable for small audio files (< 200kb)
Compressed In Memory : The sound data will be stored in the memory in a compressed form, suitable for medium-sized audio files (>= 200kb)
Streaming : Read the sound data from the disk, suitable for large audio files, such as background sounds. Note: For example, Decompress On Load requires that the file must be less than 200kb. Due to internal memory management issues, if the file is greater than 200kb, it will still only be allocated memory of less than 200kb.
Bitrate : You can compress the audio file itself and reduce the bitrate of the file, provided that the audio quality will not be too seriously damaged.
Insert image description here

5. UI level:

1. The UI can be hidden by moving it outside the Canvas instead of the SetActive(false) method.
2. UI batch processing . If UI elements change values ​​or positions, it will affect batch processing and cause more drawcalls to be sent to the GPU. Therefore, it is recommended to put UIs with different update frequencies on different Canvas. The Z value of UI elements in the same Canvas must be the same so as not to interrupt batch processing. UI elements in the same Canvas must use the same material and texture. Materials or shaders can have dynamic transformations (such as some special effects), which will not affect batch processing. UI elements in the same Canvas must use the same clipping matrix.
3. Graphic Raycaster This component is used to process input events and is mounted on each Canvas by default. Sometimes the non-interactive object is still part of the canvas and comes with the component, so every time the mouse or touch is clicked, the system has to traverse all UI elements that may accept input events, which will cause multiple "clicks" falls within the rectangle" check to determine whether the object should react. When the UI is very complex, this computational cost will be very high. Therefore, it is recommended to ensure that only interactive Canvas has this component to save CPU running time.
4. Processing of full-screen UI . There may be some full-screen UI in the game (such as some settings interfaces), which will block scene objects or other UI elements. However, even if they are blocked and invisible, the CPU and GPU will still be consumed. Therefore, it is recommended that if the 3D scene is completely blocked, turn off the camera that renders the 3D scene. For the obscured UI, Disable these Canvas. Note not SetActive(false). Reduce the frame rate as much as possible, because these UIs generally do not need to be refreshed frequently.

Off topic: It is true that in optimization, the proportion of art is very important, so let’s understand the art production process theoretically.

Next Generation : Compared with traditional games, Next Generation games integrate next-generation game development technology into modern games, improve the graphics of the game by increasing the number of faces of the model and the amount of texture data, and using the next-generation game engine. Effect. The standard performance is: the model reaches high precision (high modulus), the use of PBR process (real normal + highlight map) to express texture under real lighting, which is a new game engine technology.
PBR (Physically Based Rendering): PBR is a kind of physically based rendering. By approximating, simulating, and reproducing real-world physical phenomena, 3D objects can show realistic rendering textures in different environments, and through the parameterization of materials Transform the handicraft process of material production into a standardized and streamlined industrial process. Insert image description here
Please add image description
Excellent resource link sharing:
1. Unity official Profiler: https://docs.unity3d.com/Manual/ProfilerMemory.html
Unity URP: https://upr.unity.cn
2. UWA related:
2.1 Use UWA GOT to optimize Unity Performance and memory: https://blog.uwa4d.com/archives/2029.html
2.2 Introduction to trial products: https://blog.uwa4d.com/archives/UWA_PipelineV2-4.html
2.3 Introduction to pipeline products: https ://blog.uwa4d.com/archives/UWA_Pipeline42.html
2.4 Introduction to local resource detection: https://blog.uwa4d.com/archives/UWAGOTOL_Summary.html
2.5 GOT Online related introduction: https://www.uwa4d.com/demo/projects.html
3. Unity resource related:
3.1 Unity optimization practical learning (2) Resource optimization: https://blog.csdn.net/dengshunhao/ article/details/82663719
3.2 Unity scene art resource optimization: https://blog.csdn.net/weixin_34203832/article/details/92379182
3.3 Unity overall performance optimization section (2) - Unity resource optimization: https://blog .csdn.net/chongzi_daima/article/details/101381290
4. Unity rendering technology: http://imgtec.eetrend.com/blog/2020/100050575.html
5. How to use Unity and Arm analysis tools to solve mobile game performance problems (Part 1): https://mp.weixin.qq.com/s/968NoWRjcV2rNYH51Mbfqg
6. The new Arm Mobile Studio for Unity software package enhances mobile terminal performance analysis: https://developer.unity.cn/projects/60e2a5f9edbc2a04cfc5e341
7. Compilation of Unity performance optimization experience: https://segmentfault.com/a/1190000019844821?utm_source=tag-newest
8. LuaProfiler: https://github.com/leinlin/Miku-LuaProfiler
9. Memory Profiler: https://docs.unity3d.com/Packages/[email protected]/manual/index.html
https:/ /www.bilibili.com/video/av334941622
10. Garbage collection: https://docs.microsoft.com/zh-cn/dotnet/standard/garbage-collection/fundamentals
11. Lua reference: https://github.com /jxhgzs/LuaMemorySnapshotDump
12. [Unity Project Optimization] Summary of project resource optimization based on UPR resource detection report: https://blog.csdn.net/qq_42437783/article/details/124275092

Guess you like

Origin blog.csdn.net/qq_42194657/article/details/132563890