How to specify my CGIncludes directories?

I have my own folder with all the custom .cginc files.
How can I set up Unity to scan this folder for the required cginc files when the shader compiled?
E.g., I have:

  • Assets/MyCgLib folder
  • files in this folder: my1.cginc, my2.cginc, my3.cginc …
  • The following line in my shader:

#include "my2.cginc"

For now, Unity looks for that file only in 2 folders:

  1. ./ (current directory)
  2. Unity/Editor/Data/CGIncludes/ (default directory)

How can I add some directories in this list and tell Unity to scan them in this order?

  1. ./ (current directory)
  2. Assets/MyCgLib (my folder)
  3. Unity/Editor/Data/CGIncludes/ (default directory)

Of course, I’ve got more then one “my” folder. And of course, cginc files themselves can also contain include statements.

I don’t know how to set a default directory to scan for include files, but they don’t have to be contained in one of the folders you mention - you can place them anywhere in your project and include an absolute/relative directory path in the #include directive itself:

#include "./relative/path/to/yourshader.cginc"
#include "Assets/absolute/path/to/your/shader.cginc"

I don’t think it can be changed but I found all the search directories used in 5.4 via Process Monitor:

  1. The root of the project folder. (OUTSIDE the Assets folder)
  2. The same folder as the shader file.
  3. Unity\Editor\Data\CGIncludes.

(ordered from first to last)

If you want to keep them in the assets folder you could use symlinks to mirror the individual files into the search path.

If you sell stuff on the asset store PLEASE don’t use absolute paths. You force people to use your folder layout if you do that, that makes project setup a headache.

If you put your .cginc files right in the project folder (beside the “Assets” folder) you won’t need to specify any paths, similar to how UnityCG.cginc works.

Also you can override UnityCG.cginc by placing a file with the same name beside your “Assets” folder.