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. Dismiss Notice

Unity is building Shader Variants for unused shaders

Discussion in 'Shaders' started by Dreamback, Jul 20, 2021.

  1. Dreamback

    Dreamback

    Joined:
    Jul 29, 2016
    Posts:
    220
    My project is compiling thousands of Shader Variants for HDRP/Lit, which I'm not using. How can we stop this? It's not included in Graphics/preloaded or always included shaders. And at the bottom of Graphics it says it should only be compiling 128 total variants, not thousands.

    Also, Unity never used-to take lots of time to compile Shader Variants at build time at all, is this some sort of "optimization" that we can disable, to return Unity to the old ways? This really makes iteration time horrible when the first time someone makes a build to test stuff, it takes literally hours.
     
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,844
    Hi!
    Which Unity version are you using?
    Which platform are you targeting?
     
  3. Dreamback

    Dreamback

    Joined:
    Jul 29, 2016
    Posts:
    220
    Good point, I should have mentioned that. Using Unity 2020.3.14f1 LTS, targeting Windows Standalone (x86_64) for VR using XRPlugin / Oculus. To be fair, the project was originally created as an HDRP project, and then switched manually to URP, but I've had these long Shader Variant compilations in the past as well when the project targeted URP from the start (and it was only a couple years ago, we never saw these Shader Variant compilations at all, so it seems something changed in how Unity works that had a negative impact towards making builds; if there was a flag that let us switch back to the old system during development, that would be very useful).
     
  4. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,844
    That's quite unlikely there is one, as there's no "old system" to begin with :)

    Ok, first off:
    This is not the amount of variants it needs to compile. This is the total number of variants the Editor encountered, and has nothing to do with what goes into the build.

    This just means they are referenced by something. If, as you say, you manually switched to URP, I suggest to try and uninstall HDRP - this may help.
    We have shader cache for variants that have been compiled previously. When a variant is in the cache, it's not compiled again, the data is just being read from the cache. Please check the Editor log after building the player, it should say per shader pass, how many cache hits it had.
    This, obviously, doesn't happen when a shader variant has never been compiled on a particular machine, unless you have the asset cache server enabled.