O'Reilly logo

Unity 2018 Shaders and Effects Cookbook by Alan Zucconi, John P. Doran

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required