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

Shader Control - manages shader keywords and variants - helps reducing compilation time and build si

Discussion in 'Assets and Asset Store' started by Kronnect, Nov 22, 2016.

  1. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    Yep. It’s a normal upgrade, it’s version 4 though. So it’s the same asset but evolved significantly..
     
    recon0303 likes this.
  2. DropNodes

    DropNodes

    Joined:
    Jun 11, 2019
    Posts:
    39
    hi @Thrawn75 sending here too so may other benefit, I saw in another thread that you added an option to convert global keywords to local, could you share how to do it because that 256 word limit is :S
     
  3. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    That change is easy. Shader Control lists all keywords found and the shaders they're using. If the keyword is of type "shader_feature" it will display a button to do the switch. So you just go through those keywords and click that button. The change just replaces the "shader_feature" to "shader_feature_local" in the keyword declaration.
     
  4. DropNodes

    DropNodes

    Joined:
    Jun 11, 2019
    Posts:
    39
    thank you for the reply, a little bit of help again, this is what I see:

    https://ibb.co/Ms95JVc

    edit: found it, Convert to Local Keyword when I sord by keyword.

    btw as you see it says 231 global words, and still throws me the error, weird system
     
    Last edited: Sep 27, 2019
    Crossway likes this.
  5. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    The global keyword count found in the "Project View" refers to the keywords found in your project files. That count does not include keywords used by Unity internally (so even if the limit is 256, in practice it's much lower).
    Check the "Build View" for the real number of keywords used during compilation.
     
  6. rmon222

    rmon222

    Joined:
    Oct 24, 2018
    Posts:
    76
    How does Shader Control work with asset bundles? Does the global keyword count include shaders in asset bundles? Thanks

    Also, on 2019.3.0b8, I do a quick build but nothing happens in the shader control window. Previously, the shader control window would detect the build and populate the window.
     
  7. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    Global keyword count is for the build (shaders should be included in both the build and the asset bundles as specified here).
    If no shaders are listed in the Build View, try deleting the BuiltShaders file under ShaderControl/Editor/Resources folder and perform a "Quick Build" again from the Build View.
    Tested with Unity 2019.3.0b9 and Build View shows output as expected:
     
  8. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,739
    hi
    I'm using Shader Control and I find "standard" shaders on it, but no way to disable them. Is there a way to remove all standard shaders from the build? I don't use any since I use my own mobile shaders.
    Also, a lot of times, the keywords are empty. You expand something like the Diffuse shader and see a whole bunch of "include" checkbox with no names on the keyword. What does that mean?
     
  9. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    The Standard Shader is an exception and will always be included in the build however you can exclude its keywords reducing the number of variants. Find it in the Build View and uncheck "Include" for any of its keywords. Those variants won't be included.

    Regarding the diffuse shader with empty keywords, that shouldn't happen. If it's the Legacy/Diffuse shader, the Build View should look like this:


    Try clicking "Quick Build" and doing a build again, then check the output in the Build View. If problem persists, could you send me a copy of that diffuse shader or is it the legacy shader? Also which Unity version are you using?
     
  10. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,739
    ok, Nature/Terrain/Diffuse you don't see a ton of empty lines checkboxes at the end?
    or Hidden/TerrainEngine/Splatmap/Diffuse-Base
     
  11. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    No, this is what you should see:


    It could be something related to a specific Unity version. Which one are you using?
     
  12. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,739
    I'm using 2019.3beta10. Probably you should give it a go before it goes out of beta because that will be in one to two weeks. So you know whether you have to change things or Unity messed up stuff and they should fix it before full release.
     
  13. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    You were right - it was an API change which was causing that issue. An update has been submitted to the Asset Store. Thanks for the heads up!
     
  14. peeka

    peeka

    Joined:
    Dec 3, 2014
    Posts:
    113
    Hello, Just started using shader control looks great so far, quick feedback I think can save a lot of time for the user and maybe it's already in the works.

    The List material button makes my list very long and time-consuming to scroll, there is no way that I can find to collapse the list by Keyword, it's the most time-consuming part of my usage so far, and seem like also the easiest to implement since the menu already supports collapse by the shader.
     
  15. peeka

    peeka

    Joined:
    Dec 3, 2014
    Posts:
    113
    Run into an issue, I unchecked all the keyword for one shader, now it won't show up on the search anymore, and therefore I can't restore it.
     
  16. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    Build or Project View?
     
  17. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    Make sure the filters are not excluding it, like keyword count (set it to 0 to show shaders without no keywords active):
     
  18. peeka

    peeka

    Joined:
    Dec 3, 2014
    Posts:
    113
    it's in project view, I uncheck all boxes of a shader, and hit save, and then hit Scan project folder, the shader does not show up in the list anymore. thank god for the backup.

    UPDATE: it's working now, it's because Force scan all shaders got unchecked for some reason.
     
    Last edited: Nov 29, 2019
  19. peeka

    peeka

    Joined:
    Dec 3, 2014
    Posts:
    113
    one minor issue, Build View uses shader name and Project view uses shader file name, some shader their name and file name don't match so Show in project view won't work. would be nice if both suppot display file name or shader name.
     
  20. Skjalg

    Skjalg

    Joined:
    May 25, 2009
    Posts:
    208
    I updated shadercontrol and now unity crashes when compiling shaders. I reverted the shadercontrol upgrade and now it builds again.
     
  21. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    Hello,
    Which Unity version are you using now? And which Shader Control version did you use before the update?
    Thanks
     
  22. DrInternet

    DrInternet

    Joined:
    Apr 6, 2014
    Posts:
    103
    Hello again,

    it's great to see SC constantly being updated with more features and bugfixes. If you take a feature requests for future iterations, I think it would be swell to see following improvements:

    1) list candidates for local keywords. SC would go through all scripts in project and see what keywords are used by EnableShaderKeyword() and Shader.EnableKeyword(). Keywords that aren't globally enabled would make a good candidate for a local one.

    2) clean materials from unused keywords++. Like "clean all materials" button but instead of only cleaning disabled keywords, it would go through all materials and clean any keyword that is not present in any project shader. This would be a huge timesaver as an asset creators often upload materials with keywords from various shaders they worked with or and older version that used different or more keywords. So I have to clean those "manually", but then there is an asset update, so redundant keywords are back, so I have to clean them again and so on and so on
     
    Kronnect likes this.
  23. iceb_

    iceb_

    Joined:
    Nov 10, 2015
    Posts:
    95
    I just clicked the Convert To Local Keyword button, I'm on 2019.3.0f6, and it did a large reimport of a lot of meshes for some reason. Is this normal?
     
    Last edited: Apr 5, 2020
  24. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    It invokes an AssetDatabase.Refresh which should affect only the modified files:
    https://docs.unity3d.com/ScriptReference/AssetDatabase.Refresh.html
    It’s strange your meshes are reimported. May be this is related? https://issuetracker.unity3d.com/is...-setting-can-drastically-increase-build-times
     
  25. iceb_

    iceb_

    Joined:
    Nov 10, 2015
    Posts:
    95
    thanks! I'll check it out and leave it untoggled for now!
     
  26. FloofyTsuna

    FloofyTsuna

    Joined:
    Dec 21, 2017
    Posts:
    2
    Can it clean up materials by removing keywords not used by any shader in the project? Also an option to clean all keywords from materials currently using the error shader would be nice.
     
    Kronnect likes this.
  27. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    Hi,

    Latest beta includes a new "Sort by Material" option which lists all materials using keywords.
    And this option lets you locate the material, remove that keyword from that material OR remove that keyword from ALL materials in project:

     
    Exeneva likes this.
  28. BigRookGames

    BigRookGames

    Joined:
    Nov 24, 2014
    Posts:
    329
    I am having a bit of trouble managing the shaders in my project. I am using HDRP which doesn't help, but after I execute Scan Project Folders with Force scan all shaders the Used Keywords is always "331 of 333 (99%)"

    upload_2020-11-22_11-3-24.png

    I continue to remove shaders and keywords followed by restarting the Editor but still seems to be above the limit. Correct me if I am wrong, but I'm assuming that the shaders that are ignored by unity are not being counted and that I am just over the shader limit in an amount more than I have removed.

    I have tried converting all of the global keywords to local that it shows, and I think that helped but it's hard to tell because I keep getting the editor errors about the max shader count reached.

    Is there any way to look at a list of keywords in the project that excludes all of the ones that are required by Unity?

    Is there an easier way to determine how many keywords I must disable or remove? This has been a pain point in my project, every time I add any type of plugin or VFX. Any help would be greatly appreciated here.
     
  29. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    The total keywords used in the build should be shown in the Build View. Project View only shows a partial count because some keywords are injected by Unity at build time.
     
  30. BigRookGames

    BigRookGames

    Joined:
    Nov 24, 2014
    Posts:
    329
    Okay, thanks. I haven't built in a long time because of how long it takes. I will have it build overnight and use that.
    Much appreciated.
     
    Neto_Kokku likes this.
  31. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    Use the Build View and click the button "Quick Build". This will discard shader compilation only the next build you do but Shader Control will be able to gather info about those shaders. Then the stats in the Build View should be accurate summary of how many keywords and variants are being included in the build.
     
    BigRookGames likes this.
  32. BigRookGames

    BigRookGames

    Joined:
    Nov 24, 2014
    Posts:
    329
    Thank you for your help. I was able to build and the result was:
    upload_2020-11-23_5-30-27.png
    I still see the error message about max shaders being exceeded:
    upload_2020-11-23_5-27-55.png
    Is the build view results strictly showing keywords included in the build and not the project entirely?
     

    Attached Files:

    Crossway likes this.
  33. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    Yes, the Build View gathers info from the compilation stage itself so it will report only keywords that are used in the build.
    In this case, there're more keywords in the project than in the final build and it surpasses the 256 limit.
    The only way to remove that error is to reduce keywords in the Project itself.

    This option, in the Project View, can help you quickly identify which shaders are not used during the last build so you can remove them (please make sure you have a backup before using this kind of operations):

     
    BigRookGames likes this.
  34. catfink

    catfink

    Joined:
    May 23, 2015
    Posts:
    175
    I need a little help understanding what is going on. If I build my project with all shaders enabled (nothing disabled through Shader Control) then I will get highlighted about 7 keywords that will be ignored due to me being over the 256 limit. If I then go in via shader control and uncheck (disable) some shaders and build I then can get hundreds of errors about shader keywords being ignored.

    I'm missing what the correlation here is between disabling shaders and somehow then ending up with more keywords ignored in the build. Can someone enlighten me as to what is going on here as it's driving me crazy as everything I do seems to make it worse rather than better.
     
  35. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    When you disable a keyword from the Project Panel, Shader Control removes the declaration of that shader keyword in the source file of the shader. Nothing else suggests that behaviour, it's really strange what you say indeed.
    Are you sure you're building the same content (scenes) in both cases?
    Feel free to contact us by email with some screenshots and details about your project.
     
  36. catfink

    catfink

    Joined:
    May 23, 2015
    Posts:
    175
    Maybe my process is wrong. I click the button to run a build analysis and then do a build. That gets me a list of shaders. I then go through those and untick things I can live without - which although I know will cause material problems I can clear those up later and assign new shaders. After unticking stuff I close the shader control window and run a new build (there is no save button so I assume it is auto saving my selections). The build runs and I get the same errors (or more). There are only seven shader keywords it is failing on, I freed up over 7 shader keywords according to the unique keywords list but I just built again and the same errors for ignored keywords are coming out.

    Can you see anything wrong in my process?
     
  37. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    When you press the Quick Button, Shader Control will discard any shader compilation during the next build so it finishes quickly. Since no shader is compiled it gives no errors.
    When you do the normal build is when you get those errors.
    The actual keyword count is listed in the Build View which includes everything that was included in the compilation even hidden shaders and keywords. The Project View only shows shaders and keywords available in your project and this amount is normally less than the figure in the Build View.
    In any case your best bet is to continue finding shaders or keywords you know you don’t use and disable or delete them completely.
    Do a restart of Unity after some changes to ensure the keyword cache is cleared.
     
  38. catfink

    catfink

    Joined:
    May 23, 2015
    Posts:
    175
    ok, I think the restart of unity after changes may be what is throwing me off here as I'm not doing that - thanks
     
  39. JeffG

    JeffG

    Joined:
    Oct 21, 2013
    Posts:
    73
    So...After restarting Unity. Doing a build.

    Shader Control reports.
    Total Shaders: 203 Shaders using Keywords: 203

    Total Unique Keywords: 180

    and yet still getting the Maximum number (256) of shader global keywords exceeded and shaders not working properly

    and Ideas/Guidance? or was just moving to HDRP the biggest mistake and waste of time?
     
    Crossway likes this.
  40. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    The stats in the Build View are the actual shaders/keywords used by that build but you may have some materials or additional shaders not included in the build due to stripping that adds extra keywords in Unity Editor.

    Make sure you have latest version (6.3.1 as of today) and after making a Quick Build, take a look at Project View tab. It will tell you the amount of keywords found in files of your project + additional keywords added by Unity during the build itself.

    A HDRP project can take between 90-100 global keywords without adding any other asset so that leaves you with about 155 global keywords for your project. Keep removing shaders and keywords OR converting global keywords to local from assets until you get below the 256 max.

    Shader Control will only suggest converting global shader features to local (but not multi_compile keywords) to avoid breaking any asset that can be enabling those multi_compile keywords with the Shader.EnableKeyword API. But you can use shader control filters to find all global keywords of type Multi_Compile and locate/remove those shaders if you know they won't be used.

    Also, HDRP native shaders are read-only files so any change to them will produce Unity reverting those changes upon restart.
     
    Last edited: Dec 1, 2020
  41. JeffG

    JeffG

    Joined:
    Oct 21, 2013
    Posts:
    73
    What happens if you try to exclude these? Do they also revert back and end up being included?
     
  42. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    Yes. If you remove a shader (ie. the Lit shader), Unity will detect this and try to restore the file.
     
  43. JeffG

    JeffG

    Joined:
    Oct 21, 2013
    Posts:
    73
    Perfect. Thanks, that for sure is one of my issues. (I tried getting rid of a few of those to get my nubers down)
     
  44. JeffG

    JeffG

    Joined:
    Oct 21, 2013
    Posts:
    73
    OK...Thanks again

    I did the Quick Build, went to Project view

    An then selected the show shaders not in build. Then started deleting shaders I would never use.

    Got my count down. Thanks Again
     
  45. macish

    macish

    Joined:
    Oct 29, 2018
    Posts:
    55
    @Kronnect when importing into Unity 2019.4.18f i get this error

    Assets\ShaderControl\Editor\ShaderDebugBuildProcessor.cs(96,31): error CS0266: Cannot implicitly convert type 'UnityEditor.Rendering.ShaderType' to 'ShaderType'. An explicit conversion exists (are you missing a cast?)
     
  46. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    Check your inbox.
     
  47. macish

    macish

    Joined:
    Oct 29, 2018
    Posts:
    55
    thnx that was super fast support, wow!
     
    Kronnect likes this.
  48. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,081
    Hi

    Can not find info.
    Do ShaderControl support URP?
     
  49. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    Yes, it also can handle ShaderGraph keywords.
     
    JesOb likes this.
  50. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    506
    I'm pretty sure I disabled "SC_DOF_MASK_ON" keyword from project but now I get a message that says

    Maximum number (256) of shader global keywords exceeded, keyword SC_DOF_MASK_ON will be ignored.
    You will have to delete some shaders or make them use less keywords.

    Why it ignored a keyword I disabled before? :eek: