不同平台使用不同的着色器编译器来编译着色器程序,如下所述:
可以使用预定义的着色器宏来确定 Unity 正在使用哪个编译器。如果使用只有一个编译器才支持的 HLSL 语法,或者要解决编译器错误,您可能需要使用它。
You can configure various shader compiler settings using [SL-Programs](compilation directives).
着色器编译涉及几个步骤。首先,需要对着色器源代码进行预处理。默认情况下,Unity 使用平台编译器的预处理器来执行这一步;但是,您可以选择覆盖它,而使用 Unity 的缓存着色器预处理器来执行预处理。缓存着色器预处理器比平台编译器使用的默认预处理器最多快 25%。
缓存着色器预处理器缓存中间预处理数据,可以加速着色器导入和编译。编辑器重用这些缓存数据,只需要在内容更改时解析 include 文件。这使得编译同一着色器的多个变体更加高效。当项目中的着色器使用大量常见 include 文件时,启用缓存着色器预处理器具有最明显的效果。
请注意,缓存着色器预处理器是实验性的功能;仍处于积极开发阶段。您可以在 Unity 论坛上提供与此实验性功能相关的反馈。
您可以使用 Editor settings 窗口的 Shader Compilation 部分中的 Caching Shader Preprocessor (Experimental) 复选框来启用或者禁用缓存着色器预处理器。也可以在 C# 脚本中使用 EditorSettings.cachingShaderPreprocessor API 启用或禁用此功能。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.