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

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

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.

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?

Unity now supports local (per shader) keywords, though i’m not sure whether this is implemented for Shader Graph yet: Unity - Manual: Declaring and using shader keywords in HLSL

Still hitting this.

According to Keywords | Shader Graph | 10.2.2 , 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.

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.