In this section of the guide, we will describe some best practice tips. You can use these tips during the development of your game.
Keep the shader simple
In a situation where overdraw is unavoidable, make the shader as simple as possible. Keep these principles in mind:
- Use the simplest shader possible, like unlit, and avoid using unnecessary features.
- Unity has a shader that was designed specifically for particles, which can be a good implementation to start with.
- Try to minimize overdraw. Reducing the number and size of particles can help with this.
Profile shader complexity
Adding more texture samplers, transparency, and other features makes a shader more complex and can affect the rendering. We recommend that you profile your shaders often.
Arm provides tools to perform profiling, for example Mali Offline Shader Compiler and Streamline. However, these tools require a higher level of graphics knowledge to understand more about how the GPU works. If you are editing shaders, then this is an area worth studying more deeply.
Do as many operations as possible in a vertex shader
It is common in projects to achieve a specific look through the combination of a vertex shader and a pixel, or fragment, shader. Vertex shaders work on every vertex, and pixel shaders run on every pixel.
Usually, there are more pixels that are being rendered than there are vertices on screen. This means that the pixel shader runs more often than the vertex shader. We recommend that you move computation from the pixel shader to the vertex shader whenever possible.
Moving operations to a vertex shader usually means moving the processed data onto the pixel shader, through varying variables. So, even though moving operations to a vertex shader is generally a good idea, you must pay attention to the tiler in case it now becomes the limiting factor in performance. As usual, after working on optimizations, you must do further profiling.
Avoid using complicated math operations where possible
You use mathematical operations within the shader to customize its look and behavior.
These math operations are not equal in terms of performance cost. Therefore, you must pay attention to their usage. Some of the more complicated operations include sin, pow, cos, divide, and noise.
Basic operations, like additions and multiplications, are faster to process, so try to keep the number of slower math operations as small as possible. You should minimize the amount of complicated math that you use must be kept lower on older devices, for example devices that use GLES 2.0.
Always do performance profiling
To understand where the real bottlenecks are occurring in your application, profile the performance. Profiling is also recommended to compare the before and after effect of any optimization that you use.