I have a shader that I change during runtime via UI buttons. It changes the shader to either have a vertical or radial gradient, or activates a texture instead. It works fine in the editor, but doesn’t work at all when I run it on android. Will it even work on android? I have no idea what the problem could be, so any help is much appreciated!
You want #pragma multi_compile for keywords you want to enable / disable at runtime. If you use shader_feature the build will strip any shader variants that aren’t referenced by materials used in the build, where as multi_compile will automatically include all variants.
I’d suggest using this one line instead of the two you have:
If you switch the two shader_feature lines you have now to multi_compile you’ll have the weird problem that the toggles you have will stop working even in the editor. This is because shader_feature and multi_compile annoyingly work slightly differently and shader_feature always assumes you want a variant of the shader without the keyword(s) listed after it enabled, where as multi_compile you have to be explicit about that by having one of the listed “keywords” be only one or more underscores. But if you keep it as two lines you’re asking Unity to create 4 variants of the shader when you really only want 3: no keywords, only VERTICAL_GRADIENT, or only TEXTURE_ON. You don’t ever need both TEXTURE_ON and VERTICAL_GRADIENT which having two multi_compile or shader_feature lines will allow for.
You also didn’t mention how you are trying to change which variant you use. Changing the material properties at runtime won’t do anything as they’re just dummy properties the material inspector is using to let it show the options. When you toggle the setting it’s calling mat.EnableKeyword() / mat.DisableKeyword() behind the scenes, which is what you’ll need to do as well.
bgolus, thank you so much for taking the time to write that detailed explanation and your help. I really appreciate it, you are just so helpful and awesome on these forums. That solved my issue and you helped me understand why. Thank you!!!