Search Unity

Help with Shader Error: "Undeclared Identifier"

Discussion in 'Shaders' started by Mr_Admirals, Feb 1, 2019.

  1. Mr_Admirals

    Mr_Admirals

    Joined:
    May 13, 2017
    Posts:
    86
    Hey,

    So I'm running into an error that doesn't make sense to me. Here's the error:

    upload_2019-2-1_12-18-19.png

    Here's the code in question:

    Code (CSharp):
    1. TessellationFactors PatchConstantFunction(
    2.     InputPatch<TessellationControlPoint, 3> patch
    3. ) {
    4.     float3 p0 = mul(unity_ObjectToWorld, patch[0].vertex).xyz;
    5.     float3 p1 = mul(unity_ObjectToWorld, patch[1].vertex).xyz;
    6.     float3 p2 = mul(unity_ObjectToWorld, patch[2].vertex).xyz;
    7.  
    8.     half p0factor = tex2Dlod(_DispTex, float4(patch[0].uv.zw, 0, 0)).r;
    9.     half p1factor = tex2Dlod(_DispTex, float4(patch[1].uv.zw, 0, 0)).r;
    10.     half p2factor = tex2Dlod(_DispTex, float4(patch[2].uv.zw, 0, 0)).r;
    11.     half p3factor = tex2Dlod(_DispTex, float4(((patch[1].uv.z) + (patch[2].uv.z)) / 2, (patch[1].uv.w + patch[2].uv.w) / 2, 0, 0)).r;
    12.     half p4factor = tex2Dlod(_DispTex, float4(((patch[2].uv.z) + (patch[0].uv.z)) / 2, (patch[2].uv.w + patch[0].uv.w) / 2, 0, 0)).r;
    13.     half p5factor = tex2Dlod(_DispTex, float4(((patch[0].uv.z) + (patch[1].uv.z)) / 2, (patch[0].uv.w + patch[1].uv.w) / 2, 0, 0)).r;
    14.  
    15.     // Right here
    16.     half dispFactor = tex2Dlod(_DispMap, float4(patch[0].uv.xy, 0, 0)).r +
    17.                       tex2Dlod(_DispMap, float4(patch[1].uv.xy, 0, 0)).r +
    18.                       tex2Dlod(_DispMap, float4(patch[2].uv.xy, 0, 0)).r;
    19.  
    20.     half factor = (p0factor + p1factor + p2factor + p3factor + p4factor + p5factor + dispFactor);
    21.  
    22.     TessellationFactors f;
    23.     f.edge[0] = factor > 0.0 ? TessellationEdgeFactor(p1, p2) : 1.0;
    24.     f.edge[1] = factor > 0.0 ? TessellationEdgeFactor(p2, p0) : 1.0;
    25.     f.edge[2] = factor > 0.0 ? TessellationEdgeFactor(p0, p1) : 1.0;
    26.     f.inside = factor > 0.0 ? (TessellationEdgeFactor(p1, p2) +
    27.                                TessellationEdgeFactor(p2, p0) +
    28.                                TessellationEdgeFactor(p0, p1)) * (1 / 3.0) : 1.0;
    29.  
    30.     return f;
    However, _DispMap is clearly defined in a separate .cginc file, and I'm able to use it elsewhere in my code. Anyone have any insight into this?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    Is that separate cginc file #included at the top of SnowTessellation.cginc?
     
  3. Mr_Admirals

    Mr_Admirals

    Joined:
    May 13, 2017
    Posts:
    86
    No. Here's how it's included:

    Code (CSharp):
    1. Pass
    2.         {
    3.             Tags { "LightMode"="ForwardBase" }
    4.             CGPROGRAM
    5.  
    6.             #pragma target 4.6
    7.  
    8.             #pragma multi_compile_fwdbase
    9.             #pragma multi_compile EDGE_LENGTH
    10.  
    11.             #pragma vertex TessellationVertexProgram
    12.             #pragma fragment FragmentProgram
    13.             #pragma hull HullProgram
    14.             #pragma domain DomainProgram
    15.  
    16.             #define FORWARD_BASE_PASS
    17.             #define TESSELLATION_TANGENT 1
    18.  
    19.             #include "SnowLighting.cginc"
    20.             #include "SnowTessellation.cginc"
    21.  
    22.             ENDCG
    23.         }
    The vast majority of variables are defined in SnowLighting.cginc, and I'm able to use other ones defined in SnowLighting in SnowTessellation.
     
  4. Mr_Admirals

    Mr_Admirals

    Joined:
    May 13, 2017
    Posts:
    86
    Oh wait, I found it! I was reorganizing the structure of my code, when I remembered that one of my passes doesn't use SnowLighting, so I had to define it in the other .cginc file in there.

    Honestly, I feel like these forums are my rubber duck most of the time. Haha.