maximum number (256) of shader keywords exceeded unity的报错解决方法

https://bitbucket.org/ArtIsDarkGames/shader-keywords-tool-unity3d/src/master/

https://eternity429.wordpress.com/2017/12/06/unity-shader-variant-system%E6%BD%9B%E8%97%8F%E9%9A%B1%E6%86%82/

其中,multi_compile 及 shader_feature都是定義keyword的功能,但其Build情況有所不同。

  • shader_feature會根據專案內是否有同時使用到此keyword啟動、非啟動的狀態生成對應Variant,適合無須在Runtime中變動、僅需要在Editor中設定好的功能。
  • multi_compile則會無論有無實際啟動keyword與否都會生成Variant。
    如果你的keyword功能會在Runtime中動態切換,那麼需使用此項。

-------------------------------------------------------------------------------------------------------------------------

一般大多數情況都是使用shader_feature足矣,你可以在編輯器中選中Shader來觀察該Shader會實際產生多少個Variant。

整个unity里面的shader的#pragma multi xxxxx_ON 关键字不能超过256个,给系统添加负担。
所以会报错:maximum number (256) of shader keywords exceeded unity。
做法是减少关键字的使用。

官方解答

好像是说在u3d 2019 beta4后面用window>package manager>安装LightWeight render-pipelines,就能解决toggleui不再产生关键字的问题?

下面提供一个优化工具。这个工具只是检查,而具体优化还是要靠手动,就是toggle的方式最多只能又256个。

使用方法:
重点!是先备份你的工作,然后把这个工具拷贝到你的项目 Assets文件夹。
从这个ShaderKeywordsTool文件目录拖拽 the ShaderKeywordsTool预制体到场景里。
把ShaderKeywordsTool.cs套到预制体上。
选择并点击这个绿色按钮 'Scan project for Shader Keywords’。
你点击这个‘Show Shader’按钮 ,它将给你在项目窗口做些shader。
你能够高亮显示shaders 统计keywords关键字 used between shaders
点击按钮‘More Info’ button 将显示发现的shader的关键字的路径。
删除没用的shaders。
重新扫描项目按钮 - 'Scan project for Shader Keywords’
点击这个红色按钮, 工具将自动搜索所有的 materials并且移除这些关键字 keywords that are now longer used 在项目里, 确保你已经备份了你的项目先。
在unity的Edit/Project Settings/Graphics 点击在‘Currently tracked’旁边的clear按钮。
重启项目。

How to use

IMPORTANT back up your work, this tool will alter your materials and is cannot be undone! copy the ShaderKeywordsTool folder to your Assets folder
drag the ShaderKeywordsTool prefab from the ShaderKeywordsTool folder onto the stage
select it and click the green button 'Scan project for Shader Keywords’
You can click on the ‘Show Shader’ and it will take you to the shader in the project window
You can highlight multiple shaders to count the keywords used between shaders
Clicking the ‘More Info’ button will show the path to the shader and keywords found
Delete unused shaders.
Rescan project - 'Scan project for Shader Keywords’
Click the red button, tool will automatically search all materials and remove the keywords that are now longer used in the project, make sure you have backed up your project
In unity goto Edit/Project Settings/Graphics and click on the clear button at the bottom near ‘Currently tracked’
Restart project
I have used this on a big project with around 3500 Materials and found it really useful. I hope you find this tool useful also

Taz Cebula - Art Is Dark

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值