Custom Shader Giving Unexpected token error for period ' . '
So I was following along with this video and I have the same code as at around the 27th minute, 18th second: https://youtu.be/epixwRw80MM?t=27m18s
The above is from the video at the referenced moment
When I build in MonoDevelop or VS2017, there is no error. This is my code
However, when my console gives this error: Shader error in '.ShaderLive/Fixed Unlit': syntax error: unexpected token '.' at line 20 (on d3d11)
If I remove either of the . (periods) on the line , then other errors pop up. Any idea what I'm doing wrong?
Answer by AtGfx · Apr 27, 2017 at 12:10 PM
Here is your working shader :
Shader ".ShaderLive/Fixed Unlit"
{
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 pos : SV_POSITION;
};
v2f vert(appdata IN)
{
v2f OUT;
OUT.pos = mul(UNITY_MATRIX_MVP, IN.vertex);
return OUT;
}
fixed4 frag(v2f IN) :COLOR
{
return fixed4(1,0,0,1);
}
ENDCG
}
}
}
You made 2 mistakes in your code.
The first one, if you use some variables defined in UnityCG you have to include the header
#include "UnityCG.cginc"
And the second one
v2f OUT.pos = mul(UNITY_SHADER_MVP, IN.vertex);
does not really make sense : declare a struct, then initialize it.
Also, I think you want to use UNITY_MATRIX_MVP and not UNITY_SHADER_MVP.
Have fun ;)
Woah you're a life saver man! I realised I copied over the "UNITY_SHADER_$$anonymous$$VP" code incorrectly so that wasn't the problem. But the main two you pinpointed were correct on the dot and had been bugging me for days!! I don't know how it worked on the aforementioned tutorial. Anyway, thanks a lot!!