Search Unity

Bug My material's shader_feature variants are missing from build.

Discussion in 'Shaders' started by adamgryu, Jan 26, 2023.

  1. adamgryu

    adamgryu

    Joined:
    Mar 1, 2014
    Posts:
    188
    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:
    upload_2023-1-26_11-48-8.png
    (Unity 2021.3.14f1)
     
    Last edited: Jan 26, 2023
  2. adamgryu

    adamgryu

    Joined:
    Mar 1, 2014
    Posts:
    188
    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.
     
  3. Elvar_Orn

    Elvar_Orn

    Unity Technologies

    Joined:
    Dec 9, 2019
    Posts:
    162
    Heyhey!
    Thanks for letting us know.
    This is clearly a bug. I'm working on this area right now so I shall fix this.
     
    adamgryu likes this.
  4. IJM

    IJM

    Joined:
    Aug 31, 2010
    Posts:
    143
    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.
     
  5. Elvar_Orn

    Elvar_Orn

    Unity Technologies

    Joined:
    Dec 9, 2019
    Posts:
    162
    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?