Adding support for GPU instancing for legacy shaders?

I’m using legacy Diffuse shader to achieve a very specific look in my game that is just not possible (or rather I’d have to mess with sliders and possibly shader code and it still wouldn’t be “it”) with the Standard shader, as it is meant for more… realistic rendering than what I’m trying to achieve (early 3D game look).

Any idea how can I put instancing support to it? The “unlit” example in the docs wasn’t very enlightening (pun intended) and it’s not a good candidate for copy-paste programming either as I don’t know which parts I need to copy over and where.

I’m using an Instanced Diffuse Shader. It’s a great style.

Note that Legacy → Diffuse is essentially a Surface Shader using the “Lambert” lighting scheme. Using that knowledge we can recreate the Diffuse Shader and add instancing.

Right click in your project window, go to Create → Standard Surface Shader (Instanced).

Now you can tweak the Surface Shader to be diffuse by following this example here:

I’ll help you as well.

In the shader change the “#pragma surface surf Standard fullforwardshadows addshadow” to “#pragma surface surf Lambert fullforwardshadows addshadow”

Now change the “surf” function to

	void surf (Input IN, inout SurfaceOutput o) {
		fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * UNITY_ACCESS_INSTANCED_PROP(_Color);
		o.Albedo = c.rgb;
		o.Alpha = c.a;
	}

And delete all the references to “Metallic” and “Glossiness”. You can delete the MainTex as well if you aren’t using texturing.

BOOM! You have an instanced diffuse shader!