Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

URP Simple Lit - Shader Variants missing in build (Alpha Clip)

Discussion in 'Shaders' started by rob11, Oct 13, 2021.

  1. rob11

    rob11

    Joined:
    Mar 7, 2017
    Posts:
    57
    Important note : I use Addressables. It only happens in Addressables build. Very hard to know where to post about issues overlapping 2 forums :D

    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 !

    In editor :
    upload_2021-10-13_8-42-37.png

    In build :
    upload_2021-10-13_8-42-57.png
     
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,852
    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.
     
  3. rob11

    rob11

    Joined:
    Mar 7, 2017
    Posts:
    57
    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 !
     
  4. rob11

    rob11

    Joined:
    Mar 7, 2017
    Posts:
    57
    @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.
     
  5. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,852
    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.
     
  6. BonitaPersona

    BonitaPersona

    Joined:
    Feb 20, 2014
    Posts:
    16
    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?

    Is there any way to work this out?
     
  7. rob11

    rob11

    Joined:
    Mar 7, 2017
    Posts:
    57
    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