Additional Material and Shader Best Practices
Tutorial
·
intermediate
·
+0XP
·
0 mins
·
(78)
Unity Technologies
In this tutorial, we examine additional best practices when optimizing your 3D mobile application's Materials and Shaders.
Languages available:
1. Keep Shaders Simple
When overdraw is unavoidable, make the Shader as simple as possible. Keep these principles in mind:
- Use the simplest Shader possible (such as an unlit Shader) and avoid using unnecessary features.
- Use Unity's built-in Shader designed specifically for particles.
- To minimize overdraw, reduce the number and/or size of particles in your game.
2. Profile Shader Complexity
Adding Texture samplers, transparency, and other features make a Shader more complex and can affect rendering. We recommend that you profile your Shaders often.
Arm provides tools to do this, such as Mali Offline Shader Compiler and Streamline. However, these tools require a higher level of graphics knowledge
3. Math Operations In the Vertex Shader
It’s common in projects to achieve a specific look through the combination of a vertex Shader and a fragment Shader.
Vertex Shaders work on every vertex while 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. Because of this, we recommend that you move computation from the pixel Shader to the vertex Shader whenever possible.
Moving computation operations to a vertex Shader usually means moving the processed data onto the pixel Shader. Even though this is generally a good idea, you must pay attention to the tiler in case it becomes the bottleneck. As usual, after working on optimizations, you must do further profiling to determine the best solution for your particular situation.
4. Avoid Using Complicated Math Operations
Mathematical operations within Shaders customize the desired look and behavior.
But 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, such as addition and multiplication, are faster to process. It's best to keep the number of slower math operations as small as possible. The amount of complicated math that is used must be kept lower on older devices, such as ones using GLES 2.0.
5. Conclusion
There are many different ways to optimize Shader code, but to understand where the real bottlenecks are occurring, you have to profile your application. Profiling is also recommended to compare the before and after effect of any optimization that you make. In the next tutorial, we’ll dive into an example of how Shaders and Materials can be optimized in Unity using the SRP Batcher.