Unity 中的每个着色器都包含一个子着色器列表。当 Unity 必须显示网格时,它将找到要使用的着色器,并选择在用户的显卡上运行的第一个子着色器。
Subshader { [Tags] [CommonState] Passdef [Passdef ...]}
将子着色器定义为可选标签、通用状态和通道定义列表。
子着色器定义渲染通道的列表,并且可选择性地设置所有通道共同的任意状态。此外,还可以设置子着色器专用的标签。
当 Unity 选择要用于渲染的子着色器时,它会为每个定义的通道 (Pass) 渲染一次对象(并且数量可能由于光交互而增加)。由于对象的每次渲染成本都很高,因此应以尽可能少的通道数量定义着色器。当然,有时在某些图形硬件上,所需的效果不能在单个通道中完成;那么您别无选择,只能使用多个通道。
每个通道定义可以是常规 Pass、Use Pass 或 Grab Pass。
Pass 定义中允许的任何语句也可能出现在子 Subshader 代码块中。这将使所有通道都使用这一“共享”状态。
// ...
SubShader {
Pass {
Lighting Off
SetTexture [_MainTex] {}
}
}
// ...
以上子着色器定义了单个通道 (Pass),用于关闭光照并且只显示一个名为 _MainTex 的纹理网格。
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.