Best Practice For Shader Complexity + IOS

Quick question for all you shader wizzards out there, target platform is IOS.

Let’s say I want 3 different things for a shader:

1. Unlit + Lightmap Support * Color.
2. Unlit + Lightmap Support.
3. Unlit * Color (no lightmap support).

Now I can write the shader with a bunch of #ifdef regions, branching to all 3 different outcomes depending on settings I choose from script. It keeps all the code in 1 place and makes it easier for organization.

Or I could write 3 different versions of the same shader. I’m not a big fan because I don’t like code duplication, and it also makes it harder to organize everything and keep track of all the changes.

The question is, how much of an impact does a shader with too many branches have on the performance in an IOS game? If anyone has some “PRO” pointers for me I would really appreciate it, as always :slight_smile:

Thanks for your time guys,

shaders are compiling in editor and goes to build version in compiled mode. i don’t know a way to recompile it an runtime. so, in anyway your task should output 3 different shaders. and that’s why is not so important how it will be built.

#ifdef’ is pre-compile operator, so i’m not sure you can do something with it at runtime.

point to another way - using, for example, shader 1 instead of shader 1+2 can be more efficient caused by unity batching.

tell if i understood you wrong.