Unity GPU Profiling

GPU Profiling

GPU performance might affect performance badly, In my case (TrajektAR) is basically an AR app, so Occlusion culling was not an option (at least for the ar camera), on top of that I had another camera rendering the whole scene again, So optimization was crucial to provide higher frame rate per second.

I had to go through some optimization procedures before I start profiling

1. Camera Clipping Planes

Camera Clipping Planes

Play with the Near and Far distances to show only what needs to be shown with this specific camera.

In other words, it might be very costly from a rendering perspective to draw objects that are far or very close to the camera and not important for the app/game functionality.

In my situation, I had an AR Camera and overlay camera showing the whole map, it was nonsense showing the player and drawing the player mesh, however, I wanted to show the ground below the player but not the player itself.

In this case, Number 2 was useful.

2. Camera Culling Mask Layers

Culling Mask Layer is a good solution when you have two cameras in the scene and want to render specific objects on each camera ( Group certain objects by layer and choose whether they should be rendered with this camera or not).

3. Lighting Culling Mask

Like camera culling mask, Not every object on the scene should be affected by lighting, try to minimize the rendering work by only applying Lighting for layers that need to be lit.

(In AR apps, I don’t think Unity Lighting is the way to go. If you write your own shaders or use the unlit texture shader it might provide a better experience and less work is done )

Also, as a precaution, I try to turn off the cast shadows checkmark in the mesh renderer component for objects that don’t need to have shadows rendered.

4. Textures

Textures are usually on top of the list in terms of size in the build and the rendering performance problems.

I started with textures responsible for 75% of the build size to the following

Build Size Break-Down

When dealing with textures we should consider the target devices, overriding the max size value for phone platforms is highly recommended

Unity Textures Optimization

Some online articles state that disables mipmaps generation is a good approach since it consumes more space 33% more but unity documentation states that you should enable mipmaps.

5. Static Batching

Unity Static Batching

Enabling Static Batching by checking the Static checkbox is useful if the object is not a moving object and minimize the draw calls for this object.

6. GPU Instancing

Unity GPU Instancing

Enable GPU Instancing if you have a game object that is being instantiated over and over again, you can find the option by adjusting the material properties.

After going through those precautions its time to start profiling

Choose the rendering tab in the profiler

Unity Rendering Profiler

The main purpose of rendering profiling should be to minimize the number of draw calls

Unity Frame Debugger

The Frame Debugger is a useful tool to give an insight into how objects are being rendered

Click on Open Frame Debugger

Unity Frame Debugger

Use the slider and check the game view to see how objects are being rendered on the game view.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store