Search Unity

Too many texture interpolators (11 out of max 10)

Discussion in 'Shaders' started by Leoo, Aug 25, 2015.

  1. Leoo

    Leoo

    Joined:
    May 13, 2013
    Posts:
    96
    Hello everyone,

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

    Code (csharp):
    1.  
    2. Shader "Hidden/TerrainEngine/Splatmap/Lightmap-AddPass-Advanced" {
    3. Properties {
    4.     _Depth ("Blend Depth", Range(0.001, 1)) = 0.1
    5.     _Control ("Control (RGBA)", 2D) = "black" {}
    6.     _Splat3 ("Layer 3 (A)", 2D) = "white" {}
    7.     _Splat2 ("Layer 2 (B)", 2D) = "white" {}
    8.     _Splat1 ("Layer 1 (G)", 2D) = "white" {}
    9.     _Splat0 ("Layer 0 (R)", 2D) = "white" {}
    10. }
    11.    
    12. SubShader {
    13.     Tags {
    14.         "SplatCount" = "4"
    15.         "Queue" = "Geometry-99"
    16.         "IgnoreProjector"="True"
    17.         "RenderType" = "Opaque"
    18.     }
    19. CGPROGRAM
    20. #pragma surface surf Lambert decal:add
    21. #pragma target 3.0
    22.  
    23. struct Input {
    24.     float2 uv_Control : TEXCOORD0;
    25.     float2 uv_Splat0 : TEXCOORD1;
    26.     float2 uv_Splat1 : TEXCOORD2;
    27.     float2 uv_Splat2 : TEXCOORD3;
    28.     float2 uv_Splat3 : TEXCOORD4;
    29. };
    30.  
    31. float _Depth;
    32. sampler2D _Control;
    33. sampler2D _Splat0,_Splat1,_Splat2,_Splat3;
    34.  
    35. inline float4 normalized(float4 val) {
    36.     return val / (val.r + val.g + val.b + val.a);
    37. }
    38.  
    39. inline float maximized(float4 val) {
    40.     return max(val[0], max(val[1], max(val[2], val[3])));
    41. }
    42.  
    43. void surf (Input IN, inout SurfaceOutput o) {
    44.     fixed4 sc = tex2D (_Control, IN.uv_Control);
    45.  
    46.     fixed4 t0 = tex2D (_Splat0, IN.uv_Splat0);
    47.     fixed4 t1 = tex2D (_Splat1, IN.uv_Splat1);
    48.     fixed4 t2 = tex2D (_Splat2, IN.uv_Splat2);
    49.     fixed4 t3 = tex2D (_Splat3, IN.uv_Splat3);
    50.  
    51.     float4 blend;
    52.     blend[0] = t0.a + sc.r;
    53.     blend[1] = t1.a + sc.g;
    54.     blend[2] = t2.a + sc.b;
    55.     blend[3] = t3.a + sc.a;
    56.  
    57.     float a = maximized(blend);
    58.     blend = normalized(max(blend - a + _Depth, 0));
    59.  
    60.     fixed3 col;
    61.     col  = blend.r * t0;
    62.     col += blend.g * t1;
    63.     col += blend.b * t2;
    64.     col += blend.a * t3;
    65.  
    66.     o.Albedo = col * (sc.r + sc.g + sc.b + sc.a);
    67.     o.Alpha = 0;
    68. }
    69. ENDCG  
    70. }
    71.  
    72. Fallback off
    73. }
    74.  
    75.  
    76.  
    Code (csharp):
    1.  
    2. Shader "Nature/Terrain/Advanced Diffuse HotFix" {
    3. Properties {
    4.     _Depth ("Blend Depth", Range(0.001, 1)) = 0.1
    5.     [HideInInspector] _Control ("Control (RGBA)", 2D) = "red" {}
    6.     [HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "black" {}
    7.     [HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "black" {}
    8.     [HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "black" {}
    9.     [HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "black" {}
    10.  
    11.     [HideInInspector] _MainTex ("BaseMap (RGB)", 2D) = "white" {}
    12.     [HideInInspector] _Color ("Main Color", Color) = (1,1,1,1)
    13. }
    14.    
    15. SubShader {
    16.     Tags {
    17.         "SplatCount" = "4"
    18.         "Queue" = "Geometry-100"
    19.         "RenderType" = "Opaque"
    20.     }
    21. CGPROGRAM
    22. #pragma surface surf Lambert
    23. #pragma target 3.0
    24.  
    25. struct Input {
    26.     float2 uv_Control : TEXCOORD0;
    27.     float2 uv_Splat0 : TEXCOORD1;
    28.     float2 uv_Splat1 : TEXCOORD2;
    29.     float2 uv_Splat2 : TEXCOORD3;
    30.     float2 uv_Splat3 : TEXCOORD4;
    31. };
    32.  
    33. float _Depth;
    34. sampler2D _Control;
    35. sampler2D _Splat0,_Splat1,_Splat2,_Splat3;
    36.  
    37. inline float4 normalized(float4 val) {
    38.     return val / (val.r + val.g + val.b + val.a);
    39. }
    40.  
    41. inline float maximized(float4 val) {
    42.     return max(val[0], max(val[1], max(val[2], val[3])));
    43. }
    44.  
    45. void surf (Input IN, inout SurfaceOutput o) {
    46.     fixed4 sc = tex2D (_Control, IN.uv_Control);
    47.  
    48.     fixed4 t0 = tex2D (_Splat0, IN.uv_Splat0);
    49.     fixed4 t1 = tex2D (_Splat1, IN.uv_Splat1);
    50.     fixed4 t2 = tex2D (_Splat2, IN.uv_Splat2);
    51.     fixed4 t3 = tex2D (_Splat3, IN.uv_Splat3);
    52.  
    53.     float4 blend;
    54.     blend[0] = t0.a + sc.r;
    55.     blend[1] = t1.a + sc.g;
    56.     blend[2] = t2.a + sc.b;
    57.     blend[3] = t3.a + sc.a;
    58.  
    59.     float a = maximized(blend);
    60.     blend = normalized(max(blend - a + _Depth, 0));
    61.  
    62.     fixed3 col;
    63.     col  = blend.r * t0;
    64.     col += blend.g * t1;
    65.     col += blend.b * t2;
    66.     col += blend.a * t3;
    67.  
    68.     o.Albedo = col * (sc.r + sc.g + sc.b + sc.a);
    69.     o.Alpha = 0;
    70. }
    71. ENDCG
    72. }
    73.  
    74. Dependency "AddPassShader" = "Hidden/TerrainEngine/Splatmap/Lightmap-AddPass-Advanced"
    75. Dependency "BaseMapShader" = "Diffuse"
    76. Dependency "Details0"      = "Hidden/TerrainEngine/Details/Vertexlit"
    77. Dependency "Details1"      = "Hidden/TerrainEngine/Details/WavingDoublePass"
    78. Dependency "Details2"      = "Hidden/TerrainEngine/Details/BillboardWavingDoublePass"
    79. Dependency "Tree0"         = "Hidden/TerrainEngine/BillboardTree"
    80.  
    81. // Fallback to Default shader
    82. Fallback "Nature/Terrain/Diffuse"
    83. }
    84.  
    85.  
    86.  
    87.  
    88.  
    89.  
     

    Attached Files:

  2. WhiskyJoe

    WhiskyJoe

    Joined:
    Aug 21, 2012
    Posts:
    143
    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. http://answers.unity3d.com/questions/472852/i-tried-hard-but-too-many-texture-interpolators-wo.html
     
    Leoo likes this.
  3. Plutoman

    Plutoman

    Joined:
    May 24, 2013
    Posts:
    257
    To add to what was mentioned above,

    Check out the section "Custom data computed per-vertex" in http://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html

    You'll add
    Code (csharp):
    1. //modify input to have two float4 UV's, and add the vertex function to the definition list
    2.  
    3. void vert (inout appdata_full v, out Input o)
    4. {
    5.      UNITY_INITIALIZE_OUTPUT(Input,o);
    6.      o.uv_Set1 = float4(v.texcoord0, v.texcoord1);
    7.      o.uv_Set2 = float4(v.texcoord2, v.texcoord3);
    8. }
    Then you'll access splat0 with uv_Set1.xy, and splat1 with uv_Set1.zw, and so forth.
     
    Leoo likes this.
  4. Leoo

    Leoo

    Joined:
    May 13, 2013
    Posts:
    96
    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.

    :(
     
  5. WhiskyJoe

    WhiskyJoe

    Joined:
    Aug 21, 2012
    Posts:
    143
    You gotta start somewhere. :)