Search Unity

Error: Too many output registers declared

Discussion in 'Shaders' started by ensiferum888, Mar 11, 2015.

  1. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    266
    Good morning everyone,

    I'm trying to use this shader for the terrain which worked perfectly in Unity 4.6. I'm getting this error message:


    Shader error in 'Nature/Terrain/Specular': Too many output registers declared (12). When no output register has been declared with the semantic 'psize0', 11 o# registers are available. When an o# register has been declared with the semantic 'psize0' (same as 'psize'), 12 registers are available. at line 190 (on d3d9)

    Compiling Vertex program with DIRECTIONAL SHADOWS_SCREEN LIGHTMAP_OFF DIRLIGHTMAP_OFF DYNAMICLIGHTMAP_OFF FOG_LINEAR

    I can open the compiled code and see the 12 registers declared (am I even looking at the right thing?)
    Code (CSharp):
    1. struct v2f_surf {
    2.   float4 pos : SV_POSITION;
    3.   float4 pack0 : TEXCOORD0; // _Control _Splat0
    4.   float4 pack1 : TEXCOORD1; // _Splat1 _Splat2
    5.   float2 pack2 : TEXCOORD2; // _Splat3
    6.   float4 tSpace0 : TEXCOORD3;
    7.   float4 tSpace1 : TEXCOORD4;
    8.   float4 tSpace2 : TEXCOORD5;
    9.   fixed4 color : COLOR0;
    10.   #if UNITY_SHOULD_SAMPLE_SH
    11.   half3 sh : TEXCOORD6; // SH
    12.   #endif
    13.   SHADOW_COORDS(7)
    14.   UNITY_FOG_COORDS(8)
    15.   #if SHADER_TARGET >= 30
    16.   float4 lmap : TEXCOORD9;
    17.   #endif
    18. };
    Here is the actual code:
    Code (CSharp):
    1. // Original Code provided by Chris Morris of Six Times Nothing (http://www.sixtimesnothing.com)
    2. // Modified to support snow by lars bertram (http://forum.unity3d.com/members/3642-larsbertram1)
    3.  
    4. Shader "Nature/Terrain/Specular" {
    5. Properties {
    6.     _Control ("Control (RGBA)", 2D) = "red" {}
    7.     _Splat3 ("Layer 3 (A)", 2D) = "white" {}
    8.     _Splat2 ("Layer 2 (B)", 2D) = "white" {}
    9.     _Splat1 ("Layer 1 (G)", 2D) = "white" {}
    10.     _Splat0 ("Layer 0 (R)", 2D) = "white" {}
    11.     // used in fallback on old cards
    12.     _MainTex ("BaseMap (RGB)", 2D) = "white" {}
    13.     _Color ("Main Color", Color) = (1,1,1,1)
    14.    
    15.     _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
    16. }
    17.  
    18. SubShader {
    19.     Tags {
    20.         "SplatCount" = "4"
    21.         "Queue" = "Geometry-100"
    22.         "RenderType" = "Opaque"
    23.     }
    24. CGPROGRAM
    25. #pragma surface surf BlinnPhong vertex:vert
    26. #pragma target 3.0
    27. #include "UnityCG.cginc"
    28.  
    29. struct Input {
    30.     float3 worldPos;  
    31.     float2 uv_Control : TEXCOORD0;
    32.     float2 uv_Splat0 : TEXCOORD1;
    33.     float2 uv_Splat1 : TEXCOORD2;
    34.     float2 uv_Splat2 : TEXCOORD3;
    35.     float2 uv_Splat3 : TEXCOORD4;
    36.     float3 color : COLOR;
    37. };
    38.  
    39. // Supply the shader with tangents for the terrain
    40. void vert (inout appdata_full v, out Input o) {
    41.     UNITY_INITIALIZE_OUTPUT(Input, o);
    42.     // store worldNormal in vertexColor in order to safe registers
    43.     // terrains usually are not rotated -> so we do not have to to calculate the worldNormal, which would be:
    44.     // v.color.rgb = normalize(mul((float3x3)_Object2World, v.normal));
    45.     v.color.rgb = v.normal;
    46.    
    47.     // A general tangent estimation  
    48.     float3 T1 = float3(1, 0, 1);
    49.     float3 Bi = cross(T1, v.normal);
    50.     float3 newTangent = cross(v.normal, Bi);
    51.     normalize(newTangent);
    52.     v.tangent.xyz = newTangent.xyz;
    53.     if (dot(cross(v.normal,newTangent),Bi) < 0)
    54.         v.tangent.w = -1.0f;
    55.     else
    56.         v.tangent.w = 1.0f;
    57. }
    58.  
    59. sampler2D _Control;
    60. sampler2D _BumpMap0, _BumpMap1, _BumpMap2, _BumpMap3, _SnowTexture;
    61. sampler2D _Splat0,_Splat1,_Splat2,_Splat3;
    62. float _snowPowerTex0, _snowPowerTex1, _snowPowerTex2, _snowPowerTex3;
    63. //float _Spec0, _Spec1, _Spec2, _Spec3, _Tile0, _Tile1, _Tile2, _Tile3,
    64. float _snowShininess, _SnowTile, _TerrainX, _TerrainZ;
    65. float4 _v4CameraPos;
    66. float _SnowAmount;
    67. float _SnowStartHeight;
    68.  
    69. void surf (Input IN, inout SurfaceOutput o) {
    70.     UNITY_INITIALIZE_OUTPUT(SurfaceOutput, o);
    71.     half4 splat_control = tex2D (_Control, IN.uv_Control);
    72.     half3 col;
    73.     float snowPower;
    74.    
    75. // 4 splats, normals, and specular settings
    76.  
    77.     col  = splat_control.r * tex2D(_Splat0, IN.uv_Splat0).rgb;
    78.     o.Normal = splat_control.r * UnpackNormal(tex2D(_BumpMap0, IN.uv_Splat0));
    79.     snowPower = splat_control.r * _snowPowerTex0;
    80.     //o.Gloss = _Spec0 * splat_control.r;
    81.     //o.Specular = _Spec0 * splat_control.r;
    82.  
    83. ////
    84.     col  += splat_control.g * tex2D(_Splat1, IN.uv_Splat1).rgb;
    85.     o.Normal += splat_control.g * UnpackNormal(tex2D(_BumpMap1, IN.uv_Splat1));
    86.     snowPower += splat_control.g * _snowPowerTex1;
    87.     //o.Gloss += _Spec1 * splat_control.g;
    88.     //o.Specular += _Spec1 * splat_control.g;
    89.    
    90. ////    
    91.     col  += splat_control.b * tex2D(_Splat2, IN.uv_Splat2).rgb;
    92.     o.Normal += splat_control.b * UnpackNormal(tex2D(_BumpMap2, IN.uv_Splat2));
    93.     snowPower += splat_control.b * _snowPowerTex2;
    94.     //o.Gloss += _Spec2 * splat_control.b;
    95.     //o.Specular +=_Spec2 * splat_control.b;
    96.  
    97. ////  
    98.     col += splat_control.a * tex2D (_Splat3, IN.uv_Splat3).rgb;
    99.     o.Normal += splat_control.a * UnpackNormal(tex2D(_BumpMap3, IN.uv_Splat3));
    100.     snowPower += splat_control.a * _snowPowerTex3;
    101.     //o.Gloss += _Spec3 * splat_control.a;
    102.     //o.Specular += _Spec3 * splat_control.a;
    103.    
    104.        
    105. ///////////////////  
    106.  
    107.     // get snow texture
    108.     half3 snow = tex2D( _SnowTexture, float2(IN.uv_Control.x * (_TerrainX/_SnowTile), IN.uv_Control.y * (_TerrainZ/_SnowTile)) ).rgb;
    109.  
    110.     // get snow distribution texture
    111.     half3 snowdistribution = tex2D( _SnowTexture, IN.uv_Control).a;
    112.  
    113.     // (1-col.b) = take the blue channel to get some kind of heightmap // worldNormal is stored in IN.color
    114.     //float snowAmount = (_SnowAmount * IN.color.y * (1-col.b) + clamp(o.Normal.y, 0, 1) * _SnowAmount * .25) * snowPower;
    115.    
    116.     //float snowAmount = (_SnowAmount * IN.color.y * (1-col.b) * snowPower + clamp(o.Normal.y, 0, 1) * _SnowAmount * .25);
    117.    
    118.     float snowAmount = (_SnowAmount * IN.color.y * (1-col.b)  + clamp(o.Normal.y, 0, 1) * _SnowAmount * .25)*snowPower;
    119.  
    120.  
    121.    
    122.     // instead of col.b we can go with Luminance(col.rgb)
    123.     // but this will lead to bright textures on the terrain getting less snow and is more expensive
    124.     //float snowAmount = _SnowAmount * IN.color.y * (1- Luminance(col.rgb)) + clamp(o.Normal.y, 0, 1) * _SnowAmount *.5;
    125.    
    126.     // clamp snow to _SnowStartHeight
    127.     snowAmount *= clamp((IN.worldPos.y - _SnowStartHeight)*.0125, 0, 1);
    128.    
    129.     // mix in snowdistributionmap (lerp) and sharpen snow mask (pow), then clamp
    130.     snowAmount = clamp(pow(snowAmount*(lerp(snowdistribution, 1, snowAmount)),6)*256, 0, 1);
    131.    
    132.     o.Albedo = col.rgb * (1-snowAmount) + snow.rgb*snowAmount;
    133.    
    134.     // smooth normal
    135.     o.Normal = normalize(lerp(o.Normal, float3(0,0,1), snowAmount*.50));
    136.     o.Gloss = snowAmount*(1-snow);
    137.     o.Specular = _snowShininess;
    138.     o.Alpha = 0.0;
    139.    
    140. }
    141. ENDCG
    142. }
    143.  
    144. // Fallback to Diffuse
    145. Fallback "Diffuse"
    146. }
    Any help would be greatly appreciated. Thanks!
     
  2. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    266
    Fixed it by adding the nolightmap directive. I'm really not familiar with this lightmaping thing yet so I'm not sure this is the proper way to go about this.
     
  3. Alec-Chalmers

    Alec-Chalmers

    Joined:
    Jul 8, 2012
    Posts:
    16
    I'm having the same issue, could you explain the nolightmap directive and where you put it?
     
unityunity