Using replacement shader at runtime?

My dilemma:

When building levels, I like all my scene assets to use a surface shader, so I can preview within the Editor how the lighting will look like after setting up all my lights, without having to bake all lightmaps to see how the lights are affecting the objects.

But I am working on an mobile game, so using surface shaders is definitively not the best for speed. Before making a build, I assign a cheaper, vertex lit shader to the scene objects, and if I haven’t rendered any lightmaps yet, the scene looks like it’s being lit by only one light, my main directional light.

Having to manually switch shaders everytime I change the lighting setup or make changes to the scene is a time waster and a pain :slight_smile:

What I would like to do:

I want tell Unity to use surface shaders when the game is being run in the editor, and use vertex lit shaders when it’s running on a mobile platform. I could do that using replacement shaders, or writing the logic directly within a shader (if isEditor use surface else use vertex lit).

Which would be the better approach, and is there any other way of doing this? Also, is using replacement shaders at runtime have an impact on performance?

Thanks for your time!


You can use a variety of preprocessor directives to achieve what you want…

    // Change your material's shader here when it's being run in the editor

   // Change your material' shader here when being run on iOS

   // Change your material' shader here when being run on Android