Search Unity

Trying to create a geometry shader - running into syntax errors:

Discussion in 'Shaders' started by markashburner, Mar 19, 2018.

  1. markashburner

    markashburner

    Joined:
    Aug 14, 2015
    Posts:
    212
    So I have been following this tutorial to an immaculate degree.



    And for the life of me, I can not get around these syntax errors. Here is my code:

    Code (CSharp):
    1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
    2.  
    3. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
    4.  
    5. // Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject'
    6.  
    7. Shader "Planet/LowPolyGrass" {
    8.     Properties {
    9.         _Color ("Color", Color) = (1,1,1,1)
    10.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
    11.         _Glossiness ("Smoothness", Range(0,1)) = 0.5
    12.         _Metallic ("Metallic", Range(0,1)) = 0.0
    13.     }
    14.     SubShader {
    15.         Tags { "RenderType"="Opaque" }
    16.         LOD 200
    17.  
    18.         Pass{
    19.  
    20.         CGPROGRAM
    21.         #include "UnityCG.cginc"
    22.        
    23.         #pragma vertex vert
    24.         #pragma fragment frag
    25.         #pragma geometry geom
    26.  
    27.         #pragma target 4.0
    28.  
    29.         sampler2D _MainTex;
    30.  
    31.         struct v2g
    32.         {
    33.         float4 pos : SV_POSITION;
    34.         float3 norm : NORMAL;
    35.         float2 uv : TEXCOORD0;
    36.         };
    37.  
    38.         struct g2f
    39.         {
    40.         float4 pos : SV_POSITION;
    41.         float3 norm : NORMAL;
    42.         //float2 uv : TEXCOORD0;
    43.         //float3 diffuseColor : TEXCOORD1;
    44.         //float3 specularColor : TEXCOORD2;
    45.         };
    46.        
    47.  
    48.         half _Glossiness;
    49.         half _Metallic;
    50.         fixed4 _Color;
    51.  
    52.         v2g vert(appdata_full v)
    53.         {
    54.         float3 v0 = v.vertex.xyz;
    55.        
    56.         v2g OUT;
    57.         OUT.pos = v.vertex;
    58.         OUT.norm = v.normal;
    59.         OUT.uv = v.texcoord;
    60.         return OUT;
    61.         }
    62.  
    63.  
    64.         [maxvertexcount(3)]
    65.         void geom(triangle v2g IN[3], inout TriangleStream<g2f> triStream)
    66.         {
    67.             float3 v0 = IN[0].pos.xyz;
    68.             float3 v1 = IN[1].pos.xyz;
    69.             float3 v2 = IN[2].pos.xyz;
    70.  
    71.         float3 normal = normalize(cross(v1 - v0, v1 - v2))
    72.  
    73.         g2f OUT;
    74.  
    75.         OUT.pos = UnityObjectToClipPos(IN[0].pos);
    76.         OUT.norm = normal;
    77.         //OUT.uv = IN[0].uv;
    78.         //OUT.diffuseColor = ambientLighting + diffuseReflection;
    79.         //OUT.specularColor = specularReflection;
    80.         triStream.Append(OUT);
    81.         OUT.pos = UnityObjectToClipPos(IN[1].pos);
    82.         OUT.norm = normal;
    83.         //OUT.uv = IN[1].uv;
    84.         //OUT.diffuseColor = ambientLighting + diffuseReflection;
    85.         //OUT.specularColor = specularReflection;
    86.         triStream.Append(OUT);
    87.         OUT.pos = UnityObjectToClipPos(IN[2].pos);
    88.         OUT.norm = normal;
    89.         //OUT.uv = IN[2].uv;
    90.         //OUT.diffuseColor = ambientLighting + diffuseReflection;
    91.         //OUT.specularColor = specularReflection;
    92.         triStream.Append(OUT);
    93.         }
    94.  
    95.  
    96.         half4 frag(g2f IN) : COLOR
    97.         {
    98.         return float4(1.0, 1.0, 1.0, 1.0);    }
    99.        
    100.         ENDCG
    101.     }
    102.     }
    103. }
    The syntax errors I am getting are these:

    Shader error in 'Planet/LowPolyGrass': syntax error: unexpected token 'g2f' at line 74 (on d3d11)

    Shader error in 'Planet/LowPolyGrass': undeclared identifier 'OUT' at line 76 (on d3d11)

    Can someone please tell me what I am doing wrong?

    I have declared Out at line 76?

    And I have declared g2f.
     
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,025
    line 71 is missing a ';'