- Home /
Too many texture interpolators would be used for ForwardBase pass (again)
This shader gives me the above error (minus the "(again)") when I uncomment the line that starts "//o.normal". It's for a terrain, and the idea is to use worldspace instead of normal uvs so hills aren't all stretchy. I searched online and most people seemed to be struggling with multiple sets of uvs, but I've got 3 with that line commented and still only 3 commented so why does it break?
Appologies if it's a typo but I've stared at it for hours.
Shader "gamevial/TerrainWorldMapped" {
Properties {
_Control("Control",2D)= "grey" {}
_Splat0("Texture2 (R)", 2D) = "white" {}
_Normal0 ("Bump2 (R)",2D)="grey"{}
_Splat1("Texture3 (G)", 2D) = "white" {}
_Normal1 ("Bump3 (G)",2D)="grey"{}
_Splat2("Texture4 (B)", 2D) = "white" {}
_Normal2 ("Bump4 (B)",2D)="grey"{}
_Splat3 ("Texture1 (A)", 2D) = "white" {}
_Normal3 ("Bump1 (A)",2D)="grey"{}
_MainTex ("BaseMap (RGB)", 2D) = "white" {}
_Detail("Fallback Detail",2D)="white"{}
_Scale ("Texture Scale", Float) = 0.1
}
SubShader {
Tags { "RenderType"="Opaque" "SplatCount" = "4" "Queue" = "Geometry-100" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
struct Input {
float2 uv_Control;
float3 worldNormal;
float3 worldPos;
};
sampler2D _Normal3;
sampler2D _Normal0;
sampler2D _Normal1;
sampler2D _Normal2;
sampler2D _Splat3;
sampler2D _Splat0;
sampler2D _Splat1;
sampler2D _Splat2;
sampler2D _Control;
float _Scale;
void surf (Input IN, inout SurfaceOutput o) {
float2 UV;
if(abs(IN.worldNormal.x)>0.5) {
UV = IN.worldPos.yz*_Scale; // side
}else if(abs(IN.worldNormal.z*_Scale)>0.5) {
UV=IN.worldPos.xy;//front
} else {
UV = IN.worldPos.xz*_Scale; // top
}
half4 vCT=tex2D(_Control, IN.uv_Control).rgba;
//o.Normal=((tex2D(_Normal0, UV))*vCT.r)+((tex2D(_Normal1, UV))*vCT.g)+((tex2D(_Normal2, UV))*vCT.b)+((tex2D(_Normal3, UV))*vCT.a);
o.Albedo =((tex2D(_Splat0,UV).rgb)*vCT.r)+((tex2D(_Splat1,UV).rgb)*vCT.g)+((tex2D(_Splat2,UV).rgb)*vCT.b)+((tex2D (_Splat3,UV).rgb)*vCT.a);
}
ENDCG
}
FallBack "Diffuse"
as a note, experimenting with another shader suggests that o.Normal freaks out with the above uv mix for bumpmaps without the splat, could this be the problem? can annyone explain?
Answer by jamesflowerdew · Jul 13, 2014 at 11:48 AM
Hi All, I figured this out finally. I should mention that I got a clue here, albeit not one that I understood: http://forum.unity3d.com/threads/unity-3-2-update-too-many-texture-interpolators-in-triplanar-projection.78579/
I needed to build my own normal variable and get it through using a vert program and changes to the input struct, using the one that's there already freaks out unity (a fixable bug?). My new normal stuff is ccalled "myNormal".
Shader "gamevial/TerrainWorldMapped" {
Properties {
_Control("Control",2D)= "grey" {}
_Splat0("Texture1 (R)", 2D) = "white" {}
_Normal0 ("Bump1 (R)",2D)="grey"{}
_Splat1("Texture2 (G)", 2D) = "white" {}
_Normal1 ("Bump2 (G)",2D)="grey"{}
_Splat2("Texture3 (B)", 2D) = "white" {}
_Normal2 ("Bump3 (B)",2D)="grey"{}
_Splat3 ("Texture4 (A)", 2D) = "white" {}
_Normal3 ("Bump4 (A)",2D)="grey"{}
//_MainTex ("BaseMap (RGB)", 2D) = "white" {}
//_Detail("Fallback Detail",2D)="white"{}
_Scale ("Texture Scale", Float) = 0.1
}
SubShader {
Tags { "RenderType"="Opaque" "SplatCount" = "4" "Queue" = "Geometry-100" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert vertex:vert
//#pragma target 3.0
struct Input {
float2 uv_Control;
float3 worldNormal;
float3 worldPos;
float3 myNormal;
};
void vert(inout appdata_full v, out Input o) {
o.worldPos = mul(_Object2World, v.vertex).xyz;
o.worldNormal = mul(_Object2World, float4(v.normal, 0.0)).xyz;
o.myNormal=o.worldNormal;
}
sampler2D _Normal0,_Normal1,_Normal2,_Normal3;
sampler2D _Splat0,_Splat1,_Splat2,_Splat3;
sampler2D _Control;
float _Scale;
void surf (Input IN, inout SurfaceOutput o) {
half4 vCT=tex2D(_Control, IN.uv_Control).rgba;
float vBlack=1-vCT.r-vCT.g-vCT.b;
float2 UV = IN.worldPos.xz*_Scale;
if(abs(IN.myNormal.x)>0.5) {
UV = IN.worldPos.yz*_Scale; // side
}else if(abs(IN.myNormal.z)>0.5) {
UV=IN.worldPos.xy*_Scale;//front
}
half3 vAlb=(tex2D(_Splat3,UV).rgb*vBlack)+(tex2D(_Splat0,UV).rgb*vCT.r)+(tex2D(_Splat1,UV).rgb*vCT.g)+(tex2D(_Splat2,UV).rgb*vCT.b);
half4 vNor=(tex2D(_Normal3, UV)*vBlack) + (tex2D(_Normal0, UV)*vCT.r) + (tex2D(_Normal1, UV)*vCT.g) + (tex2D(_Normal2, UV)*vCT.b);
o.Normal= UnpackNormal(vNor);
o.Albedo =vAlb;
}
ENDCG
}
FallBack "Diffuse"
}
Your answer
Follow this Question
Related Questions
CG diffuse shader 1 Answer
Problem with custom shaders (surface function error) 0 Answers
GLSL: Shader cannot be patched for instancing 1 Answer
jungle terrain problem 0 Answers