Unity 3 shader conversion

Hi Community,

We’re currently in the process of moving from Unity 2 to Unity 3 and have come across a bit of trouble regarding the new surface shaders. Quite a few of our pixel-lit shaders uses multiple passes with different alpha tests, blend modes, zwrites, ztests, culling and so on for every pass. What Unity 3 does is to comment out the entire shader telling us to rewrite them using surface shaders. After reading through the documentation, a few tutorials and a few forum posts we can’t really see how our shaders could be transformed into surface shaders, as these seems very limiting.

How can we write a surface shader that for instance uses one pass for front facing triangles and one for back facing triangles and uses different blend modes for the two passes?

As we only use one directional light for the game and don’t use shadows we were thinking of just setting light data in the material, however we feel that it was more convenient the way it worked in Unity 2. As far as we understand it the surface shaders are more or less code generators for what was in Unity 2, so the old build blocks should be there somewhere. Is there a way to use the old pixel-lit shaders, or to access the light data, without having Unity 3 commenting them out?

Your best bet is not to upgrade to v3.x until you’ve finished your project and then start fresh. You can also check out ShaderFusion ($100) and the Shader Editor (free) which might make writing complex shaders to match your older ones easier.

As our game is being live developed it is unlikely to finish in that sense, thus, not upgrading to start fresh later is not an option for us. I looked through the tutorials and documentations of ShaderFusion and Shader Editor and neither allowed for the kind of features we’re looking for as far as I could see. They both looked really awesome for simpler shaders however.

I managed to find how to write multipass shaders using pixel lights in Unity 3. However, _ModelLightColor0 seems to have been removed as a build-in value, and I can’t seem to find the Unity3 equivalent of it.

If you haven’t already, check out the source code generated in a surface shader compiled with #pragma debug. This should give you some insight into Unity’s lighting framework.

Thanks, I’d missed the #pragma debug. I managed to rewrite our shaders now.