for add add tangent and binormal to surface shader , but find something error .
it only says : too many texture interpolators would be used for forwardbase pass at line 9
how to add tangent and binormal to surface shader, what is the correct way to do this ,
is any sample code here in unity?
here is my code :
Shader “Custom/sur” {
Properties {
_MainTex (“Base (RGB)”, 2D) = “white” {}
}
SubShader {
Tags { “RenderType”=“Opaque” }
LOD 200
CGPROGRAM
#pragma surface surf LambertA vertex:vert
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
half3 normal_input;
half3 tangent_input;
half3 binormal_input;
};
struct SurfaceOutputEx{
half3 Albedo;
half3 Normal;
half3 Emission;
half3 Gloss;
half Specular;
half Alpha;
half3 normal_input;
half3 tangent_input;
half3 binormal_input;
};
void vert(inout appdata_full i, out Input o){
half4 p_normal =mul(float4(i.normal,0.0f),_World2Object);
half4 p_tangent =mul(_Object2World,i.tangent);
half3 normal_input =normalize(p_normal.xyz);
half3 tangent_input=normalize(p_tangent.xyz);
half3 binormal_input =cross(p_normal.xyz,p_tangent.xyz);
o.normal_input =normal_input;
o.tangent_input =tangent_input ;
o.binormal_input =binormal_input ;
}
void surf (Input IN, inout SurfaceOutputEx o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb ;
o.Alpha = c.a;
o.normal_input =IN.normal_input;
o.tangent_input =IN.tangent_input ;
o.binormal_input =IN.binormal_input ;
}
inline half4 LightingLambertA (SurfaceOutputEx s , half3 lightDir, half3 viewDir, half atten)
{
half3 h =normalize(lightDir+viewDir);
half3 b =s.binormal_input;
half diff = max (0, dot (s.Normal, lightDir));
half4 c;
c.rgb = s.Albedo * _LightColor0.rgb * (diff * atten * 2) ;
c.a = s.Alpha;
return c ;
}
ENDCG
}
FallBack “Diffuse”
}