I'd like to have this in my shader:

#if SHADER_API_MOBILE
#else
#pragma surface surf Lambert
#endif


But this tries to compile both #pragma surface and ignores the second one instead of respecting the #if condition.

Anyone know how to add "noforwardadd" to a shader, but only when it's compiled for mobile platforms?

Thanks!

Allen

Preprocessor macros don't work on pragmas, because they are parsed before any preprocessing happens. What you can do instead is to make two identical subshaders, the top one without noforwardadd and the bottom one with. If you assign different LOD thresholds to those subshaders, you can then choose between them by making mobile builds use a lower LOD value:

SubShader {
LOD 300

CGPROGRAM
#pragma surface surf Lambert
...
ENDCG
}
LOD 100

CGPROGRAM

#if (UNITY_IOS || UNITY_ANDROID)