How to do it...

With our CgInclude file open, we can begin to enter the code that will get it working with our Surface Shaders. The following steps will get our CgInclude file ready for use within our Surface Shaders and allow us to continually add more code to it as we develop more shaders:

  1. We begin our CgInclude file with what is called a preprocessor directive. These are statements such as #pragma and #include. In this case, we want to define a new set of code that will be executed if our shader includes this file in its compiler directives. Enter the following code at the top of your CgInclude file:
#ifndef MY_CG_INCLUDE 
#define MY_CG_INCLUDE 
  1. We always need to make sure that we close #ifndef or #ifdef with #endif to close the definition ...

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.