目录索引
译文
指令“.cginc”(Cg include)包含几个文件,可用于在着色器中引入预定义变量和辅助函数。
如果我们检查 USB_simple_color 着色器,我们可以发现以下几个在 pass 中声明过的指令:
- UNITY_FOG_COORDS(texcoordindex).
- UnityObjectToClipPos(inputVertex) .
- TRANSFORM_TEX(tex, name).
- UNITY_TRANSFER_FOG(outputStruct, clipSpacePos).
- UNITY_APPLY_FOG(inputCoords, colorOutput).
这些函数都属于“UnityCG.cginc”。如果删除这条指令,着色器就无法编译,因为这些函数没有引用。
我们还可以在 UnityCG.cginc 中找到另一个预定义函数 UNITY_PI,它的值为 3.14159265359f。UNITY_PI 并没有包含在我们的默认着色器中,因为它仅在特定情况下使用(例如计算三角函数或球体时)。如果我们想查看 .cginc 文件中的变量和函数,可以按照以下路径查找:
Windows: {unity install path}/Data/CGIncludes/UnityCG.cginc
Mac: /Applications/Unity/Unity.app/Contents/CGIncludes/UnityCG.cginc
除了 Unity 默认的指令外,我们也可以通过使用扩展名“.cginc”来创建自定义指令,为此,我们只需创建一个以“.cginc”为扩展名的新文档,然后编写自定义变量和函数即可。在本书的后续章节中,我们将使用一些自定义指令来处理光照、阴影和体积。
原文对照
The directive “.cginc” (Cg include) contains several files that can be used in our shader to bring in predefined variables and auxiliary functions.
If we look at our USB_simple_color shader, we will find the following directives that have been declared within the pass:
- UNITY_FOG_COORDS(texcoordindex).
- UnityObjectToClipPos(inputVertex) .
- TRANSFORM_TEX(tex, name).
- UNITY_TRANSFER_FOG(outputStruct, clipSpacePos).
- UNITY_APPLY_FOG(inputCoords, colorOutput).
All these functions belong to “UnityCG.cginc“. If we remove this directive, our shader will not be able to compile because it will not have its reference.
Another defined function that we can find in UnityCG.cginc is UNITY_PI, which equals 3.14159265359f. The latter is not included in our default shader because it is used only in specific cases (e.g. when calculating a triangle or Sphere). In case we want to review the variables and functions that come in our .cginc files, we can follow the following path:
Windows: {unity install path}/Data/CGIncludes/UnityCG.cginc
Mac: /Applications/Unity/Unity.app/Contents/CGIncludes/UnityCG.cginc
In addition to the Unity default directives, we can create our directives using the extension “.cginc”, to do this we must simply create a new document, save it with that extension and then start defining our variables and functions. Later in this book, we will start using some custom directives to work with lighting, shadows, and volumes.
暂无评论内容