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

Question Can't have more than 7 shader keywords with Shader Graph and URP? Is this a bug?

Discussion in 'Shader Graph' started by Sinterklaas, Aug 9, 2021.

  1. Sinterklaas

    Sinterklaas

    Joined:
    Jun 6, 2018
    Posts:
    93
    Pretty much what the title says. On Unity 2020.3.15f2 (LTS), with Shader Graph version 10.5.1, whenever I try to add an 8th local keyword in any graph's blackboard panel, I get the following error:
    Code (CSharp):
    1. Error in Shader Graph Test:Graph is generating too many variants. Either delete Keywords, reduce Keyword variants or increase the Shader Variant Limit in Preferences > Shader Graph.
    2. UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()
    If I up the shader variant limit from 128 to 512, I get the error when trying to add the 11th keyword instead, which still isn't a lot. I'm guessing that Unity compiles literally every possible variant of the graph, even ones that are not actually used anywhere, since I've noticed the editor starts to update slower and slower as I add more keywords. But I'm new to URP and shader graph, so I don't really know.

    With hand-coded shaders on the built-in renderer, I had about 20 local keywords without issue, which allowed me to turn off specific parts of the shader whenever they weren't needed and save on computation time. Why is this a problem on URP? Should I just set the shader variant limit to a ludicrously large number and just deal with the slow compile times, or is there a better way to have 20-ish keywords in your shader graphs?
     
  2. Autarkis

    Autarkis

    Joined:
    Oct 10, 2011
    Posts:
    318
    2^7 = 128 shader variants
    I'm assuming that you mean you exceeded variants when you set the limit to 512 at the 10th keyword, as 2^9 = 512 variants.
     
  3. Sinterklaas

    Sinterklaas

    Joined:
    Jun 6, 2018
    Posts:
    93
    I see, well that clears that up.

    What I still don't quite understand though, is why this wasn't a problem on the built-in renderer. On the old renderer, I had about 20-25 local keywords in my hand-coded shader, which should have vastly exceeded the default 128 variant limit (which I never bumped up until I switched to URP). For some reason, I never got any errors before I made the transition.

    So I guess my two questions are: what changed in URP, compared to the built-in renderer? And what is the recommended way to tackle this issue (bumping up the variant limit, cutting down on keywords, or something else)?