Search Unity

Shader Error

Discussion in 'Shaders' started by SilentParrotStudio, Aug 20, 2014.

  1. SilentParrotStudio

    SilentParrotStudio

    Joined:
    Aug 13, 2014
    Posts:
    12
    Hello! My name is Cristi and I have a big problem with a shader. This shader is from "ats Snow Suite".
    The error is: "incorrect number of arguments to numeric-type constructor" on line 65 and the Shader is:
    Click here:
    Code (csharp):
    1.  
    2. Shader "snowShader Bumped Diffuse" {
    3. Properties {
    4.     _Color ("Main Color", Color) = (1,1,1,1)
    5.     _MainTex ("Base (RGB)", 2D) = "white" {}
    6.     _BumpMap ("Normalmap", 2D) = "bump" {}
    7. }
    8.  
    9. SubShader {
    10.     Tags { "RenderType"="Opaque" }
    11.     LOD 300
    12.  
    13. CGPROGRAM
    14. #pragma surface surf Lambert vertex:snow
    15. #pragma exclude_renderers flash
    16. //#pragma target 3.0
    17.  
    18.  
    19. sampler2D _MainTex;
    20. sampler2D _SnowTex;
    21. sampler2D _BumpMap;
    22. fixed4 _Color;
    23.  
    24. float _snowShininess;
    25. float _SnowAmount;
    26. float _SnowStartHeight;
    27. sampler2D _SnowTexture;
    28.  
    29. struct Input {
    30.     float2 uv_MainTex;
    31.     float2 uv_BumpMap;
    32.     fixed4 color : COLOR;
    33.     float3 worldPos;
    34.     fixed3 MyWorldNormal;
    35. };
    36.  
    37.  
    38. void snow (inout appdata_full v, out Input o) {  
    39.     o.MyWorldNormal = normalize(mul((float3x3)_Object2World, v.normal));
    40. }
    41.  
    42.  
    43. void surf (Input IN, inout SurfaceOutput o) {
    44.  
    45.     fixed4 col = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    46.     fixed4 snow = tex2D(_SnowTex, IN.uv_MainTex);
    47.     o.Alpha = col.a;
    48.     o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    49.  
    50.     // get snow texture // distribution might be stored in alpha
    51.     half4 snowtex = tex2D( _SnowTexture, IN.uv_MainTex);
    52.  
    53.     // clamp(IN.MyWorldNormal.y + 0.6, 0, 1) = allows snow even on orthogonal surfaces // (1-col.b) = take the blue channel to get some kind of heightmap
    54.     float snowAmount = (_SnowAmount * (clamp(IN.MyWorldNormal.y + 0.6, 0, 1)) * (1-col.b) *.8 + clamp(o.Normal.y, 0, 1) * _SnowAmount * .25);
    55.  
    56.     // clamp snow to _SnowStartHeight
    57.     snowAmount = snowAmount * clamp((IN.worldPos.y - _SnowStartHeight)*.0125, 0, 1);
    58.  
    59.     // sharpen snow mask
    60.     snowAmount = clamp(pow(snowAmount,6)*256, 0, 1);
    61.  
    62.     o.Alpha = 0.0;  
    63.  
    64.     // mix
    65.     o.Albedo = col.rgb * (1-snowAmount) + snowtex.rgb*snowAmount;
    66.     o.Gloss = half(snowAmount*(1-snowtex.rgb));
    67.     o.Specular = _snowShininess;
    68.  
    69.     // smooth normal
    70.     o.Normal = normalize(lerp(o.Normal, float3(0,0,1), snowAmount*.50));
    71.  
    72. }
    73. ENDCG
    74. }
    75.  
    76. FallBack "Diffuse"
    77. }
    78.  
    79.  

    Help me, please!
     
  2. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    I actually have no Idea what's up here...

    Once I get home, I might try and check this on my laptop. (could do it now, but I forgot my TAFE ID... ;))
     
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,408
    I'm guessing its line 66,
    o.Gloss = half(snowAmount*(1-snowtex.rgb));

    test if this works,
    o.Gloss = half(snowAmount*(1-snowtex.r));
     
  4. SilentParrotStudio

    SilentParrotStudio

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

    Cyrien5100

    Joined:
    Oct 17, 2012
    Posts:
    145
    Try this (not sure) :
    It seems that the o parameter is useless, because you don't use it in the function, you directly modify v (inout).
     
    Last edited: Aug 23, 2014
  6. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    @Cristi97Gaming: Looks like you're using DX11. Try doing what Cyrien said! :) DX11 is very sensitive about syntax, so silly syntax differences, (or things that should work... ;)) often stuff up DX11.

    If all else fails, try D3D9 renderer and see what happens.
     
  7. spraycanmansam

    spraycanmansam

    Joined:
    Nov 22, 2012
    Posts:
    254
    Try adding UNITY_INITIALIZE_OUTPUT(Input, o); to the beginning of your vertex program.
    Like so ---

    Code (csharp):
    1. void vert (inout appdata_full v, out Input o)
    2. {
    3.     UNITY_INITIALIZE_OUTPUT(Input, o);
    4.     // ...
    5. }
     
  8. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    @spraycanmansam: Isn't that only needed for DX11? because I do remember seeing that! :)
     
  9. spraycanmansam

    spraycanmansam

    Joined:
    Nov 22, 2012
    Posts:
    254
    Use it when compiling HLSL. It initialises the output to zero so the compiler doesn't complain about uninitialised values. For Dx9, that will come up as a warning, but Dx11 will throw an error.
     
  10. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    @spraycanmansam: Yes... ;)
     
  11. SilentParrotStudio

    SilentParrotStudio

    Joined:
    Aug 13, 2014
    Posts:
    12
    Thank you all for your help and I wish you all a good day!
     
  12. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871