Hello community!
I’m relatively new to shader. I’ve authored some shaders and now trying to organize my code for easy maintenance. So I decided to write a macro, everything looks OK to me but compiler gives me wired error and I can’t understand why it says so.
The error is
Shader error in 'Some/Test/Shader': syntax error: unexpected token '}' at Assets/TestInclude.cginc(32) (on glcore)
Here’s my .cginc file:
struct appdata {
float4 vertex : POSITION;
float4 color : COLOR;
half2 uv0 : TEXCOORD0;
};
struct v2f {
float4 vertex : POSITION;
float4 color : COLOR;
half2 uv0 : TEXCOORD0;
};
v2f vert (appdata vertexInput) {
v2f vertexOutput;
vertexOutput.vertex = UnityObjectToClipPos(vertexInput.vertex);
vertexOutput.uv0 = vertexInput.uv0;
vertexOutput.color = vertexInput.color;
return vertexOutput;
}
#define SHADER_VARIABLES \
sampler2D _MainTex; \
float4 _Tint;
#define SHADER_FRAGMENT_FUNC(ComputeFragmentCode) \
float4 frag(v2f vertexOutput) : SV_Target { \
float4 src = tex2D(_MainTex, vertexOutput.uv0); \
src.rgb = src.rgb * vertexOutput.color.rgb * _Tint.rgb; \
src.a = src.a * vertexOutput.color.a * _Tint.a; \
ComputeFragmentCode \
return src; \
}
#define BODY(ComputeFragmentCode) \
SHADER_VARIABLES \
SHADER_FRAGMENT_FUNC(ComputeFragmentCode)
And here’s .shader file:
Shader "Some/Test/Shader"
{
Properties
{
[Header(Properties)]
_MainTex ("Texture", 2D) = "white" {}
_Tint("Tint", Color) = ( 1, 1, 1, 1 )
}
SubShader
{
Tags
{
"IgnoreProjector" = "True"
"Queue" = "Transparent"
"RenderType" = "Transparent"
"ForceNoShadowCasting" = "True"
"PreviewType" = "Plane"
}
ZWrite Off
ZTest Off
Lighting Off
Cull Off
Fog { Mode Off }
Pass {
BlendOp Add
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
#include "TestInclude.cginc"
BODY( /\* nothing to compute here \*/ )
ENDCG
}
}
Fallback "Sprites/Default"
}
Thanks in advance!