Search Unity

Error In My Shader

Discussion in 'Shaders' started by AnthonyGDI, May 2, 2017.

  1. AnthonyGDI

    AnthonyGDI

    Joined:
    Feb 5, 2016
    Posts:
    20
    Hey guys.

    I get "Unexpected token usertype" when I try to create an Input struct in my shader. Any clue why?

    Error: "Shader error in 'Custom/MyTriplanar-FirstPass': Unexpected token usertype. Expected: identifier at line 65"

    Code (csharp):
    1. Shader "Custom/MyTriplanar-FirstPass" {
    2.     Properties{
    3.         // set by terrain engine
    4.         [HideInInspector] _Control("Control (RGBA)", 2D) = "red" {}
    5.     [HideInInspector] _Splat3("Layer 3 (A)", 2D) = "white" {}
    6.     [HideInInspector] _Splat2("Layer 2 (B)", 2D) = "white" {}
    7.     [HideInInspector] _Splat1("Layer 1 (G)", 2D) = "white" {}
    8.     [HideInInspector] _Splat0("Layer 0 (R)", 2D) = "white" {}
    9.     [HideInInspector] _Normal3("Normal 3 (A)", 2D) = "bump" {}
    10.     [HideInInspector] _Normal2("Normal 2 (B)", 2D) = "bump" {}
    11.     [HideInInspector] _Normal1("Normal 1 (G)", 2D) = "bump" {}
    12.     [HideInInspector] _Normal0("Normal 0 (R)", 2D) = "bump" {}
    13.     [HideInInspector][Gamma] _Metallic0("Metallic 0", Range(0.0, 1.0)) = 0.0
    14.         [HideInInspector][Gamma] _Metallic1("Metallic 1", Range(0.0, 1.0)) = 0.0
    15.         [HideInInspector][Gamma] _Metallic2("Metallic 2", Range(0.0, 1.0)) = 0.0
    16.         [HideInInspector][Gamma] _Metallic3("Metallic 3", Range(0.0, 1.0)) = 0.0
    17.         [HideInInspector] _Smoothness0("Smoothness 0", Range(0.0, 1.0)) = 1.0
    18.         [HideInInspector] _Smoothness1("Smoothness 1", Range(0.0, 1.0)) = 1.0
    19.         [HideInInspector] _Smoothness2("Smoothness 2", Range(0.0, 1.0)) = 1.0
    20.         [HideInInspector] _Smoothness3("Smoothness 3", Range(0.0, 1.0)) = 1.0
    21.  
    22.         // used in fallback on old cards & base map
    23.         [HideInInspector] _MainTex("BaseMap (RGB)", 2D) = "white" {}
    24.     [HideInInspector] _Color("Main Color", Color) = (1,1,1,1)
    25.     }
    26.  
    27.         SubShader{
    28.         Tags{
    29.         "Queue" = "Geometry-100"
    30.         "RenderType" = "Opaque"
    31.     }
    32.  
    33.         CGPROGRAM
    34. #pragma surface surf Standard vertex:SplatmapVert finalcolor:SplatmapFinalColor finalgbuffer:SplatmapFinalGBuffer fullforwardshadows
    35. #pragma multi_compile_fog
    36. #pragma target 3.0
    37.         // needs more than 8 texcoords
    38. #pragma exclude_renderers gles psp2
    39. #include "UnityPBSLighting.cginc"
    40.  
    41. #pragma multi_compile __ _TERRAIN_NORMAL_MAP
    42. #if defined(SHADER_API_D3D9) && defined(SHADOWS_SCREEN) && defined(LIGHTMAP_ON) && defined(DIRLIGHTMAP_COMBINED) && defined(DYNAMICLIGHTMAP_ON) && defined(SHADOWS_SHADOWMASK) && defined(_TERRAIN_NORMAL_MAP) && defined(UNITY_SPECCUBE_BLENDING)
    43.         // TODO : On d3d9 17 samplers would be used when : defined(SHADOWS_SCREEN) && defined(LIGHTMAP_ON) && defined(DIRLIGHTMAP_COMBINED) && defined(DYNAMICLIGHTMAP_ON) && defined(SHADOWS_SHADOWMASK) && defined(_TERRAIN_NORMAL_MAP) && defined(UNITY_SPECCUBE_BLENDING)
    44.         // In that case it would be probably acceptable to undef UNITY_SPECCUBE_BLENDING however at the moment (10/2/2016) we can't undef UNITY_SPECCUBE_BLENDING or other platform defines. CGINCLUDE being added after "Lighting.cginc".
    45.         // For now, remove _TERRAIN_NORMAL_MAP in this case.
    46. #undef _TERRAIN_NORMAL_MAP
    47. #define DONT_USE_TERRAIN_NORMAL_MAP // use it to initialize o.Normal to (0,0,1) because the surface shader analysis still see this shader writes to per-pixel normal.
    48. #endif
    49.  
    50. #define TERRAIN_STANDARD_SHADER
    51. #define TERRAIN_SURFACE_OUTPUT SurfaceOutputStandard
    52. #include "TerrainSplatmapCommon.cginc"
    53.  
    54.         half _Metallic0;
    55.     half _Metallic1;
    56.     half _Metallic2;
    57.     half _Metallic3;
    58.  
    59.     half _Smoothness0;
    60.     half _Smoothness1;
    61.     half _Smoothness2;
    62.     half _Smoothness3;
    63.  
    64.     // Surface shader input structure
    65.     struct Input {
    66.         float3 worldPos;
    67.         float3 worldNormal;
    68.     };
    69.  
    70.     void surf(Input IN, inout SurfaceOutputStandard o) {
    71.         half4 splat_control;
    72.         half weight;
    73.         fixed4 mixedDiffuse;
    74.         half4 defaultSmoothness = half4(_Smoothness0, _Smoothness1, _Smoothness2, _Smoothness3);
    75. #ifdef DONT_USE_TERRAIN_NORMAL_MAP
    76.         o.Normal = fixed3(0, 0, 1);
    77. #endif
    78.         SplatmapMix(IN, defaultSmoothness, splat_control, weight, mixedDiffuse, o.Normal);
    79.         o.Albedo = mixedDiffuse.rgb;
    80.         o.Alpha = weight;
    81.         o.Smoothness = mixedDiffuse.a;
    82.         o.Metallic = dot(splat_control, half4(_Metallic0, _Metallic1, _Metallic2, _Metallic3));
    83.     }
    84.     ENDCG
    85.     }
    86.  
    87.         Dependency "AddPassShader" = "Triplanar-AddPass"
    88.         Dependency "BaseMapShader" = "MyTriplanar-Base"
    89.  
    90.         Fallback "Diffuse"
    91. }
    92.  
     
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    It seems "Input" is a keyword. Try something like "surface_in" instead.

    There are some pretty bad cases of this in shaders with pretty random error messages. You sometimes get up to a level you want to put "my" in front of every variable name like in a programming for dummies book just to make sure you're not hitting any keywords.
     
    Krishx007 likes this.
  3. glitchers

    glitchers

    Joined:
    Apr 29, 2014
    Posts:
    64
    I got this error because one of my #includes already include an struct called `Input` - check your includes to make sure you're not making a duplicate.
     
    Krishx007 likes this.