How it works...

When using shaders, we can include other sets of code using the #include preprocessor directive. This tells Unity that we want to let the current shader use the code from within the included file in the shader; this is the reason why these files are called CgInclude files. We are including snippets of Cg code using the #include directive.

Once we have declared the #include directive and Unity is able to find the file in the project, Unity will then look for code snippets that have been defined. This is where we start to use the #ifndef and #endif directives. When we declare the #ifndef directive, we are simply saying "if not defined, define something with a name." In this recipe's case, we said we wanted to #define MY_CG_INCLUDE ...

Get Unity 2018 Shaders and Effects Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.