Search Unity

Parse Error: Syntax Error TOK_COLOR vs TVAL_COLOR?

Discussion in 'Shaders' started by BrewNCode, Jan 26, 2020.

  1. BrewNCode

    BrewNCode

    Joined:
    Feb 17, 2017
    Posts:
    372
    I have an error in a shader that I was learning on about. I wanted to recreate a Blinn-Phong shader. but I have This problem.

    Code:

    Code (CSharp):
    1. Shader "Compendium/BasicBlinn"
    2. {
    3.     Properties
    4.     {
    5.         Color("Color", Color) = (1,1,1,1)
    6.         SpecularColor("Spec Color", Color) = (1,1,1,1)
    7.         Specular("Specu;ar", Range(0,1)) = 0.5
    8.         Gloss("Gloss", Range(0,1)) = 0.5
    9.     }
    10.         SubShader
    11.     {
    12.         Tags
    13.     {
    14.         "Queue" = "Geometry"
    15.  
    16.     }
    17.         CGPROGRAM
    18.         #pragma surface surf BlinnPhong
    19.  
    20.         float4 Color;
    21.         half Specular;
    22.         fixed Gloss;
    23.  
    24.         struct Input
    25.         {
    26.             float2 uv_MainTex;
    27.         };
    28.  
    29.         void surf(Input IN, inout SurfaceOutput o)
    30.         {
    31.             o.Albedo = Color.rgb;
    32.             o.Specular = Specular;
    33.             o.Gloss = Gloss;
    34.         }
    35.         ENDCG
    36.     }
    37.         FallBack "Diffuse"
    38. }
    The error is the following:
    Code (CSharp):
    1. Shader error in 'BasicBlinn': Parse error: syntax error, unexpected TOK_COLOR, expecting TVAL_ID or TVAL_VARREF at line 5
    line 5 being Color("Color", Color) = (1,1,1,1)

    I don't know how to solve this because I'm new to Shading, but if someone could tell me what is wrong here?
     
  2. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    Color
    and
    Specular
    as property names conflict with some built-in parsing types that's causing an error. Change them to
    _Color
    and
    _Specular
    , ideally start all your top level properties with underscore as common naming convention.

    Like:
    _Color("Color", Color) = (1,1,1,1)

    _Specular("Specular", Range(0,1)) = 0.5


    Also there's a semicolon in the string description for your Specular property. It shouldn't cause a compile issue but just pointing it out.
     
    Last edited: Jan 26, 2020
    jensVrag and BrewNCode like this.
  3. BrewNCode

    BrewNCode

    Joined:
    Feb 17, 2017
    Posts:
    372
    Thank you, it worked perfectly. Thank you for that rule of thumb for the naming convention.
     
  4. denny017

    denny017

    Joined:
    Sep 18, 2019
    Posts:
    2
    I got this error as well, and the cause of mine was, I forgot the another double quote (") at the end of the shader name... so stupid...