Happy to announce a new handy tool called Shader Control.
What it does is help you take control over keywords usage at project level from a convenient unified view in the Editor.
- Has your project exceeded Unity shader keyword limit? - Does your project take ages generating the build? - Do you want to reduce the build size removing unnecessary shader variants?
Those are the kind of situations where Shader Control can be very helpful.
How does it work?
Shader Control quickly scans your project and shows all shaders that use keywords and generate what Unity calls a shader variant. From this list, you can see what keywords can be disabled (or re-enabled) per shader and let Shader Control do the change for you. As you disable or enable keywords, Shader Control will tell you the global number of shader variants that will be generated by the compiler.
It will also clean any material that uses disabled keywords so they do not count towards the imposed limit of 64 or 128 max keywords per project.
Note that Shader Control operates at shader level, it can edit the shader itself, not only disable keywords on materials so it effectively prevent any unwanted shader variant from your build.
Get it now on the Asset Store and take a look at your project now!
V2 has been released. This update is a great improvement in many ways:
It will list any shader potentially included in a build, either those shaders found in Resources folder or referenced by materials. You can now check which materials are using what shaders from the list.
It can prune keywords in two ways: if the shader code is available, it can modify the shader automatically so Unity won’t waste time compiling variants that won’t be used. Yes, the keywords listed along the shaders (multi_compile or shader features) can be disabled or enabled again with a click.
Also any material using keywords not available in shaders will be cleaned. If the shader source is not available, you can choose which keywords will be pruned from your project with a single click.
Hey, yet another fantastic tool from Kronnect! Thanks for making this!
I’m grappling with this error on Mac OpenGL:
-------- GLSL link error: WARNING: Output of vertex shader ‘vs_TEXCOORD5’ not read by fragment shader
WARNING: Output of vertex shader ‘vs_TEXCOORD0’ not read by fragment shader
ERROR: Implementation limit of 16 active fragment shader samplers (e.g., maximum number of supported image units) exceeded, fragment shader uses 17 samplers
I’ve used Shader Control to reduce the number of keywords to 212, but this still appears – and I’m not sure what that “16” is referring to. Can Shader Control help me with this?
On Mac OS X and OpenGL texture samplers in fragment shaders are limited to 16 - removing extra samplers can’t be done with Shader Control as it will probably break the shader or definitely change its behaviour/output.
If this shader is created with some authoring tool, try removing some features or material layers from the tool itself. Or send me a copy of the offending shader by email and I’ll take a look into it for further recommendations.
Thanks for the prompt reply…but I don’t even know which shaders are using up all the texture samplers. (I assume some in the project already were, and then I added some new shaders which pushed me over…but I’d probably prefer to delete some of the older ones than the new ones.)
This is the entire error in the console, so I guess it doesn’t?
-------- GLSL link error: WARNING: Output of vertex shader ‘vs_TEXCOORD5’ not read by fragment shader
WARNING: Output of vertex shader ‘vs_TEXCOORD0’ not read by fragment shader
ERROR: Implementation limit of 16 active fragment shader samplers (e.g., maximum number of supported image units) exceeded, fragment shader uses 17 samplers
No, it doesn’t, sorry. Perhaps the error is dumped to Editor.log while compiling the shader in a build of a scene that uses it… try it. Otherwise you will need to manually remove temporarily group of shaders from the project and identify which group / shader is producing that error. Start with the shaders that use more keywords according to Shader Control, chances are some of them are the culprit. Make a backup copy of the project in any case before moving files out and inside the project as you can quickly mess things.
No problem. This is an issue that perhaps could be better identified in next releases of Shader Control. If you find the bad shader send it to me so I can add some new detection features to this asset.
@gecko , windows and mac shaders should both aim to be <=16 samplers (bare in mind Unity standard shader uses a lot of ‘hidden’ ones ie for lighting etc), this is a general API limitation. It sounds either like you’re still over the max keywords (which can prevent shaders compiling and cause weird errors like this) or you’re using a shader that is badly made. Does it go away if you right click the shader folders and reimport?
@Kronnect interesting asset. Bizarre Unity doesn’t have it built in but that’s your profit I guess
Shader Control can fill some gaps here identifying and sorting shaders by complexity and allowing you to quickly disable some keywords but even with this tool there are, as we all know, limitations to how shader variants are defined.
For instance, you can define multiple permutations (multi_compile) of keywords but it would be great if some keywords combinations could be excluded from the mix. This is not possible right now in Unity unless you manually generate the desired combinations. Would this be an useful feature for Shader Control?
Shader_feature pragma is incredibly slow as well during import. I guess the Editor has to examine existing materials looking for enabled keywords to generate the corresponding code.
Also multi-instancing should be an opt-in feature in surface shaders. In Unity 5.6 all surface shaders get automatically the instancing variants including those that don’t need them. Yes, you could add the noinstancing pragma but again, you usually never touch shaders from others.This is another feature that could be added in a future update as well, sounds good?
That’s an estimation using the explicit keyword count which for some reason casts an overflow when printed on the console. Is it possible to have a copy of your project to check this? Thanks.
Hi, I think it was related to “Wireframe Shader DirectX 11”, and when I restored it, the problem went away. There are also some other payware shaders in the project right now for me to post it.
Hello!
Does this tool treat any surface shader similarly to the Standard Shader? It showed a couple of keywords on one of my surface shaders(originally duplicated from Unity’s “Mobile/Diffuse” shader.), which I wasn’t expecting. After disabling them, the included variant count in the inspector increased from 12 to 51.
In the original shader, I was making use of some #pragmas to try to strip out the fluff. I could not sort out why that many variants(12) were being used, so I decided to try out this tool!
The documentation mentions pruning for the standard shader, but I don’t see that option on surface shaders.
@Emericanized yes, Shader Control works with surface and vertex/fragment shaders. The variant count should never increase after disabling a shader keyword. Feel free to send me your shader by pm or email so I can advice.
Shader Control works with the shader source code. But when the source code of the shader used by a material is not found, the “Prune” option still can clear the keywords of the material itself. This option is useful for shader features which are keywords that are only enabled when a material uses them in the scene.
Thanks for the guidance on the Volumetric Fog forum about pruning keywords. Now I’ve got it down to 245 keywords, according to the Shader Control inspector panel…but I am still getting the “Maximum number (256) of shader keywords exceeded,” warning in the console. That error appears only twice now, indicating two shaders that won’t be used, but it keeps appearing even as I pruned from 256 down to 245 now. Any idea what’s going on?
Shader Control says:
Total shaders: 418 With Keywords 62
Used Keywords: 245 of 303 (80%) Actual variants 1172 of 1857826 (0%)