- Home /
Can I make the self-illumin shader use a second UV channel for the illumination texture?
I've made a simple test model in 3ds Max consisting of two intersecting planes (exported from 3ds Max as an FBX file). Each plane uses a different material. The mesh has two UV channels: the first channel maps the textures and the second channel consists of an automatic flatten unwrap performed by 3ds Max for the illumination texture (for this example, I'm using an ambient occlusion texture as the illumination texture rather than a lightmap, but that doesn't affect the issue at hand).
Once imported into Unity, the object's two materials work properly if set to use a legacy lightmapped shader: the lightmap texture uses the second UV channel and is mapped to the object correctly. However, if the object's materials are set to use a self-illumination shader, the second UV channel is ignored and the illumination texture is mapped to the object using the first UV channel. The image below illustrates the problem.
The object on the left uses a self-illumination shader for its materials; the object on the right uses a legacy lightmapped shader for its materials.
The two versions of one of the object's materials are shown in the image below.
Is there any way I can make the self-illumin shader use the second UV channel when mapping the illumination texture to the model? If not, what are the disadvantages associated with using a legacy lightmapped shader? Should I just write my own version of the self-illumin shader that uses the second UV channel when applying the illumination texture?
Any thoughts on this would be appreciated!
Answer by TheCatProblem · Apr 02, 2013 at 09:56 PM
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):
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, 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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613095542im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can you still use the old legacy lightmapped shaders? 1 Answer
Unity 3 Problem: Legacy Lightmap Shaders don't seem to work. 1 Answer
Is it possible to make a Self Illum bumped shader using uv2 for an illum map 0 Answers
Emissive shaders not working 0 Answers
Is there a way to change the shader on all meshes without doing it manually one by one? 3 Answers