Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Parse or syntax error?

Discussion in 'Shaders' started by LittleRainGames, Sep 8, 2017.

  1. LittleRainGames

    LittleRainGames

    Joined:
    Apr 7, 2016
    Posts:
    97
    Just started to learn writing shaders, and I keep running into problems which seem non existent.

    I get this error...

    "Shader error in 'Normal Map': Parse error: syntax error, unexpected TVAL_ID at line 7"

    Every time I add this line into the properties....

    _Transparency ("Transparency", Range(0, 1)) = 1.0

    So I had typed it in, then got the issue, so I copied and pasted it from a shader that I had wrote watching a tutorial last night and I still get the issue. Yet there is nothing wrong in the other shader.

    Here is the full code, if you remove the _Transparency property, or even just change from a ranged float to a float everything is fine. So why am I getting this issue?

    Code (CSharp):
    1.  
    2. Shader "Custom/Normal Map" {
    3.  Properties {
    4.   _Color ("Color", Color) = (1, 1, 1, 1)
    5.   _MainTex ("Albedo (RGBA)", 2D) = "white"
    6.   _NormalTex ("Normal", 2D) = "white"
    7.   _NormalIntensity ("Normal Intensity", Float) = 1.0
    8.   //_Transparency ("Transparency", Range(0, 1)) = 1.0
    9.  }
    10.  SubShader{
    11.   Tags { "RenderType"="Opaque" }
    12.   LOD 200
    13.   pass{
    14.    CGPROGRAM
    15.    #pragma vertex vert
    16.    #pragma fragment frag
    17.    #include "UnityCG.cginc"
    18.  
    19.   //structs
    20.    struct appdata{
    21.     float4 vertex : POSITION;
    22.     float4 tangent : TANGENT;
    23.     float3 normal : NORMAL;
    24.     float2 uv : TEXCOORD0;
    25.    };
    26.    struct v2f {
    27.     float4 vertex : SV_POSITION;
    28.     float3 normal : NORMAL;
    29.     float2 uv : TEXCOORD0;
    30.     float3 tbn[3] : TEXCOORD1;
    31.    };
    32.    float4 _Color;
    33.    float4 _MainTex;
    34.    float4 _MainTex_ST;
    35.    float3 _NormalTex;
    36.    float3 _NormalTex_ST;
    37.    float _Transparency;
    38.  
    39.    v2f vert(appdata v){
    40.     v2f o;
    41.     o.vertex = UnityObjectToClipPos(v.vertex);
    42.     //o.uv = TRANSFORM_TEX(v.uv, _NormalTex);
    43.     o.normal = v.normal;
    44.     return o;
    45.    }
    46.    
    47.    fixed4 frag (v2f i) : SV_Target{
    48.     float3 normal = normalize(i.normal);
    49.     float3 nColor = (normal + 1) * 0.5;
    50.     return fixed4(nColor.rgb, 0);
    51.     //return _Color;
    52.    }
    53.   //declares
    54.   //Vertex
    55.   //fragment
    56.   //surface
    57.  
    58.   ENDCG
    59.   }
    60.  }
    61.  FallBack "Diffuse"
    62. }
    63.  
     
  2. Windcrosser

    Windcrosser

    Joined:
    Feb 3, 2018
    Posts:
    3
    most likely misspelling,
    for instance, I got the same error, and spent 2 hours running error check, only found out it was "Rnage" instead of ""Range" on the shader lab code part
     
  3. Windcrosser

    Windcrosser

    Joined:
    Feb 3, 2018
    Posts:
    3
    also, use

    float3 n1 = lerp (n0, float3 (0,0,1), (1 - _Norm));

    as to adjust your normal strength, instead of any linear method, otherwise, it wont work, since normal map is a vector.

    from the above line, where: n1 is the finalized normal after the strength adjustment.
    n0 is the normal map unpacked from the normal texture.
    _Norm is the strength value, can be defined as either half or float
     
  4. HakanaiVR

    HakanaiVR

    Joined:
    Jan 1, 2018
    Posts:
    6
    I'm not so sure. I am getting the same issue and can't figure out why it happens at all.

    Example, this gives the error:

    Code (csharp):
    1.  
    2.     Properties
    3.     {
    4.         _NoiseTex("Noise Texture", 2D) = "white"
    5.  
    6.         _SkyColour1("Sky Colour 1", Color) = (0.3, 0.6, 0.8)
    7.         _SkyColour2("Sky Colour 2", Color) = (0.0, 0.1, 0.4)
    8.         _SunColour("Sun Colour", Color) = (1.0, 0.7, 0.55)
    9.     }
    10.  
    But this works fine:

    Code (csharp):
    1.  
    2.     Properties
    3.     {
    4.         _SkyColour1("Sky Colour 1", Color) = (0.3, 0.6, 0.8)
    5.         _SkyColour2("Sky Colour 2", Color) = (0.0, 0.1, 0.4)
    6.         _SunColour("Sun Colour", Color) = (1.0, 0.7, 0.55)
    7.  
    8.         _NoiseTex("Noise Texture", 2D) = "white"
    9.     }
    10.  
    Apparently the declaration order matters, but I can't figure out why it should.
     
    zhuhaiyia1 and dccoo like this.
  5. thamkung275

    thamkung275

    Joined:
    Jan 20, 2021
    Posts:
    1
    SubShader {
    Tags { "DisableBatching" = "true" "FORCENOSHADOWCASTING" = "true" "IGNOREPROJECTOR" = "true" "IsEmissive" = "true" "LIGHTMODE" = "ALWAYS" "PreviewType" = "Plane" "QUEUE" = "Overlay+2147479647" "RenderType" = "Overlay" }
    GrabPass {
    "_1stPass"
    }
    Pass {
    Name "ColEffects"
    Tags { "DisableBatching" = "true" "FORCENOSHADOWCASTING" = "true" "IGNOREPROJECTOR" = "true" "IsEmissive" = "true" "LIGHTMODE" = "ALWAYS" "PreviewType" = "Plane" "QUEUE" = "Overlay+2147479647" "RenderType" = "Overlay" }
    Blend SrcAlpha OneMinusSrcAlpha, SrcAlpha OneMinusSrcAlpha
    ZTest Always
    ZWrite Off
    Cull Off
    GpuProgramID 38858
    Program "vp" {
    SubProgram "d3d11 " {
    "vs_4_0

    it error around Program "vp" {
    Parse error: syntax error, unexpected TVAL_ID, expecting TOK_SETTEXTURE or '}'
    PLS HELPP!
     
    lexajan likes this.
  6. Hyper_Engineering

    Hyper_Engineering

    Joined:
    Aug 23, 2018
    Posts:
    1
    You seem to be missing closing brackets.
     
  7. WangLLLK

    WangLLLK

    Joined:
    Sep 13, 2021
    Posts:
    1
    I got the same error! Did you figure it out?
     
  8. Michael_Swan

    Michael_Swan

    Joined:
    Aug 24, 2021
    Posts:
    59
    For me GLSL shader:

    Not work:
    _ScreenParamss("ScreenParams", Vec4) = (1920.0, 1080.0, 0.0, 0.0) // no Vec 4
    _ScreenParamss("ScreenParams", Float4) = (1920.0, 1080.0, 0.0, 0.0) // no Float4
    _ScreenParamss("ScreenParams", Vector) = (1920.0, 1080.0, 1/0/1920.0, 0.0 ) // no 1.0/1920

    Worked
    _ScreenParamss("ScreenParams", Vector) = (1920.0, 1080.0, 0.0, 0.0)
     
  9. HengshiKang

    HengshiKang

    Joined:
    Jun 28, 2022
    Posts:
    2
    Should be _MainTex ("Albedo (RGBA)", 2D) = "white"{}
     
    PrecisionCats and Sasha_Hulko like this.