Search Unity

Why do I get a "syntax error: unexpected token 'sampler2D'" or "redefinition of 'float4'".

Discussion in 'Scripting' started by NotAlwaysCoding, Dec 23, 2019.

  1. NotAlwaysCoding

    NotAlwaysCoding

    Joined:
    Sep 1, 2018
    Posts:
    7
    Hello I get this error I don't know why, I followed a tutorial about dissolve effect because I am new on shaders, I did everything, but my shader doesn't works in my material and I think it's because of this error, when I change the order of sampler2D with float between the lines, the error changes too for a "redefinition of 'float4'.
    Code (CSharp):
    1. Shader "Unlit/Dissolve"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Texture", 2D) = "white" {}
    6.         _DisolveTexture("Disolve Texture", 2D) = "white" {}
    7.         _DisolveY("Current Y of the disolve effect", float) = 0
    8.         _DisolveSize("Size of the effect", float) = 2
    9.         _StartingY("Starting point of the effect", float) = -10
    10.     }
    11.     SubShader
    12.     {
    13.         Tags { "RenderType"="Opaque" }
    14.         LOD 100
    15.  
    16.         Pass
    17.         {
    18.             CGPROGRAM
    19.             #pragma vertex vert
    20.             #pragma fragment frag
    21.  
    22.             #include "UnityCG.cginc"
    23.  
    24.             struct appdata
    25.             {
    26.                 float4 vertex : POSITION;
    27.                 float2 uv : TEXCOORD0;
    28.             };
    29.  
    30.             struct v2f
    31.             {
    32.                 float2 uv : TEXCOORD0;
    33.                 float4 vertex : SV_POSITION;
    34.                 float3 worldPos : TEXCOORD1;
    35.             }
    36.  
    37.             sampler2D _MainTex;
    38.             float4 _MainTex_ST;
    39.             sampler2D _DisolveTexture;
    40.             float _DisolveY;
    41.             float _DisolveSize;
    42.             float _StartingY;
    43.            
    44.  
    45.             v2f vert (appdata v)
    46.             {
    47.                 v2f o;
    48.                 o.vertex = UnityObjectToClipPos(v.vertex);
    49.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    50.                 o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz
    51.                 return o;
    52.             }
    53.  
    54.             fixed4 frag (v2f i) : SV_Target
    55.             {
    56.                 float transition = _DisolveY - i.worldPos.y;
    57.                 clip(_StartingY + (transition + (tex2D(_DisolveTexture,i.uv))* _DisolveSize))
    58.                 // sample the texture
    59.                 fixed4 col = tex2D(_MainTex, i.uv);
    60.                
    61.                 clip();
    62.                 return col;
    63.             }
    64.             ENDCG
    65.         }
    66.     }
    67. }
    68.  
     
  2. aaro4130

    aaro4130

    Joined:
    Jul 15, 2010
    Posts:
    420
    You're missing a semicolon at the closing brace of struct v2f
     
unityunity