Optimize Shader Compilation & Package Sizes
Unreal Engine Project Settings allow a major reduction (up to 50%) of shader permutations affecting shader compile times, package size, and load times. You can find the options under the Engine > Rendering > Shader Permutation Reduction Category. Which settings you can disable will depend on your project’s rendering requirements.
- Stationary Skylight Stationary skylight requires permutations of the basepass shaders. You can disable this when never using a Stationary Skylight as the name implies.
- Low-Quality Lightmap shader permutations The mobile renderer requires low-quality lightmaps, disabling this setting is not recommended for mobile titles using static lighting.”
- PointLight WholeSceneShadows requires many vertex and geometry shader permutations for cubemap rendering.
- Atmospheric Fog requires permutations of the basepass shaders. You can disable this if you don’t use the AtmosphericFog Actor which simulates atmospheric light scattering.
- Sky Atmosphere requires extra samplers/textures to be bound to apply aerial perspective on transparent surfaces (and all surfaces on mobile via per-vertex evaluation).
- Sky Atmosphere Affecting Height Fog The sky atmosphere component can light up the height fog but it requires extra samplers/textures to be bound to apply aerial perspective on transparent surfaces (and all surfaces on mobile via per-vertex evaluation). It requires SupportSkyAtmosphere to be true.”
When your project is missing required shader permutations by the level it will tell you about it in the Viewport right next to the “Lighting needs to be rebuilt” message. This can be helpful to quickly realize that a level has changed such as a SkyAtmosphere actor being added later on and now requiring those permutations to be re-enabled.
These options are enabled by default, especially stylized games that don’t rely on PBR/realistic lighting may benefit. But many if not most projects may find that they can delete certain settings such as LowQualityLightmaps which are targeting the Mobile renderer (HoloLens and certain other VR games might use the Mobile renderer as well).
Changing any of these settings requires all shaders to be recompiled. This may take a long time depending on your project size. For teams using a shared Derived Data Cache I’d recommend looking into the -fill command line option to have the shaders back in the DDC more easily (without having to load each level.
Another nice effect when turning off these shader permutations is optimized package size and load times. Reducing these permutations will reduce the total size of your materials once cooked.
Any way of checking how many shaders I saved for each option?
Not to my knowledge, if you have a lot of time on hand you could disable a single option and relaunch the editor. You’ll then see how many shaders need to be compiled upon launch. This gives a rough indication.
File – Cook content for windows
If this process completes successfully, these folders will contain the report in .csv format.
%ue4_your_project_folder%/Saved/MaterialStats
%ue4_your_project_folder%/Saved/MaterialStatsDebug
in MaterialStats report you can see number of shader permutations.
in MaterialStats report you can see the reasons for this.
Also you can view this report inside ue4 and export it in a slightly different format.
ue4 – Window – Statistic – Shader Cooker Stats
Recommendations
1. Delete all shader cache, then you can see the compilation time of shaders in the report.
2. To save time when fixing one material, you can run the cooking of only modified files. Using “-iterate”.
%Path_to_UnrealEditor.exe% %Path_to_ProjectName_.uproject% -run=cook -TargetPlatform=WindowsNoEditor -unversioned -iterate
Other things related to material that don’t need cooking:
1. ue4 – window – Material Analyzer
Very basic recommendations. Allows you to quickly find Material instances with the same patameters.
2. ue commands:
DumpMaterialStats
DumpShaderPipelineStats
DumpShaderStats
I honestly don’t understand where the numbers for these reports come from =(
3. Python editor script
In theory if you have a full understanding of how to calculate permatations.
You can make a script, which may be faster than running a content cooking.
I did this and now my entire project fails to load!!!!!
You can always open the INI files in MyProject/Config to remove any project setting changes. You can also delete the temp folders like DerivedDataCache / Intermediate / Saved to clear our anything that may be corrupt. And of course use version control on projects at all times so its easy to revert a change.
It may even be unrelated to this setting that was changed at all. The above steps should help.
I like these, been thinking of doing something similar
Thanks Tom! Also love the new format!
Hi Tom, UE4.24 have a weird compiling shader my landscape material compile 99000 compiling shaders, do you know if this is a bug or not? i’m tryng to use Virtual Texture in 4.24 but looks impossible since my cpu is very old.
I have the same issue
Thanks Tom! What’s a good starting point for shader options?
Trying something new, a short-format post with variety of hidden gems, tips and tricks for Unreal.