Shader error: Parse error: syntax error

Shader “Custom/green” {
SubShader {
Tags { “RenderType”=“Opaque” }
LOD 200

		CGPROGRAM

		#pragma vertex green

		struct C2E1v_Output {
			float4 position : POSITION;
			float4 colour : COLOR;
		};

		C2E1v_Output green (float2 position : POSITION) {
			Output OUT;

			OUT.position = float4(position, 0, 1, 0);
			OUT.color = float4(0, 1, 0, 1);

			return OUT;
		}
		ENDCG
	}  
}

The error is on line 24 and I can’t for the life of me work it why it is erroring.

Hello,

CGPROGRAM … ENDCG has to be enclosed by Pass { }

Another issue is that “Both vertex and fragment programs must be present in a shader snippet.” and you have defined only the first one.

Shader error messages are often a bit cryptic, so don’t pay too much attention to the line number stated. In fact, you have lots of unrelated errors:

  • You haven’t defined a Pass {}
  • You haven’t defined a fragment function, i.e. #pragma fragment frag
  • You haven’t defined the Output structure used on line 16. I suspect you meant to use the C2E1v_Output structure.
  • On line 18, position is a float2 vector, but you’re trying to use it as the first float parameter to the float4 constructor

I recommend you refer to Unity - Manual: HLSL in Unity for more information on how to write a simple vert/frag shader.