Search Unity

Feedback SG shader variants - limit hit with a small number of keywords

Discussion in 'Shader Graph' started by huwb, Jan 4, 2020.

  1. huwb

    huwb

    Joined:
    Oct 19, 2013
    Posts:
    24
    Hi all,

    We want to put a bunch of features behind static switches. So far we've added 4 Shader Feature keywords to our SG, and we're getting the error that its generating more than 128 variants (in 2019.3.0f1):

    > ... is generating too many variants. Either delete Keywords, reduce Keyword variants or increase the Shader Variant Limit in Preferences > Shader Graph

    Changing the editor preference is not really an option for us since we're an asset that will embed in other projects. Our system needs 1 keyword, so we're limited to only 2 usable keywords before we exceed the limit.

    I guess the purpose of this post is to sanity check our approach in case I'm missing something obvious, and to point out this is a constraining limit for us. We want these to be entirely static (not multi_compile), and we had a bunch of these for the non-SG version of the shader and it was all peachy, so its a shame we're hitting this now we're moving to SG.

    Thanks
    Huw
     
    Last edited: Jan 4, 2020
  2. khalvr

    khalvr

    Joined:
    Sep 12, 2017
    Posts:
    53
    I suspect that Shader Graph is adding a bunch of keywords internally in the generated code, such as multi-light support, fog, instancing, shadow support, lightmap variants, etc. Ideally, you'd be allowed to strip some of these options to make the shader lighter, but as of now i think you need to copy the generated code and comment out the shader_feature pragmas manually.
     
  3. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    Did you find a solution for this?

    To SG devs, could the shader variant limit be set per shader so that it is an option on the master node?
     
  4. khalvr

    khalvr

    Joined:
    Sep 12, 2017
    Posts:
    53
  5. hdb0

    hdb0

    Joined:
    May 16, 2015
    Posts:
    6
    Still hitting this.

    According to https://docs.unity3d.com/Packages/com.unity.shadergraph@10.2/manual/Keywords.html , we should be able to define keywords as Local and Shader Features and they should have their own limit. However when I add these I seem to hit the global limit:

    Error in Graph at <...> at node PBR Master: Graph is generating too many variants. Either delete Keywords, reduce Keyword variants or increase the Shader Variant Limit in Preferences > Shader Graph.
     
  6. hdb0

    hdb0

    Joined:
    May 16, 2015
    Posts:
    6
    I realised at some point that one of my SGs was exceeding the shader variant limit and i was getting weird null ref exceptions and undefined behaviour in the shader graph editor in both 2019 and 2020.

    i can up the limit here obviously, but the users that i ship our SGs will not be given an indication of what has gone wrong.