- Home /
Performance Optimization for Mobile 3D, No Static
So I am working on a mobile project and while being pretty new into performance optimization I would like to hear what my options are. The context is as follows:
I am spawning a lot of Instances of a fairly primitive object (48 verts with shadows off). This group of objects is meant to be the environment. Problem: I want to be able to rotate my Environment in a predictable way. Therefore I cannot set anything static which I imagine is a huge problem for mobile. I am currently working on Combining the Meshes together with CombineMesh. What else can I do?
First rule of optimization:
Know where to start. Know what takes up your performance
To me it sounds like you did not consult the profiler. In case you did please post a screenshot and add the topmost 6-10 performance eater.
Answer by Bentley · Sep 11, 2020 at 08:03 AM
You can use GPU instancing if 1.) they are all the same mesh and 2.) you are not using too many dynamic lights (explained in the long answer below).
Short Answer: Navigate to the material that's assigned to the mesh and click the "Enable GPU Instancing" checkbox: https://pasteboard.co/JqyulYV.png
Long Answer: When a frame is rendered, the CPU must pass all of the data for each object to the GPU so that the GPU can draw the frame. If you have several objects in your scene, then the amount of work required to pass the data for each of those objects to the GPU can become excessive, which will cause your frames to be drawn slower. Even if your GPU could handle drawing those objects, your CPU can't get the objects' information to the GPU fast enough.
Enter GPU instancing. By enabling GPU instancing you are telling the GPU, "I want all of these objects drawn with the same material instance, mesh, etc., I just want them in different places." Your CPU can then batch several (1024, if I recall correctly) meshes into a single draw call and push them all to the GPU, passing only the positional data for the object and passing the textures, meshes, etc. a single time. In some cases this can provide a massive performance boost.
Drawbacks: Sometimes there are reasons that your meshes can't be batched, and those can be seen in the "Frame Debugger" window (enter play mode in the editor, pause the game, go to Window>Analysis>Frame Debugger, then click enable in the top-left corner). In the frame debugger you can expand your Camera.Render>Drawing hierarchy to see where most of your draw calls are being spent (it will tell you each and every draw call that your game is making). With GPU instancing enabled on your material you should hopefully see a lot of entries labelled "Static Batch", which means that the CPU was able to properly batch your meshes. If you see the names of individual meshes then you can click on them and read why it wasn't batched in the area to the right labelled "Why this draw call can't be batched with the previous one". A big killer here is lighting.
If, for example, you have 10,000 of the same mesh being drawn on the screen with a single light, they will all be batched into ~10 batches. If, however, you have 10,000 of the same mesh with ~100 lights scattered throughout the scene, the frame debugger will tell you that the "Objects are affected by different forward lights", in which case you would need to look into baking your lighting or reducing the number of lights in your scene, etc.
There are several reasons why a mesh may not be batchable and the frame debugger will tell you those reasons so that you can find your bottlenecks.
I hope that helps, Bentley
Answer by iTzsKiLLeR · Sep 11, 2020 at 09:18 AM
@Bentley Thank you very much. When I am in the frame debugger, It says they are all batched individually due to having different materials. Which i don't get they are all share the same material. I am Having an Albedo texture and a Metallic Texture for this material. Maybe that is the reason?
Your answer
Follow this Question
Related Questions
3D performance on mobile platforms? 1 Answer
Mesh rendering problem on mobile (using Vuforia) 0 Answers
why lwrp is very slow? 0 Answers