- Home /
why there is a parsing error at the END ?
I really don't know why I've got that error. probably a newbie error. it's in my toon shader I build. I really need your help on this one.
Shader "Custom/toony" { Properties { _Color ("Main Color", Color) = (0.5,0.5,0.5,1) _MainTex ("Texture", 2D) = "white" {} _BumpMap ("Bumpmap", 2D) = "bump" {} _RimColor ("Rim Color", Color) = (0.26,0.19,0.16,0.0) _RimPower ("Rim Power", Range(0.5,8.0)) = 3.0 _Detail ("Detail", 2D) = "gray" {} _Tooniness ("Tooniness", Range(0.1,20)) = 4 _ColorMerge ("Color Merge", Range(0.1,20)) = 8 _Outline ("Outline", Range(0,1)) = 0.4 }
SubShader { Tags { "RenderType"="Opaque" } LOD 600 Pass { Cull Front Lighting Off ZWrite On Tags { "LightMode"="ForwardBase" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct a2v
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float3 tangent : TANGENT;
};
struct v2f
{
float4 pos : POSITION;
};
float _Outline;
v2f vert (a2v v)
{
v2f o;
float4 pos = mul( UNITY_MATRIX_MV, v.vertex);
float3 normal = mul( (float3x3)UNITY_MATRIX_IT_MV, v.normal);
normal.z = -0.4;
pos = pos + float4(normalize(normal),0) * _Outline;
o.pos = mul(UNITY_MATRIX_P, pos);
return o;
}
float4 frag (v2f IN) : COLOR
{
return float(0);
}
ENDCG
}
Pass {
Cull Back
Lighting On
Tags { "LightMode"="ForwardAdd" }
Blend One One
CGPROGRAM
#pragma exclude_renderers xbox360 flash
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform float4 _LightColor0;
sampler2D _MainTex;
sampler2D _Bump;
float4 _MainTex_ST;
float4 _Bump_ST;
struct a2v
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
float4 tangent : TANGENT;
};
struct v2f
{
float4 pos : POSITION;
float2 uv : TEXCOORD0;
float2 uv2 : TEXCOORD1;
float3 lightDirection;
};
v2f vert (a2v v)
{
v2f o;
TANGENT_SPACE_ROTATION;
o.lightDirection = mul(rotation, ObjSpaceLightDir(v.vertex));
o.pos = mul( UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
o.uv2 = TRANSFORM_TEX (v.texcoord, _Bump);
return o;
}
float4 frag(v2f i) : COLOR
{
float4 c = tex2D (_MainTex, i.uv);
float3 n = UnpackNormal(tex2D (_Bump, i.uv2));
float3 lightColor = float3(0);
float lengthSq = dot(i.lightDirection, i.lightDirection);
float atten = 1.0 / (1.0 + lengthSq * unity_LightAtten[0].z);
//Angle to the light
float diff = saturate (dot (n, normalize(i.lightDirection)));
lightColor += _LightColor0.rgb * (diff * atten);
c.rgb = lightColor * c.rgb * 2;
return c;
}
ENDCG
}
CGPROGRAM
#pragma surface surf Toon
#include "UnityCG.cginc"
#ifndef LIGHTING_INCLUDED
#define LIGHTING_INCLUDED
struct SurfaceOutput {
fixed3 Albedo;
fixed3 Normal;
fixed3 Emission;
half Specular;
fixed Gloss;
fixed Alpha;
};
#ifndef USING_DIRECTIONAL_LIGHT
#if defined (DIRECTIONAL_COOKIE) || defined (DIRECTIONAL)
#define USING_DIRECTIONAL_LIGHT
#endif
#endif
#endif
struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
float2 uv_Detail;
float3 viewDir;
};
float4 _Color;
sampler2D _MainTex;
sampler2D _BumpMap;
float4 _RimColor;
float _RimPower;
sampler2D _Detail;
float _Tooniness;
float _Outline;
float _ColorMerge;
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Normal = UnpackNormal( tex2D(_BumpMap, IN.uv_BumpMap));
half edge = saturate(dot (o.Normal, normalize(IN.viewDir)));
o.Albedo = (floor(c.rgb*_ColorMerge)/_ColorMerge) * edge*_Color.rgb;
o.Alpha = c.a;
o.Albedo *= tex2D (_Detail, IN.uv_Detail).rgb * 2;
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
o.Emission = _RimColor.rgb * pow (rim, _RimPower);
}
fixed4 LightingToon(SurfaceOutput s, half3 lightDir, half atten){
fixed diff = max (0, dot (s.Normal, lightDir));
fixed4 c;
diff = floor(diff * _Tooniness)/_Tooniness;
c.rgb = s.Albedo * _LightColor0.rgb * (diff * atten * 2);
c.a = s.Alpha;
return c;
}
ENDCG
Fallback "Diffuse"
}
} ^ | the error is right there ...
Answer by meat5000 · Jun 20, 2014 at 12:15 PM
Move Fallback "Diffuse" to underneath the curly brace below it.
You kinda pointed to the wrong spot for the error :P
ENDCG
Fallback "Diffuse" <- Error was here
}
}
Do This:
ENDCG
}
Fallback "Diffuse"
}
I don't write shaders. I simply compared it to another shader with a fallback.
@$$anonymous$$cCrow just for the heads up, parsing errors are caused when compiler is unable to parse the code, which can be caused due to missing of brackets or something of that sort but to generalize it is when your code does not conform to the syntax rules.
In your case it was with the bracket where compiler was expecting a bracket after ENDCG.
No problem :) Please click the tick to accept the answer.
As I always say, ticking to accept the answer is the best way to say thank you to the answerer. :-)
Your answer
![](https://koobas.hobune.stream/wayback/20220613152023im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Shader error: incorrect number of arguments to numeric-type constructor 2 Answers
[Need Help of a expert shader user] How to make following shaders to Fallback to "Diffuse"? 1 Answer
Updating a shader from Unity 3.3 0 Answers
UnityObjectToClipPos is inverted? 0 Answers
How to add metallic and smoothness to a frag shader? 1 Answer