Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by McCrow · Jun 20, 2014 at 12:14 PM · errorshadershader programming

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 ...

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image HarshadK · Jun 20, 2014 at 12:27 PM 0
Share

@$$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.

avatar image McCrow · Jun 22, 2014 at 11:08 AM 0
Share

@Harshad$$anonymous$$ & @meat5000 Thanks a lot !

Now I feel like a noob at all, but it now works fine! :D

avatar image meat5000 ♦ · Jun 22, 2014 at 11:08 AM 0
Share

No problem :) Please click the tick to accept the answer.

avatar image HarshadK · Jun 22, 2014 at 12:14 PM 0
Share

As I always say, ticking to accept the answer is the best way to say thank you to the answerer. :-)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges