5.2-Triangle and polygon usage
原文档：Arm® Guide开发人员指南 V4.1 – 移动平台游戏图形优化
To optimize the performance of your game, always track the number of triangles that are on-screen.
It is vital that you use the minimum number of triangles to get the correct balance between the intended quality with your 3D objects, or models, and deliver a consistent performance.
We recommend that you try the following tips:
• Using fewer triangles results in increased performance.
— It is essential to keep the triangle count in mind when creating content for a mobile platform.
— Fewer triangles means that the GPU must process fewer vertices.
— Processing vertices is computationally expensive. Therefore, the fewer the number of vertices that get processed, the better it is for overall performance.
• Using fewer triangles enables the release of the game on more devices. Not just the latest devices that have the most powerful GPUs.
The following image shows a comparison between two 3D objects. One using 584 triangles, versus one using 704 triangles. Both objects look the same in shaded mode. So remove any edges that do not contribute to the silhouette:
On mobile devices, the maximum number of vertices that each 3D object, or mesh, can use is 65,535.
Therefore, you must stay below this number. Some older GPUs, including Android devices using the Mali-400, do not support more. These devices do not render 3D objects with more vertices.
It is essential to view or test the game on the target device, or as many target devices as possible. Testing your game on just a computer screen does not give you the information you need for optimization.
Keep in mind that mobile device screens are smaller than the average computer monitor. Therefore, any details that are created using lots of triangles may not even be visible on a mobile device.
Use more triangles on 3D objects that are in the foreground, so closer to the camera, and less on 3D objects that are further away in the background. A game that is using a static camera Point-of-View (POV) benefits more from this technique.
The following image shows an example of where 3D models are used in the foreground, but lower quality 3D models are baked into the 2D background
While there are no fixed numbers for the maximum triangle count that a 3D object can use, the more 3D objects that are on-screen at the same time, the fewer triangles you can use per-object. However, if you are displaying fewer 3D objects on-screen, then you can use more triangles.
The target device also matters. Newer phones, such as the latest Samsung Galaxy S series, are able to handle more complex geometry that older mobile devices.
The following example shows characters from two demos. The Circuit VR demo only has one robot character, so a model with a higher polygon count can be used. While the Armies demo has hundreds of soldiers in one frame, so it needs a tiny polygon count.
In the Armies demo, which is a 64-bit mobile device tech demo that was built in Unity, the camera is static with lots of animated characters. Each frame renders around 210,000 triangles in total, and this triangle count enables the demo to run smoothly at approximately 30 Frames Per Second (FPS)
The number of triangles to use depends on both the type of game being created, and the specifications of the target devices The following example shows the total number of triangles that were used in our tech demo:
The largest objects in the scene, the cannon towers, are approximately 3000 triangles each as they occupy a large portion of the screen.
Characters only use around 360 triangles. This is because there are so many of them and they are only seen from a distance. So, from the camera point-of-view, the characters look fine on-screen.
This section contains the following subsections:
• 5.2.1 Distribute triangles in areas that matter on page 5-66.
• 5.2.2 Why micro triangles are bad on page 5-67.
• 5.2.3 Why long and thin triangles are bad on page 5-69
5.2.1-Distribute triangles in areas that matter（ 在重要的区域分布三角形 ）
Both polygons and vertices are computationally expensive on mobile platforms. By placing them in areas that really contribute to the visual quality of the game, we are not wasting the processing budget.
Due to the small screen size on most devices, and where these 3D objects are in the game level, many small triangle details on a 3D object are not visible in-game. Instead, focus on large shapes and parts that contribute to the silhouette of the object instead of detail.
Use fewer triangles on the areas that are not often shown on-screen. An example of this would be the bottom of a car, or the back of a wardrobe.
Avoid using high-density triangle meshes for modeling small details. Instead, use textures and normal maps for fine detail.
The following images show the same mesh with and without normal map:
Consider deleting the back, or bottom, part of an object that is never seen from the camera POV.
However, this needs to be done carefully as it might limit the re-usability of the scene. For example, you delete the bottom part of a table mesh, as you think that it is never seen by the end user. Doing this would mean that you could no longer place that model upside down or reuse it for something different.
5.2.2-Why micro triangles are bad 为什么小三角形不好
Micro triangles are tiny triangles that do not contribute much to the final look of an object or scene.When a 3D object with a large polygon count is moved further away from the camera, a micro triangles problem occurs. A micro triangle is often referred to as triangles that are between one and ten pixels in size on a device.
Micro triangles are bad because the GPU must process all of these triangles. But, they do not contribute much to the final image as they are too small to see. Remember, vertices are computationally expensive
to process, and lots of tiny triangles on-screen at the same time means more vertices to process.
The following two approaches cause micro triangles:
• Details that are too small and consist of many triangles.
• Objects with many triangles that are further from the camera.
The following image shows the number of triangles that are used when a 3D object is both near the camera, and further away. The left image uses fewer triangles, and the example on the right uses a normal map instead to display the same amount of visible detail:
For the following image, most of the triangles in the highlighted area are too small to be visible on a mobile device. Therefore, they are not contributing much to the final look:
How to minimize this problem
Here are a few steps that you can take to mitigate this issue:
• For an object that changes its distance from the camera, use Level of Detail (LOD). Using the correct LOD simplifies an object when it is further away, with the object using fewer triangles.
• Use fewer triangles on background objects.
Avoid using polygons to create the finer details in a mode. Instead, use a combination of textures and a normal map instead.
• Merge any vertices or triangles that are either too small to see on-screen, or are not adding much value to the final image.
• Try to keep triangles above 10 pixels in area.
Why minimizing the use of micro triangles is important There are several reasons as to why minimizing the use of micro triangles. These are:
• The GPU must process all of the triangles, and vertices. Even when they are not adding any value to the final scene on-screen.
• Memory bandwidth is negatively affected as more data must be sent to the GPU for processing.
• The amount of processing that is required directly impacts the battery life of a mobile device.
Therefore, the less data that the GPU must process, the longer the battery lasts.
5.2.3-Why long and thin triangles are bad（为什么细长的三角形不好）
Long, thin triangles are vertices that, when rendered in the final image, are smaller than ten pixels and span along the screen. Long, thin triangles are bad because they are more expensive to process on the GPU, when compared with normal triangles.
The following screenshot shows an example of a long, thin triangle in use. The screenshot highlights the bevel on the pillar when it is viewed from a distance. However, the bevels are not a problem when seen close-up:
How to minimize this problem
Here are a few steps that you can take to mitigate this issue:
• Remove any long, thin triangles that you see from all objects where it is possible. While there can be situations where this is not possible, the best solution is to remove the long, thin triangles completely.
• Avoid using shiny materials on an object with long thin triangles as it causes flickering.
• Use Level of Detail (LOD) and remove the long, thin triangles when they are further away on-screen.
• Technically, it is better to keep triangles close to equilateral. Ensure that the triangles have more inside area, when compared to the edges.
Smoothing groups 光滑组
Use smoothing groups, or custom vertex normals, to define the hardness of an edge and alter the look of a model. Smoothing groups helps to create better shading when the art direction intentionally uses a tiny polygon count.
Take extra care as smoothing groups affect the UV islands of a model, and also the quality of a normal map when you do baking. This is explained in further detail in our Texturing Best Practice chapter on page 6-73.
If smoothing is implemented on a 3D model, then it must be exported from the 3D software and get imported into the engine.
The following image shows an example of how smoothing works when applied to an object:
Remember these tips when using mesh topology:
• When creating a 3D asset, do use a reasonably tidy and clean topology.
• Clean topology is essential for characters, or other objects, that are deforming or animated.
• Do not be obsessed with having perfect topology on a 3D model. While not all objects need a perfect edge flow, try to keep the model tidy.
— The player, or end user, does not see the wireframe of a 3D model.
— The texture and material that is applied to the mesh have a bigger contribution to the look of a 3D model.
The following image shows an example of a wireframe of the rock cliff mesh that uses simple geometry and topology. The rock cliff looks much better with the material that has been applied. Therefore, any issues with the topology have disappeared:
Shape exaggeration is a technique where certain parts and shapes are made bigger than normal to help with readability. However, whether this is the correct approach for your game depends on the type and style of the game that you are creating.
• A mobile device screen is small and it is sometimes hard to capture certain shapes when they are tiny.
Exaggerating the shape helps to overcome this. For example, make the hands on a character larger so they are more easily seen on a small screen.
The following image shows how an exaggeration in the size of a hand could look. The hand, sword, and general body proportions are all emphasized in different ways. This was done to improve the visibility, while accounting for the lower polygon count that was used: