Important note : I use Addressables. It only happens in Addressables build. Very hard to know where to post about issues overlapping 2 forums
I have noticed there is some missing variants in my builds. I am using Simple Lit Shader from URP and at a lot of places it is used with Alpha Clipping. It works perfectly in the editor, but in build it just doesnât use the _ALPHATEST_ON keyword, hinting me that maybe Unity decided to strip the alpha clipping variants ? (I am using strip unused at the moment). I believe I could fix this with âKeep Allâ stripping setting and manually stripping my shader variants, but Iâd really like to understand why this is happening. Thank you !
You can write your own implementation of IPreprocessShaders and just check if the keyword youâre interested in is present in any of the variants. Run it before the one thatâs shipped with URP and see if the keyword is there, then run it after URPâs stripping.
So URP has itâs own IPreprocessShaders, is it related to the Shader Settings Graphics settings? I actually have one myself to strip as many variants as possible, but I already tried disabling mine in case I was accidentally discarding this variants and it was not me. Iâll debug to make sure this variant never gets to my script, but I would be pretty interested to insert my script before URPâs. What is itâs callback order ? Is there also a way to disable/edit it since I am manually keeping track of all variants I need in my project ?
Thank you !
@aleksandrk After further researching, I found said script and that it is not related to the Graphics shader stripping options. Even if I toggle keep all, the IPreprocessShaders of URP runs and strips shaders variants. Is there really no options to deactivate URP shader stripping ? It really seems to be the culprit and I donât want to embed URP package.
Oh, the âShader stripping optionsâ in Graphics are a different thing. These are only for lighting-related keywords, and shouldnât influence alpha test.
AFAIK URP shader stripping is based on the URP setting assets, but I would suggest to double-check that.
Weâre having this same issue, and weâve been trying a lot of workarounds using Addressables (forcing materials with the guilty shaders, creating custom ones, adding them to âalways includeâ, but as has already been said, URP settings are different from standard graphic settings.
Weâre using the standard unity Lit shader. For example, one of the failing cases is using alpha cutoff, and another case is using Roughness. Nothing weird or complicated. Shouldnât this be supported by Addressables?
Get rid of Unity shaders. Addressables fails to know which variants you need. It compiles variants you donât need, and discard one that are needed. Unity URP shaders are made with so many possible variants (up to many millions per shaders), so Addressables seems ot have a hard time managing this. I made my own shaders with shader graph to replace Unityâs shaders because I was missing alpha clipping, emission and some other properties at time.
On top of using my own shaders, I use my own implementation of IPreprocessShaders to aggressively strip all variants that are not needed in my project. Shader memory footprint went from 1.2GB to 30mb (on mobile).
An old post from me where I go over the process of making your own IPreprocessShaders script.
Spent a looooot of time on this so donât hesitate if you have any questions. After a lot of try and errors, our shaders are now 100% stables both on iOS and Android