Unity shader memory usage optimization

The reason why the shader file takes up a lot of memory

The biggest reason is that there are too many variants of multi_compile. The more variants, the larger the file size.

Check the number of variants

View the number of shader variants
The standard shader has a lot of variants, and it is generally not used, and the shader is customized. It is recommended that the number of variants should not exceed 100

method to reduce the number of variants

Reducing the number of variants can be handled from multiple angles.

1. Graphic settings

insert image description here
Limit the baking scheme, fog scheme, etc. in the project.

Two, shader_feature use

Example: #pragma shader_feature _NORMALMAP
When the variant of the shader_feature directive is not used, it will not be compiled into the final file, which can reduce the number of final variants.
Note: If this function is used in versions 5.4.4p4, 5.5.1p4, and 5.6.0b8 or earlier, the material and shader must be in the same assetbundle to be typed into the assetbundle. Later versions can be processed with ShaderVariantCollection, but the shadert variant files must also be in the same assetbundle. (In the so-called same assetbundle, they use the same package name AssetImporter.assetBundleName)

Three, skip_variants use

This instruction is used in the shader.
Example:
#pragma skip_variants FOG_EXP
#pragma skip_variants FOG_EXP2

4. Use of #define

This is also used in the shader, for example. #pragma multi_compile_fog There are multiple instructions, but if you only use one, you can remove this instruction and replace it with #define FOG_LINEAR.

Guess you like

Origin blog.csdn.net/ytmteihc/article/details/126876484
Recommended