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:
- 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:
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.