Unity 提供了若干文件供着色器程序用于引入预定义的变量和 helper 函数。这可以通过标准 #include
指令来完成,例如:
CGPROGRAM
// ...
#include"UnityCG.cginc"
// ...
ENDCG
Unity 中的着色器 include 文件采用 .cginc
扩展名,内置的着色器 include 文件包括:
HLSLSupport.cginc
-_(自动包含)_用于跨平台着色器编译的 helper 宏和定义。UnityShaderVariables.cginc
-_(自动包含)_常用的全局变量。UnityCG.cginc
- 常用的 helper 函数。AutoLight.cginc
- 光照和阴影功能,例如表面着色器在内部使用此文件。Lighting.cginc
- 标准表面着色器光照模型;当您编写表面着色器时会自动包含。TerrainEngine.cginc
- 地形和植被着色器的 helper 函数。如果您要查看任何 helper 代码具体执行的操作,可在 Unity 应用程序中找到这些文件(Windows 上位于 {unity 安装路径}/Data/CGIncludes/UnityCG.cginc__,Mac 上位于 /Applications/Unity/Unity.app/Contents/CGIncludes/UnityCG.cginc__)。
编译 CGPROGRAM 着色器时会自动包含此文件(但不会对 HLSLPROGRAM 着色器包含此文件)。此文件声明各种预处理器宏以帮助进行多平台着色器开发。
编译 CGPROGRAM 着色器时会自动包含此文件(但不会对 HLSLPROGRAM 着色器包含此文件)。此文件声明着色器中常用的各种内置全局变量。
Unity 着色器中通常会包含此文件。此文件声明大量内置 helper 函数和数据结构。
appdata_base
:顶点着色器输入,包含位置、法线和一个纹理坐标。appdata_tan
:顶点着色器输入,包含位置、法线、切线和一个纹理坐标。appdata_full
:顶点着色器输入,包含位置、法线、切线、顶点颜色和两个纹理坐标。appdata_img
: 顶点着色器输入,包含位置和一个纹理坐标。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.