- Home /
How to make a conditional #pragma surface noforwardadd
Hi there,
I'd like to have this in my shader:
#if SHADER_API_MOBILE
#pragma surface surf Lambert noforwardadd
#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
Not definitively answered, but the question has been asked before: http://answers.unity3d.com/questions/548313/shaderlab-preprocessor-ignoring-if-endif-when-prag.html
Thanks tanoshimi! And sorry for the duplicate! $$anonymous$$aybe there's something special about #pragma surface and noforwardadd that can allow for this type of condition, even without the use of #if preprocs? $$anonymous$$aybe just making sure there is only ever one light on mobile would get most of the benefits of noforwardadd?
Hmm... $$anonymous$$aybe it's possible to somehow duplicate the entire CGPROGRA$$anonymous$$, one for SHADER_API_$$anonymous$$OBILE and one otherwise. Then only compile one of them, along with their #pragma, based on something like SHADER_API_$$anonymous$$OBILE? I feel like this method might end up negating the benefit of the smaller shader generated by noforwardadd...
Answer by allenwp · Jul 01, 2016 at 08:31 PM
The best answer I've found at this point is the following. It's not perfect, since I believe this results in a larger shader, but it answers the question: