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): Shader "Custom/MyTriplanar-FirstPass" { Properties{ // set by terrain engine [HideInInspector] _Control("Control (RGBA)", 2D) = "red" {} [HideInInspector] _Splat3("Layer 3 (A)", 2D) = "white" {} [HideInInspector] _Splat2("Layer 2 (B)", 2D) = "white" {} [HideInInspector] _Splat1("Layer 1 (G)", 2D) = "white" {} [HideInInspector] _Splat0("Layer 0 (R)", 2D) = "white" {} [HideInInspector] _Normal3("Normal 3 (A)", 2D) = "bump" {} [HideInInspector] _Normal2("Normal 2 (B)", 2D) = "bump" {} [HideInInspector] _Normal1("Normal 1 (G)", 2D) = "bump" {} [HideInInspector] _Normal0("Normal 0 (R)", 2D) = "bump" {} [HideInInspector][Gamma] _Metallic0("Metallic 0", Range(0.0, 1.0)) = 0.0 [HideInInspector][Gamma] _Metallic1("Metallic 1", Range(0.0, 1.0)) = 0.0 [HideInInspector][Gamma] _Metallic2("Metallic 2", Range(0.0, 1.0)) = 0.0 [HideInInspector][Gamma] _Metallic3("Metallic 3", Range(0.0, 1.0)) = 0.0 [HideInInspector] _Smoothness0("Smoothness 0", Range(0.0, 1.0)) = 1.0 [HideInInspector] _Smoothness1("Smoothness 1", Range(0.0, 1.0)) = 1.0 [HideInInspector] _Smoothness2("Smoothness 2", Range(0.0, 1.0)) = 1.0 [HideInInspector] _Smoothness3("Smoothness 3", Range(0.0, 1.0)) = 1.0 // used in fallback on old cards & base map [HideInInspector] _MainTex("BaseMap (RGB)", 2D) = "white" {} [HideInInspector] _Color("Main Color", Color) = (1,1,1,1) } SubShader{ Tags{ "Queue" = "Geometry-100" "RenderType" = "Opaque" } CGPROGRAM #pragma surface surf Standard vertex:SplatmapVert finalcolor:SplatmapFinalColor finalgbuffer:SplatmapFinalGBuffer fullforwardshadows #pragma multi_compile_fog #pragma target 3.0 // needs more than 8 texcoords #pragma exclude_renderers gles psp2 #include "UnityPBSLighting.cginc" #pragma multi_compile __ _TERRAIN_NORMAL_MAP #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) // 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) // 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". // For now, remove _TERRAIN_NORMAL_MAP in this case. #undef _TERRAIN_NORMAL_MAP #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. #endif #define TERRAIN_STANDARD_SHADER #define TERRAIN_SURFACE_OUTPUT SurfaceOutputStandard #include "TerrainSplatmapCommon.cginc" half _Metallic0; half _Metallic1; half _Metallic2; half _Metallic3; half _Smoothness0; half _Smoothness1; half _Smoothness2; half _Smoothness3; // Surface shader input structure struct Input { float3 worldPos; float3 worldNormal; }; void surf(Input IN, inout SurfaceOutputStandard o) { half4 splat_control; half weight; fixed4 mixedDiffuse; half4 defaultSmoothness = half4(_Smoothness0, _Smoothness1, _Smoothness2, _Smoothness3); #ifdef DONT_USE_TERRAIN_NORMAL_MAP o.Normal = fixed3(0, 0, 1); #endif SplatmapMix(IN, defaultSmoothness, splat_control, weight, mixedDiffuse, o.Normal); o.Albedo = mixedDiffuse.rgb; o.Alpha = weight; o.Smoothness = mixedDiffuse.a; o.Metallic = dot(splat_control, half4(_Metallic0, _Metallic1, _Metallic2, _Metallic3)); } ENDCG } Dependency "AddPassShader" = "Triplanar-AddPass" Dependency "BaseMapShader" = "MyTriplanar-Base" Fallback "Diffuse" }
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.
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.