Search Unity

Unity 3.2 Update: "Too Many Texture Interpolators" in triplanar projection.

Discussion in 'Shaders' started by Broken-Toy, Feb 18, 2011.

  1. Broken-Toy

    Broken-Toy

    Joined:
    Jan 16, 2010
    Posts:
    455
    As the title says. I just upgraded to 3.2 and somehow all my shaders which are based on triplanar projections give off a "too many texture interpolators" error unless UnpackNormal is commented out.

    Is there any way to allow this to work again, or did the update "downgrade" the shader language back to pre-3.0 texture interpolator limits?

    Thanks in advance.
     
    Last edited: Feb 20, 2011
  2. Broken-Toy

    Broken-Toy

    Joined:
    Jan 16, 2010
    Posts:
    455
    Also, using #pragma target 3.0 shows other kinds of errors (target 2.0 is fine though). I'm not sure if it's a second bug or part of the same issue, since it also didn't do that prior to the 3.2 update:

    #pragma target 3.0 error log:
    Very disconcerting.
     
  3. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Hey, I figured out what it is.

    I believe it's because you have added 'WorldNormal' as an interpolator. This is now a 'reserved' word in unity and will cause it to do it's own 'world normal' processing (see the 3.2 shaderlab docs). If you rename your variable it should work. You can also use the unity 'worldnormal' but it will eat interpolators because if you write to normal in the pixel shader it will require the TBN matrix to be passed to get the per-pixel (i.e. normal mapped) world normal.
     
  4. Broken-Toy

    Broken-Toy

    Joined:
    Jan 16, 2010
    Posts:
    455
    Thanks, I'd never have thought of that one. It indeed solved both issues (bump map and pragma target) and makes a lot of sense now that you explain it.
     
  5. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    I need to create my own input variable to act like my own worldNormal, since unity won't let me use theirs. I can't seem to figure it out as it is not very straightforward. Here is the simple shader code I was originally trying to get working. It doesn't.

    Code (csharp):
    1. Shader "Custom/TriPlanar" {
    2.     Properties {
    3.         _MainTex ("MainTex", 2D) = "white" {}
    4.         _Normal ("Normal", 2D) = "bump" {}
    5.         _scale ("Scale", Float) = 8
    6.     }
    7.     SubShader {
    8.         Tags { "RenderType" = "Opaque" }
    9.         CGPROGRAM
    10.         #pragma surface surf Lambert
    11.        
    12.         struct Input {
    13.             float3 worldPos;
    14.             float3 worldNormal;
    15.         };
    16.        
    17.         sampler2D _MainTex;
    18.         sampler2D _Normal;
    19.        
    20.         float _Scale;
    21.         float _Sharpness;
    22.        
    23.         void surf (Input IN, inout SurfaceOutput o) {
    24.             float3 weight = abs(IN.worldNormal);
    25.            
    26.             float2 uv = IN.worldPos.yz;
    27.             float maxWeight = weight.x;
    28.            
    29.             if(weight.y > maxWeight)
    30.             {
    31.                 uv = IN.worldPos.xz;
    32.                 maxWeight = weight.y;
    33.             }
    34.            
    35.             if(weight.z > maxWeight)
    36.             {
    37.                 uv = IN.worldPos.xy;
    38.             }
    39.            
    40.             o.Albedo = weight;
    41.             o.Normal = UnpackNormal (tex2D (_Normal, uv / _Scale));
    42.             o.Alpha = 1;
    43.         }
    44.         ENDCG
    45.     }
    46.     Fallback "Diffuse"
    47. }
    48.  
    Thanks if you can get this working.

    P.S. It's hard to describe how frustrating it is when the simplest code doesn't work, your left with no leads as to why it doesn't, and you wind up turning what would have been a short, convenient, easy to read script into a complicated, inefficient, incoherent mess during the flurry of frantic attempts to fix the problem that often lead you nowhere. :( Not that I'm blaming anyone.
     
    Last edited: May 16, 2012
  6. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    If Unity had better error messages, you and I would be able to solve such things, but instead they throw generic parsing errors, or throw things at you because you've overridden some magic pudding keyword that Unity never told you about. A "simple" preprocessing step to validate and let you know if you've used these reserved words or other things would do a world of good.
     
  7. jamesflowerdew

    jamesflowerdew

    Joined:
    Apr 29, 2009
    Posts:
    10
    Tim can you explain how to do this (get the normals through without mcking up unity's defalts)?
    This is a common question, and a great in-depth answer would save a lot of universal pain.
     
  8. Elmo2900

    Elmo2900

    Joined:
    Apr 26, 2016
    Posts:
    2
    Just write this command under other pragmas:
    #pragma only_renderers d3d9
    This should work! :)