Home > OS >  Why is my custom shader code saying : Unexpected token 'uv'?
Why is my custom shader code saying : Unexpected token 'uv'?

Time:12-07

I watched b3agz's making minecraft in unity tutorial on episode 15 there was an error when i coded the shade saying unexpected token 'uv' please help.

Here is my code for it:

Shader "Minecraft/Blocks" { Properties { _MainTex("Block Texture Atlas", 2D) = "white" {} }

SubShader
{
    Tags{"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
    LOD 100
    Lighting Off

    Pass
    {
        CGPROGRAM
            #pragma vertex vertFunction
            #pragma fragment fragFunction
            #pragma target 2.0

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION:
                float2 uv : TEXCOORD0;
                float4 color : COLOR;
            };

            struct v2f
            {
                float4 vertex : SV_POSITION:
                float2 uv : TEXCOORD0;
                float4 color : COLOR;
            };

            sampler2D _MainTex;

            float GlobalLightLevel;

            v2f vertFunction(appdata v)
            {
                v2f o;

                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                o.color = v.color;

                return o;
            }

            fixed4 fragFunction(v2f i) : SV_Target
            {
                fixed4 col = tex2D(_MainTex, i.uv);
                float localLightLevel = clamp(GlobalLightLevel   i.color.a,0,1);
                clip(col.a - 1);
                col = lerp(col, float4(0,0,0,1), localLightLevel);

                return col;
            }

        ENDCG
    }
}

}

CodePudding user response:

Both of your struct definitions, appdata and v2f have a colon in place of a semi-colon for the float4 vertex.

The correct syntax would be:

struct appdata
{
    float4 vertex : POSITION;
    float2 uv : TEXCOORD0;
    float4 color : COLOR;
};
struct v2f
{
    float4 vertex : SV_POSITION;
    float2 uv : TEXCOORD0;
    float4 color : COLOR;
};
  • Related