As it turns out, it's extremely easy to modify the standard self-illumin diffuse shader so it uses the second UV channel when applying the illumination texture.
Here's the code for the modified shader (the source code for Unity's built-in shaders is available from the [Unity download archive][1]):
Shader "Custom/Self-Illumin Diffuse" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
_Illum ("Illumin (A)", 2D) = "white" {}
_EmissionLM ("Emission (Lightmapper)", Float) = 0
}
SubShader {
Tags { "RenderType" = "Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
sampler2D _Illum;
fixed4 _Color;
struct Input {
float2 uv_MainTex;
float2 uv2_Illum; // Originally float2 uv_Illum;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
fixed4 c = tex * _Color;
o.Albedo = c.rgb;
o.Emission = c.rgb * UNITY_SAMPLE_1CHANNEL(_Illum, IN.uv2_Illum);
o.Alpha = c.a;
}
ENDCG
}
FallBack "Legacy Shaders/Lightmapped/Diffuse"
}
It was only necessary to change "uv_Illum" to "uv2_Illum" everywhere the former appeared (as documented on the [Writing Surface Shaders reference page][2], a texture name that starts with "uv2" instead of "uv" will use the second UV channel).
Hopefully this information will be of use to someone else in the future.
[1]: http://unity3d.com/unity/download/archive
[2]: http://docs.unity3d.com/Documentation/Components/SL-SurfaceShaders.html
↧