Unity shader variant optimization

The number of shader variants can be found in the property menu of the unity shader, and the corresponding keywords and their permutations and combinations can also be seen. Keywords are divided into global keywords and local keywords. The former is mainly affected by project settings, such as setting different lightmap modes, or switching fog, etc. The latter is mainly customized in the shader. The keyword can also be set through C# code, switched through the setkeyworld method of the material or shader, or using a custom preprocessing script. The optimization method can be to adjust the shader and project-related settings, or switch keyworld through a script, or filter it through the shadervariantcollection provided by Unity to reduce shader variants.
For specific usage, please refer to https://www.cnblogs.com/rexzhao/p/7884905.html
https://gwb.tencent.com/community/detail/118869
(others to be added)

The main problem encountered is that the variants collected in the Unity editor do not seem to be correct when running on the mobile phone. The shade will still compile a large amount of memory. I guess it may be necessary to collect the variant data when running on the mobile phone and then return to editing. In order to match the server settings, you can refer to this blog
https://blog.uwa4d.com/archives/USparkle_Shadervariant.html

There are many variations of pbr shadr generated using ASE or unity pbr shader graph. It seems that it needs to be written by hand. Many variations are caused by global key words. This can be set through c# scripts or some feature switches of the system, but it cannot be added to the shader. Close global keyworld

Tried variable collection and it seems to have little effect. It may be due to incomplete collection (related to multiple passes?), so compiling and running will still generate them all. I feel that I still need to use script settings. Please refer to this article https://www.xuanyusong.com/archives/4902

There is also a tool called Shader Control that seems to be able to optimize shader variants as well.

Guess you like

Origin blog.csdn.net/fdbvm/article/details/128844962