Triangle and Polygon Usage

Tutorial

·

intermediate

·

+0XP

·

20 mins

·

(200)

Unity Technologies

Triangle and Polygon Usage

In this tutorial, you will learn about how to best optimize performance and maintain visual fidelity while working with triangles in your 3D models.

Languages available:

1. Overview

To optimize the performance of your application, you must be aware of the number of triangles that are on-screen at any given time.

It is important to use the minimum number of triangles to get the correct balance between the intended quality of your 3D models and delivering consistent performance.

The following image shows a comparison between two 3D objects. One object uses 584 triangles and the other object uses 704 triangles. Both objects look the same in Shaded mode. This shows that you can remove any edges in your models that do not contribute to the silhouette.

In Unity, the format of the Mesh index buffer dictates the maximum number of vertices that a 3D object can use:

  • A 16-bit index buffer supports up to 65,535 vertices.
  • A 32-bit index buffer supports up to 4 billion vertices.

When you use fewer triangles, it means fewer vertices for the GPU to process. This is especially important when creating content for a mobile platform because processing vertices is computationally expensive. Having fewer vertices to process results in better overall performance and allows you to release your application on more devices (and not just devices with the most powerful GPUs).

2. Testing on Different Hardware/Screen Sizes

It’s essential to view or test your application on as many target devices as possible. Testing your application only on a computer screen won’t give you the information that you need for optimization.

Keep in mind that mobile-device screens are smaller than the average computer monitor. Therefore, details that use lots of triangles may not be visible on a mobile device. As a best practice, use more triangles on 3D objects that are closer to the camera and use fewer triangles on 3D objects that are in the background.

In the following image, 3D models are used in the foreground while lower-quality 3D models are baked into the 2D background:

While there is no fixed number for the maximum on-screen triangle count, the more 3D objects that are on-screen at the same time, the fewer triangles you can use per object. However, if you’re displaying fewer 3D objects on-screen, then you can use more triangles per object.

The target device also matters. Newer hardware is often able to handle more complex geometry than older mobile devices.

3. Details in Areas That Matter

Both polygons and vertices are computationally expensive on mobile platforms. By placing polygons in areas that really contribute to the visual quality of the application, you’re not wasting the processing budget.

Due to the small screen size on most mobile devices and the location of 3D objects in your application, many small triangle details on a 3D object might not be visible. This means that you should focus on large shapes and parts that contribute to the silhouette of the object rather than small details that might not be visible.

The following image highlights the object’s silhouette in red to show how the different shapes contribute to it.

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.

(Note: A normal map is a texture map storing the surface direction of each pixel.)

The following images show the same mesh with and without a normal map:

Consider deleting the back or bottom of an object that’s never seen from the camera’s POV. However, this needs to be done carefully as it might limit the re-usability of the Scene. For example, if you delete the bottom part of a table Mesh, that means you can no longer place that model upside down or it for something else.

4. Avoiding Micro Triangles

Micro triangles are tiny triangles that don’t contribute much to the final look of an object or Scene.

When a 3D object with a large polygon count is moved away from the camera, a micro triangles problem occurs. A micro triangle is often referred to as a triangle that is between one and 10 pixels in size.

Micro triangles are too small to see, but computationally expensive to process.

The following image shows the number of triangles that are used when a 3D object is near the camera (right) and the number of triangles used when it’s further away (left).

For the following image, most of the triangles in the highlighted area are too small to be visible on a mobile device. Therefore, they don’t contribute much to the final look:

The following highlights the bevel on the pillar when it’s viewed from a distance. The bevels are not a problem when seen close-up:

Here are a few steps you can take to mitigate this issue:

  • For an object that changes distance from the camera, use Level of Detail (LOD), which we will cover in the next tutorial. Using the correct LOD simplifies an object when it’s further away.
  • Use fewer triangles on background objects.
  • Avoid using polygons to create the finer details. Instead, use a combination of textures and a normal map.
  • Avoid using shiny Materials on objects with long, thin triangles, as it causes flickering.
  • Merge any vertices or triangles that are either too small to see on-screen, or are not adding much value to the final image.
  • Ensure that triangles have more inside area compared to their edges. Technically, it’s better to keep triangles close to equilateral.
  • Try to keep triangles above 10 pixels in area.
  • Remove any long, thin triangles from objects when possible.

There are several reasons why minimizing the use of micro triangles is important.

  • The GPU must process all of the triangles and vertices even when they’re not adding any value to the final Scene, resulting in unnecessary GPU cycles.
  • Memory bandwidth is negatively affected when more data must be sent to the GPU for processing.
  • The amount of processing that’s required impacts the battery life of a mobile device. Therefore, less data means a longer battery life.

5. Conclusion

By minimizing the number of triangles in a Scene to focus on areas that matter, you can improve the performance of your application across the board and target lower-end mobile devices. In the next tutorial, we’ll discuss Level of Detail (LOD) and how it can help optimize geometry even further.

Complete this tutorial