Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. We are looking for your feedback about Templates! Tell us about your experiences by taking our survey.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Max shader keywords exceeded, solution?

Discussion in 'Shaders' started by negativecap, Jan 30, 2014.

  1. negativecap

    negativecap

    Joined:
    Jan 27, 2013
    Posts:
    99
    Super simple question, I'm sure. I'm throwing an error that the maximum number of shader keywords has been exceeded. I assume this is because I have quite a few shader assets in my project with different naming conventions (wrong?) I'm having some problems getting some shaders to work properly, which I am again assuming is because of this problem (?). Am I to assume that the best course of action is to begin removing unused shaders in the hope that I'll get back under the limit? Thank-you for your time.
     
  2. meh11

    meh11

    Joined:
    Dec 1, 2009
    Posts:
    16
  3. negativecap

    negativecap

    Joined:
    Jan 27, 2013
    Posts:
    99
    Thanks for the reply, but the exact error (it throws them for different shaders so it's not just a skyshop problem, but here's an example):

    Maximum number (64) of shader keywords exceeded, keyword MARMO_BOX_PROJECTION_OFF will be ignored
    UnityEngine.Shader:EnableKeyword(String)
    mset.Sky:Apply(Renderer) (at Assets/Marmoset/Skyshop/Script/Sky.cs:116)
    mset.Sky:Apply() (at Assets/Marmoset/Skyshop/Script/Sky.cs:88)
    mset.Sky:OnDrawGizmos() (at Assets/Marmoset/Skyshop/Script/Sky.cs:398)
    UnityEditor.DockArea:OnGUI()
     
  4. meh11

    meh11

    Joined:
    Dec 1, 2009
    Posts:
    16
    Interesting. Maybe someone from UT can comment on this. Summon Aras.

    Also, I didn't see the keyword limit mentioned in either the documentation nor the unite talk from 2012. In fact, the documentation doesn't even mention Shader,EnableKeyword. Only Material.EnableKeyword.

    Aras put something online where he talks about the problem of having many keywords, but there is no solution for users. http://aras-p.info/texts/files/201301 Shader Pipeline in Unity.pdf

    Maybe you can compile the different shaders by hand instead of relying on keywords? Other than that, yeah, removing unused stuff sounds like your best bet.
     
  5. negativecap

    negativecap

    Joined:
    Jan 27, 2013
    Posts:
    99
    Hmm, weird that this doesn't come up more often, I'm only using a few (3) shader packages and this problem has rendered them unusable. Maybe I'm doing something else wrong...
     
  6. venain

    venain

    Joined:
    Aug 10, 2013
    Posts:
    6
    Just thought I'd chime in and say that this is affecting me as well. The combination of skyshop, sunshine!, and tc particles seems to be the cause in my case. I just can't run those three packages a scene without this happening:\
     
    ksam2 likes this.
  7. radimoto

    radimoto

    Joined:
    Aug 23, 2012
    Posts:
    257
    Looks like I'm also running into this issue now, experimenting with a few shader Assets and now receiving a lot of errors.

    Edit 1) Any chance we could get a response from Unity as to whether this limit will be increased in Unity 4.6 or 5.0? Sadly I'm now having to remove some of the best shader assets due to this issue that I planned on using.

    Edit 2) Fixed this issue by removing unused Shader Assets from my project. Not very happy considering they were Assets purchased before running into this issue. Unity adds in every shader with multi_compile regardless of whether they are actually used in the project or not. So it looks like unused shaders can end up going over the 64 limit and causing shaders that are being used to stop working. :(
     
    Last edited: Apr 19, 2014
  8. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,206
    Same here, using Marmoset Skyshop and AdvancedFoliageShaders.
    Any help?
     
  9. Chman

    Chman

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    721
    According to Aras, Unity 5 will very likely increase the limit to 128.
     
  10. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,206
    Nice, but this seems to be a bug for me. I had no problems with the same project on 4.5.3.
    An interesting part is, that when I re-opened the error-causing project in 4.5.3 again, it also causes these errors there.
    Fortunately I dublicated the whole project before upgrading. With the copied folder everything is fine in 4.5.3 again.
    Looks like 4.5.5 is "contaminating" a project....
     
  11. asemenov

    asemenov

    Joined:
    Jan 13, 2014
    Posts:
    11
    Same thing happened on 4.6.1. Using Marmoset RTPv3.1 ,AdvancedFoliageShaders and a lot of different shaders for postprocessing.
    I have added SunShaft Image effect to the camera and modified it. I have added SunShaftComposite shader new uniform:
    Code (CSharp):
    1. uniform float _depthThreshold
    After that I received an error in RTPv3.1:
    Maximum number (64) of shader keywords exceeded, keyword RTP_POM_SHADING_MED
    Maximum number (64) of shader keywords exceeded, keyword RTP_POM_SHADING_HI
    It still working but with default Terrain shader.

    I removed my uniform from SunShaftComposite shader and RTPv3.1 started working just fine, but still have an error in console.
    After I restarted Unity Editor, the error disappeared from console.

    Again I added new uniform to SunShaftComposite shader but with another name:
    Code (CSharp):
    1. uniform float _depthShaft
    And there is no error and everything works!

    Any ideas what caused it?
     
  12. Flailer

    Flailer

    Joined:
    Apr 1, 2014
    Posts:
    66
    You've just hit the Unity limit for the maximum amount of keywords.

    http://docs.unity3d.com/Manual/SL-MultipleProgramVariants.html

    As for your issue and fix asemenov, I can only assume that something else other than uniform was changed or activated, as the two are not related. Restarting Unity may have cleared something it had else that freed up those keywords.
     
    asemenov likes this.
  13. asemenov

    asemenov

    Joined:
    Jan 13, 2014
    Posts:
    11
    Thanks!
    Yeah, seems so.
    Before I changed SunShaft second time and Unity recompiled it, Unity Editor restart didn't help.
    It seems that Unity rearranged keywords somehow after first change of Sunshaft, and fixed it back after second change.
    I think that I almost reached keywords limit.
     
  14. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,942
    This is still an issue in 2016.

    Shaders that are not used should not be counted
     
    Rallix and ksam2 like this.
  15. lxpk

    lxpk

    Joined:
    Feb 3, 2009
    Posts:
    43
    ksam2 likes this.
  16. bome99

    bome99

    Joined:
    Sep 14, 2009
    Posts:
    105
    PLEASEEEE FIX!!
     
  17. SmartPolygon

    SmartPolygon

    Joined:
    Jan 26, 2017
    Posts:
    9
    Maximum number (256) of shader keywords exceeded..... Unity 2018. Why there is such a limit in the first place? This is ridiculous!
     
  18. AL_W

    AL_W

    Joined:
    Jan 25, 2016
    Posts:
    372
    Yea I ran into the same problem after installing light weight render pipeline and the High Def one from the package manager. uninstalled them.
     
  19. Ailrau

    Ailrau

    Joined:
    Feb 5, 2017
    Posts:
    21
    I have the same problem
     
  20. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,883
    You will find having a ton of unused materials will cause this, so remove all your unused materials. In addition most 3rd party shader assets tend to abuse this system a lot.

    SRP shouldn't have these problems because they do not use builtin shaders. So what is happening is you are probably going to have to redo all your materials and remove all your legacy shaders because they do not work on LW or HDRP anyway.
     
  21. jamesnw

    jamesnw

    Joined:
    Mar 23, 2013
    Posts:
    42
    I just ran into this as well. Upgrading from 2018.2.1 to 2018.2.2 (and updating to post processing v2) broke a lot of stuff - mostly asset store items. Now I have to start deleting a bunch of things to figure this out because the errors are completely useless to help me figure out which asset is causing it. :mad:
     
  22. Hexer_

    Hexer_

    Joined:
    Aug 25, 2016
    Posts:
    94
    So far, the only way to fix it is to delete shaders you're not using
     
unityunity