What are Keywords and How do I utilise them?

Hi, pretty much as the title says

There are lines in some of the built in shaders like this :

SubProgram "gles " {
Keywords { "DIRECTIONAL" "LIGHTMAP_OFF" "DIRLIGHTMAP_OFF" "SHADOWS_OFF" }
"!!GLES

I’d like to know how this works and what they mean if possible, I’ve removed them completely and nothing happens, I’ve tried to access them via Shader.EnableKeyword(“SHADOWS_OFF”); but nothing seems to happen

Thanks in advance :slight_smile:

You can add custom keywords to a shader using the #pragma directive:

#pragma MY_KEYWORD

You can then add conditional code within the shader based on whether the keyword is defined, as:

#ifdef MY_KEYWORD
...
#endif

And you can change the keyword from script, using

Shader.EnableKeyword("MY_KEYWORD");
Shader.DisableKeyword("MY_KEYWORD");

If you have multiple keywords and need to generate versions of your shader for each permutation of those keywords, use multi_compile:

#pragma multi_compile KEYWORDA KEYWORDB

Note that, in your example, Shader.EnableKeyword(“SHADOWS_OFF”); does nothing because it is already enabled. You need to Disable SHADOWS_OFF (I often find double negatives in these sorts of things)