system
November 3, 2010, 2:34pm
1
I'm writing a surface shader that have a base texture, a reflection cube map, a Normal map
and a Light map.
When I use all four maps inside surface function, I get the error:
Shader error in 'Reflective/Diffuseprb': Too many texture interpolators would be used for ForwardBase pass at line 21
Here is the code:
Shader "Reflective/Diffuseprb" {
Properties {
_Color ("Main Color", Color) = (1, 1, 1, 1)
_ReflectColor ("Reflection Color", Color) = (1, 1, 1, 1)
_MainTex ("Base (RGB) RefStrength (A)", 2D) = "white" {}
_Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect }
_BumpMap ("Normalmap", 2D) = "bump" {}
_LightMap ("Lightmap (RGB)", 2D) = "black" {}
}
SubShader {
Tags { "Queue"="Transparent" "RenderType"="Transparent"}
LOD 300
Cull Off
Lighting On
AlphaTest Greater 0.5
CGPROGRAM
// #pragma surface surf Lambert alpha
// #pragma vertex vert_img
#pragma surface surf Lambert alpha
#pragma debug
sampler2D _MainTex;
samplerCUBE _Cube;
sampler2D _BumpMap;
sampler2D _LightMap;
float4 _Color;
float4 _ReflectColor;
struct Input {
float2 uv_MainTex;
float3 worldRefl;
float2 uv_BumpMap;
float2 uv_LightMap;
INTERNAL_DATA
};
void surf (Input IN, inout SurfaceOutput o) {
half4 tex = tex2D(_MainTex, IN.uv_MainTex);
half4 c = tex * _Color;
o.Albedo = c.rgb;
half4 reflcol = texCUBE (_Cube, IN.worldRefl) * _ReflectColor;
c = tex2D(_LightMap, IN.uv_LightMap);
o.Emission = (reflcol.rgb * _ReflectColor.a) + c.rgb;
o.Alpha = _Color.a + reflcol.a * _ReflectColor.a;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)) * 2.0;
}
ENDCG
}
Fallback "Transparent/VertexLit"
}
Please, help me
Thanks
The UVs on your Input are the UV coordinates for each vertex stored with the mesh and Unity only takes in 2 sets of them so you can have at most two of them. See the docs on CG program inputs .
Because of this, you will have to share, but if the mapping coordinates are the same then it won't matter and you could even use the same coords for all three textures (in which case you might consider just baking some of the textures together like your lightmap for this example). You might want to consider actually using the second UV channel for your second UV if you actually intend to use both UVs (specified with uv2).
Shader "Reflective/Diffuseprb" {
Properties {
_Color ("Main Color", Color) = (1, 1, 1, 1)
_ReflectColor ("Reflection Color", Color) = (1, 1, 1, 1)
_MainTex ("Base (RGB) RefStrength (A)", 2D) = "white" {}
_BumpMap ("Normalmap", 2D) = "bump" {}
_LightMap ("Lightmap (RGB)", 2D) = "black" {}
_Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect }
}
SubShader {
Tags { "Queue"="Transparent" "RenderType"="Transparent"}
LOD 300
Cull Off
Lighting On
AlphaTest Greater 0.5
CGPROGRAM
//#pragma surface surf Lambert alpha
//#pragma vertex vert_img
#pragma surface surf Lambert alpha
#pragma debug
sampler2D _MainTex;
sampler2D _BumpMap;
sampler2D _LightMap;
samplerCUBE _Cube;
float4 _Color;
float4 _ReflectColor;
struct Input {
float2 uv_MainTex;
float2 uv_LightMap;
float3 worldRefl;
INTERNAL_DATA
};
void surf (Input IN, inout SurfaceOutput o) {
half4 tex = tex2D(_MainTex, IN.uv_MainTex);
half4 c = tex * _Color;
o.Albedo = c.rgb;
half4 reflcol = texCUBE (_Cube, IN.worldRefl) * _ReflectColor;
c = tex2D(_LightMap, IN.uv_LightMap);
o.Alpha = _Color.a + reflcol.a * _ReflectColor.a;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex)) * 2.0;
o.Emission = (reflcol.rgb * _ReflectColor.a) + c.rgb;
}
ENDCG
}
Fallback "Transparent/VertexLit"
}
system
February 1, 2011, 4:58am
3
remove cubemap calaulation.
Your Input structure consumes too much interpolators. Assign semantics to members. Like TEXCOORD, COLOR, etx.