0
\$\begingroup\$

I get the following error

syntax error unexpected token vertex

I am still learning shaders so I can't really understand the reason for this error. How can I make this shader work?

enter Shader "Custom/VertAnimShader"
{
    Properties
    {
        _MainTex("Texture", 2D) = "white" {}
        _PosTex("Position texture", 2D) = "black" {}
        _NmlTex("Normal texture", 2D) = "white" {}
        _Length("Animator lengh", float) = 1
        _DT("Delta time", float) = 0
    }

    SubShader{
        Pass{
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma debug
            #include "UnityCG.cginc"

            #define ts _PosTex_TexelSize

            struct appdata
            {
                float2 uv : TEXTCOORD0;
            };

            struct v2f {
                float2 uv : TEXTCOORD0;
                float3 normal: TEXTCOORD1;
                float4  vertex : SV_POSITION;
            };

            sampler2D _MainTex, _PosTex, _NmlTex;
            float4 _PosTex_TexelSize;
            float _Length, _DT;

            v2f vert(appdata v, uint vid: SV_VertexID)
            {
                float t = (_Time.y - _DT) / _Length;
                t = fmod(t, 1.0);
                float x = (vid + 0.5) * ts.x;
                float y = t;
                float4 pos = tex2Dlod(_PosTex, float4(x, y, 0, 0));
                float4 normal = tex2Dlod(_NmlTex, float4(x, y, 0, 0));
                v2f o;
                o.vertex = UnityObjectToClipPos(pos);
                o.normal = UnityObjectToWorldNormal(normal);
                o.uv = v.uv;
                return o;
            }

            half4 frag(v2f i) : SV_TARGET
            {
                half diff = dot(i.normal, float3(0,1,0))*0.5 + 0.5;
                half4 col = tex2D(_MainTex, i.uv);
                return diff * col;
            }
            ENDCG
        }
    }
}
\$\endgroup\$
2
\$\begingroup\$
struct v2f {
    float2 uv : TEXTCOORD0;
    float3 normal: TEXTCOORD1;
    float4 position vertex : SV_POSITION;
};

There is a mistake in the last line, it needs to be

struct v2f {
    float2 uv : TEXCOORD0;
    float3 normal: TEXCOORD1;
    float4 vertex : SV_POSITION;
};

Also note that TEXTCOORD needs to be spelled TEXCOORD. The tutorial you are using seems to be quite terrible.

This is correctly written later in the tutorial.

In addition, you are missing a semicolon in the function vert: The line

o.uv = v.uv 

needs to be

o.uv = v.uv;

As of why ts is not defined, it's because you are missing a space character in your #define:

#define TS_PosTex_TexelSize

needs to be #define TS _PosTex_TexelSize.

\$\endgroup\$
  • \$\begingroup\$ Thanks for the reply but even after changing line I am still getting error \$\endgroup\$ – paul p Nov 24 '18 at 13:19
  • \$\begingroup\$ See my edit, there was also another error. \$\endgroup\$ – Tyyppi_77 Nov 24 '18 at 13:20
  • \$\begingroup\$ No problem, good luck with your learning! \$\endgroup\$ – Tyyppi_77 Nov 24 '18 at 13:31
  • \$\begingroup\$ Hello okay this is embarassing but after fixing every typos I am getting another error program 'vert': unknown input semantics TEXTCOORD/0 (on d3d11). I updated my question current code after fixing all typos \$\endgroup\$ – paul p Nov 24 '18 at 13:53
  • 1
    \$\begingroup\$ @paulp It seems that the tutorial you are using is absolute garbage. TEXTCOORD isn't valid, it needs to be spelled TEXCOORD. \$\endgroup\$ – Tyyppi_77 Nov 24 '18 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.