Procedurally Enabling and Disabling the fog mode in an iOS shader

We have a texture atlas with a diffuse shader that enables fog ( fixed pipeline GL ).

Depending on the iOS device we’re running on, we’d like to enable and disable the fog… basically switching between:Fog { Mode Off } and whatever the render settings are set to.
I’d like to know what our options are for enabling and disabling the fog. You can’t just toggle it off in Render Settings because there is still a performance penalty in the shader from doing so.

So I guess we either need to change the shader on the material? or swap the material on all the objects that would use it ( which would be a pain ). However, I’m wondering if we change the shader on the material, is that not going to create another instance of the material that they objects won’t use anyway?

Thanks in advance

You’ve already figured out what you need to do. It will break at least some batching, but using an atlas is still an optimization.

I’m not sure what you’re getting at. :face_with_spiral_eyes:

http://unity3d.com/support/documentation/ScriptReference/Material-shader.html

Well I mean… there’s no way to change the shader for every renderer that uses that material without looping through all the renderers that use that material is there?

Doing this:

renderer.material.shader = differentShader

will only change the shader on that one renderer as the material will get instanced…

But… I guess I can modify renderer.sharedMaterial which will modify ALL objects using this material?

Yeah, but be careful not to run that code in the Editor improperly. I don’t think that makes much sense, though. A single script with a reference to the Material seems to me like what you’d want to work with. Same effect, you’ll be working with the same Material reference, either way, but you’ll bypass working with any one Renderer.