If the game's rendering bottleneck comes from the GPU
The first task is to identify the factors that are causing the GPU bottlenecks, and often GPU performance is affected by pixel resolution, especially in mobile client games, but the effects of memory bandwidth and vertex computing need to be noted. The impact of these factors requires real-time testing and positioning.
Pixel resolution
Pixel resolution refers to the number of pixels that the GPU can render per second, and if the game is affected by pixel resolution, it means that the number of pixels depicted in the game is more than the limit the GPU can handle.
The effect of detecting whether a game receives pixel resolution can be done in the following ways:
. Analyze the game and watch the GPU run time;
. Set the reduced resolution in Unity's player settings
. At this point the analysis game is running, and if the performance of the game is improved, it is possible that the pixel resolution is causing performance problems.
Here are some ways to solve the problem caused by pixel resolution:
. The slice shader in shader is primarily used to tell the GPU how to draw pixels for each slice, so if the slice shader is not performing efficiently, it can degrade the performance of the game. Complex element shader code is often the cause of resolution problems.
-If we use the built-in shader, it is best to use the simplest and most optimized shader for visual effects. For example, the mobile shaders-ship with unity is a highly optimized shader, and we can use them to test whether the performance of the game has an impact without compromising the performance of the game. These shaders are designed for mobile platforms, but can also be used on other platforms. Especially without affecting the performance of the game, the use of these shader has a great advantage.
-If the objects in the game use standard Shader, then you need to know that in Unity, the compilation of these Shader depends on the current material settings. Only the attributes that are currently being used will be compiled. You can greatly improve the performance of the chip shader by removing features such as map details. In addition, if you perform such an operation test in the game, you need to test whether the action will affect the overall performance of the game.
-If the game uses custom shader, we need to optimize this type of shader as much as possible. The optimization of shader is extremely complex, and some optimization suggestions are given in the Shader optimization section here and here.
. Overdraw refers to the same pixels being rendered more than once, and if some objects on top of other objects, the pixel problem is caused by multiple rendering. To understand overdraw, you need to understand the rendering order settings in unity. The order in which each object is rendered is determined by the shader on it, especially the render queue in shader. Unity relies heavily on the settings of the render order, as described here. In addition, objects in different render queues will be sorted differently before the object is rendered. For example, in unity, if the render queue is set to geometry, the sort is rendered from front to back. If the render queue is set to transparent, its rendering is sorted from back to front, and the rendering order from the back to the front causes the rendering to be greatly exaggerated. Overdraw is a complex problem, there is no proper way to solve this problem, but it is a good way to reduce the number of overlapping objects that unity cannot automatically sort. Solving this kind of problem is best in Unity's scene view, where you can set the scene view in draw mode to find out how to reduce this type of object. Often the cause of overdraw is a transparent material, a very special effect, and a multi-layered UI, so optimization needs to be tested for optimization. This article on the unity learn site mainly explains UI optimizations, but there are some suggestions for reducing overdraw.
The image effects in the game can cause a lot of pixel problems, especially with multiple image effects. If the game is affected by pixels while using image effects, it is best to optimize the image effects, such as using the optimized explosion effect to replace the pre-optimization explosion effects. In particular, there are multiple image effects on the same camera, which can result in multiple shader passes, in which case it is better to combine multiple image effects in a shader pass. If this does not solve the problem, it is best to consider whether to not enable image effects, especially on low-end machines.
Storage bandwidth
Storage Bandwidth refers to the rate at which the GPU reads and writes on its specific memory, and if the game is limited by the storage bandwidth, it means that the game handles large maps quickly on the operating GPU. You can determine whether storage bandwidth is an issue in the following ways:
. Run the game and analyze the GPU time;
. Reduce the mapping quality of the current platform and target objects in Unity's quality settings;
. Run the game again to detect whether the game performance has improved, and if so, it may be that memory bandwidth is causing the game performance problem.
If the game's memory bandwidth is causing game performance problems, you need to reduce the memory footprint of the map to improve the performance of your game. Of course different game solutions are different, but there are some common methods that can be used:
. Map compression map compression can greatly reduce the footprint of maps on disk and in memory. If the game's memory is our limiting factor, compressing the map can improve the performance of the game. There are different formats in the compression of the map, with specific settings for each format. So you need constant testing and experimentation to find the right format for the game, and here are some introductions to how to format the map in unity.
. Multi-level mapping (Mipmaps) is a technique in unity for farther objects, and if the scene contains more distant objects, we can use Mipmaps technology to solve the storage bandwidth problem. Here's how to view the use of multilevel maps in a scene, here's a more detailed description of the mipmaps of the map.
Vertex calculation
Vertex calculations are the computations that the GPU must perform on the vertices on each mesh, which are primarily affected by two factors: the number of vertices that need to be computed, and the actions that are required for each vertex.
If the performance problem of the GPU does not come from memory bandwidth or pixel resolution, then it is possible that vertex calculations will result in a reduction in the number of vertices that need to be rendered to improve game performance.
There are several ways to reduce the number of vertices and the operations of vertices to provide:
. The first thing you need to do is remove the unnecessarily complex mesh and don't need too much detail grids for objects that are not in the view. A complex mesh with more vertices can also be simplified to avoid GPU waste. The best solution is to create a model with a lower number of polygons instead of high modulus.
. We can use the normal mapping method to make the map have a more complex geometry, although this will cause a certain degree of GPU complexity, but this for the performance of the game to improve a great help. Here are some descriptions of the normal maps.
If the model grid in the game does not use a normal map, you can reduce the number of vertices by rejecting the tangent vertices when you import the settings.
. LOD (level of detail) technology can be used to reduce the complexity of farther meshes by reducing the number of vertices that need to be rendered without compromising the performance of the game. LOD Group has a detailed introduction to LOD technology.
. Vertex shaders in shader are primarily used to handle vertex calculations, and reducing the complexity of vertex calculations can improve game performance if the game is constrained by vertex computing.
-If we use the built-in shader, it is best to use the most optimized shader for the game's effect settings. See resolution settings above.
-If the game uses a specially crafted shader, it is best to optimize it, see resolution settings above.
Summarize
Through the full text, we learn the principle of rendering in unity, how to solve and locate the problem of rendering, provide some solutions and approaches. By using the analysis tool, we can locate the problem that causes the game performance, through the optimization can let the game run more smoothly.
I will continue to translate some of the optimization methods in unity, such as the memory management mechanism problem.
Unity rendering Optimization Chinese Translation (iii) optimization strategy of--GPU