Too many texture interpolators (11 out of max 10)

Hello everyone,

I keep getting this error in both my FirstPass and AddPass Script for my terrain shader, could anyone help me out?

Shader "Hidden/TerrainEngine/Splatmap/Lightmap-AddPass-Advanced" {
Properties {
    _Depth ("Blend Depth", Range(0.001, 1)) = 0.1
    _Control ("Control (RGBA)", 2D) = "black" {}
    _Splat3 ("Layer 3 (A)", 2D) = "white" {}
    _Splat2 ("Layer 2 (B)", 2D) = "white" {}
    _Splat1 ("Layer 1 (G)", 2D) = "white" {}
    _Splat0 ("Layer 0 (R)", 2D) = "white" {}
}
   
SubShader {
    Tags {
        "SplatCount" = "4"
        "Queue" = "Geometry-99"
        "IgnoreProjector"="True"
        "RenderType" = "Opaque"
    }
CGPROGRAM
#pragma surface surf Lambert decal:add
#pragma target 3.0

struct Input {
    float2 uv_Control : TEXCOORD0;
    float2 uv_Splat0 : TEXCOORD1;
    float2 uv_Splat1 : TEXCOORD2;
    float2 uv_Splat2 : TEXCOORD3;
    float2 uv_Splat3 : TEXCOORD4;
};

float _Depth;
sampler2D _Control;
sampler2D _Splat0,_Splat1,_Splat2,_Splat3;

inline float4 normalized(float4 val) {
    return val / (val.r + val.g + val.b + val.a);
}

inline float maximized(float4 val) {
    return max(val[0], max(val[1], max(val[2], val[3])));
}

void surf (Input IN, inout SurfaceOutput o) {
    fixed4 sc = tex2D (_Control, IN.uv_Control);

    fixed4 t0 = tex2D (_Splat0, IN.uv_Splat0);
    fixed4 t1 = tex2D (_Splat1, IN.uv_Splat1);
    fixed4 t2 = tex2D (_Splat2, IN.uv_Splat2);
    fixed4 t3 = tex2D (_Splat3, IN.uv_Splat3);

    float4 blend;
    blend[0] = t0.a + sc.r;
    blend[1] = t1.a + sc.g;
    blend[2] = t2.a + sc.b;
    blend[3] = t3.a + sc.a;

    float a = maximized(blend);
    blend = normalized(max(blend - a + _Depth, 0));

    fixed3 col;
    col  = blend.r * t0;
    col += blend.g * t1;
    col += blend.b * t2;
    col += blend.a * t3;

    o.Albedo = col * (sc.r + sc.g + sc.b + sc.a);
    o.Alpha = 0;
}
ENDCG  
}

Fallback off
}
Shader "Nature/Terrain/Advanced Diffuse HotFix" {
Properties {
    _Depth ("Blend Depth", Range(0.001, 1)) = 0.1
    [HideInInspector] _Control ("Control (RGBA)", 2D) = "red" {}
    [HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "black" {}
    [HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "black" {}
    [HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "black" {}
    [HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "black" {}

    [HideInInspector] _MainTex ("BaseMap (RGB)", 2D) = "white" {}
    [HideInInspector] _Color ("Main Color", Color) = (1,1,1,1)
}
   
SubShader {
    Tags {
        "SplatCount" = "4"
        "Queue" = "Geometry-100"
        "RenderType" = "Opaque"
    }
CGPROGRAM
#pragma surface surf Lambert
#pragma target 3.0

struct Input {
    float2 uv_Control : TEXCOORD0;
    float2 uv_Splat0 : TEXCOORD1;
    float2 uv_Splat1 : TEXCOORD2;
    float2 uv_Splat2 : TEXCOORD3;
    float2 uv_Splat3 : TEXCOORD4;
};

float _Depth;
sampler2D _Control;
sampler2D _Splat0,_Splat1,_Splat2,_Splat3;

inline float4 normalized(float4 val) {
    return val / (val.r + val.g + val.b + val.a);
}

inline float maximized(float4 val) {
    return max(val[0], max(val[1], max(val[2], val[3])));
}

void surf (Input IN, inout SurfaceOutput o) {
    fixed4 sc = tex2D (_Control, IN.uv_Control);

    fixed4 t0 = tex2D (_Splat0, IN.uv_Splat0);
    fixed4 t1 = tex2D (_Splat1, IN.uv_Splat1);
    fixed4 t2 = tex2D (_Splat2, IN.uv_Splat2);
    fixed4 t3 = tex2D (_Splat3, IN.uv_Splat3);

    float4 blend;
    blend[0] = t0.a + sc.r;
    blend[1] = t1.a + sc.g;
    blend[2] = t2.a + sc.b;
    blend[3] = t3.a + sc.a;

    float a = maximized(blend);
    blend = normalized(max(blend - a + _Depth, 0));

    fixed3 col;
    col  = blend.r * t0;
    col += blend.g * t1;
    col += blend.b * t2;
    col += blend.a * t3;

    o.Albedo = col * (sc.r + sc.g + sc.b + sc.a);
    o.Alpha = 0;
}
ENDCG
}

Dependency "AddPassShader" = "Hidden/TerrainEngine/Splatmap/Lightmap-AddPass-Advanced"
Dependency "BaseMapShader" = "Diffuse"
Dependency "Details0"      = "Hidden/TerrainEngine/Details/Vertexlit"
Dependency "Details1"      = "Hidden/TerrainEngine/Details/WavingDoublePass"
Dependency "Details2"      = "Hidden/TerrainEngine/Details/BillboardWavingDoublePass"
Dependency "Tree0"         = "Hidden/TerrainEngine/BillboardTree"

// Fallback to Default shader
Fallback "Nature/Terrain/Diffuse"
}

2265595–151665–TerrainAdvancedFirstPass.shader (2.33 KB)
2265595–151666–TerrainAdvancedAddPass.shader (1.66 KB)

In a surface shader, unity takes up some amount of the interpolators. You are using 5 of them already in your shader and the total amount (with #pragma target 3) is 10, so together with the stuff the surface shader needs, you’re surpassing the total of amount supported. (The interpolators are the TEXCOORD0, TEXCOORD1 etc)

Your best option would be to pack your 4 uv_SplatX in 2 interpolators. (So use float4 instead of float2 for them).

Check this one out. Too many texture interpolators would be used... Why? - Questions & Answers - Unity Discussions

1 Like

To add to what was mentioned above,

Check out the section “Custom data computed per-vertex” in Unity - Manual: Surface Shader examples

You’ll add

//modify input to have two float4 UV's, and add the vertex function to the definition list

void vert (inout appdata_full v, out Input o)
{
     UNITY_INITIALIZE_OUTPUT(Input,o);
     o.uv_Set1 = float4(v.texcoord0, v.texcoord1);
     o.uv_Set2 = float4(v.texcoord2, v.texcoord3);
}

Then you’ll access splat0 with uv_Set1.xy, and splat1 with uv_Set1.zw, and so forth.

1 Like

Hey guys, thanks a loot for pointing me into the right direction!, have been trying for hours with no success, but am still just a newbie on shader writing, fell like am really still behind this level of complexity, even when it dosnt seems to be that hard.

:frowning:

You gotta start somewhere. :slight_smile: