I have a shader with many different shader_features keywords. It works fine in the editor, but unless I change them to multi_compile, they don't work in the build. I've tried using the Frame Debugger in the editor and on the build, and I can see that my keywords are missing in the build (but are present in the editor). These are not dynamic keywords enabled via C#, they are set on the material at build time. I've tried disabling "Strip Unused Variants" and also tried preloading a shader variant collection that includes the desired shader variants - neither of these seem to work. Changing them to multi_compile introduces excessive build times, so that isn't a good option. The shader_feature keywords seem to be working for other shaders in my build. Does anyone know what else could be causing this issue? Is there something I might be missing? Here's my pragma code, in case it is helpful: (Unity 2021.3.14f1)
Through trial and error, I discovered that "Strip Unused Post Processing Variants" was the cause of this behavior. Although this isn't a post-processing shader, it does use the keyword "_DISTORTION" which leads the stripper to believe this is an unused post-processing variant. Renaming my keyword solved the issue! This is a pretty unique edge case, but a fix might involve checking the shader name in ShaderPreprocessor.StripVolumeFeatures() before stripping to prevent this from happening to anyone else.
Heyhey! Thanks for letting us know. This is clearly a bug. I'm working on this area right now so I shall fix this.
Same problem in Unity 2022.3.10f1 LTS with URP. Can't update to the higher version of the LTS since those are very broken at the moment. This happens with the shader graph shaders, which is even more bizarre.
Can you file a bug about this? Both URP shaders and ShaderGraph go through the same keyword stripping so it shouldn't matter which one is used. Do you know what keyword is being incorrectly stripped?