Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Cubicle · Apr 29, 2016 at 06:30 AM · errorshaderscript.

All C# Shader Scripts giving CS 8025 Parsing Error.

I've created basic scripts using Project create->C#Script, so I know it works. But, whenever I attempt to use any Shader script, I get the CS8025 Parsing Error for the -- Shader "Name" { -- portion on every Shader Script I attempt to use. I've played with the { } brackets, but since it wasn't working, I went searching for other Shader scripts. Each Shader script gave me the same error. So far, I've tried 4 Shader Scripts, all with red ! errors. I'm using Unity v5.3.4f1 and these scripts have been used by others.

Am I bugged, or are { } brackets actually missing?

Below are 2 scripts I've tried, with links to their source.

 // WATCH FULL EXPLANATION ON YOUTUBE-VIDEO: https://www.youtube.com/watch?v=3qBDTh9zWrQ 

 Shader "Our Toonshader Vol. 3" {
   Properties {
 _Color ("Diffuse Material Color", Color) = (1,1,1,1) 
 _UnlitColor ("Unlit Color", Color) = (0.5,0.5,0.5,1)
 _DiffuseThreshold ("Lighting Threshold", Range(-1.1,1)) = 0.1
 _SpecColor ("Specular Material Color", Color) = (1,1,1,1) 
 _Shininess ("Shininess", Range(0.5,1)) = 1    
 _OutlineThickness ("Outline Thickness", Range(0,1)) = 0.1
 _MainTex ("Main Texture", 2D) = "AK47" {}
     
   }
   
  SubShader {
  Pass {
 Tags{ "LightMode" = "ForwardBase" }
     // pass for ambient light and first light source
   
       CGPROGRAM
       
       #pragma vertex vert 
       //tells the cg to use a vertex-shader called vert
       #pragma fragment frag
       //tells the cg to use a fragment-shader called frag
       
       //== User defined ==//
       
       //TOON SHADING UNIFORMS
       uniform float4 _Color;
       uniform float4 _UnlitColor;
       uniform float _DiffuseThreshold;
       uniform float4 _SpecColor;
       uniform float _Shininess;
       uniform float _OutlineThickness;
   
       
       //== UNITY defined ==//
       uniform float4 _LightColor0;
       uniform sampler2D _MainTex;
       uniform float4 _MainTex_ST;          
       
       struct vertexInput {
           
       //TOON SHADING VAR
       float4 vertex : POSITION;
       float3 normal : NORMAL;
       float4 texcoord : TEXCOORD0;
            
       };
       
       struct vertexOutput {
            
            float4 pos : SV_POSITION;
            float3 normalDir : TEXCOORD1;
            float4 lightDir : TEXCOORD2;
            float3 viewDir : TEXCOORD3;
           float2 uv : TEXCOORD0; 
       };
       
       vertexOutput vert(vertexInput input)
       {
           vertexOutput output;
           
           //normalDirection
           output.normalDir = normalize ( mul( float4( input.normal, 0.0 ), _World2Object).xyz );
            
           //World position
           float4 posWorld = mul(_Object2World, input.vertex);
           
           //view direction
           output.viewDir = normalize( _WorldSpaceCameraPos.xyz - posWorld.xyz ); //vector from object to the camera
           
           //light direction
           float3 fragmentToLightSource = ( _WorldSpaceCameraPos.xyz - posWorld.xyz);
           output.lightDir = float4(
               normalize( lerp(_WorldSpaceLightPos0.xyz , fragmentToLightSource, _WorldSpaceLightPos0.w) ),
               lerp(1.0 , 1.0/length(fragmentToLightSource), _WorldSpaceLightPos0.w)
           );
           
           //fragmentInput output;
           output.pos = mul( UNITY_MATRIX_MVP, input.vertex );  
           
           //UV-Map
           output.uv =input.texcoord;
           
           return output;
         
       }
       
       float4 frag(vertexOutput input) : COLOR
       {

 float nDotL = saturate(dot(input.normalDir, input.lightDir.xyz)); 
         
 //Diffuse threshold calculation
 float diffuseCutoff = saturate( ( max(_DiffuseThreshold, nDotL) - _DiffuseThreshold ) *1000 );
         
 //Specular threshold calculation
 float specularCutoff = saturate( max(_Shininess, dot(reflect(-input.lightDir.xyz, input.normalDir), input.viewDir))-_Shininess ) * 1000;
         
 //Calculate Outlines
 float outlineStrength = saturate( (dot(input.normalDir, input.viewDir ) - _OutlineThickness) * 1000 );
     
         
 float3 ambientLight = (1-diffuseCutoff) * _UnlitColor.xyz; //adds general ambient illumination
 float3 diffuseReflection = (1-specularCutoff) * _Color.xyz * diffuseCutoff;
 float3 specularReflection = _SpecColor.xyz * specularCutoff;
     
 float3 combinedLight = (ambientLight + diffuseReflection) * outlineStrength + specularReflection;
         
 return float4(combinedLight, 1.0); // + tex2D(_MainTex, input.uv); // DELETE LINE COMMENTS & ';' TO ENABLE TEXTURE
     

       }
       
       ENDCG
   
      }

   
   }

  } 

There's one. Here's another that I pulled from https://www.assetstore.unity3d.com/en/#!/content/21288.

 Shader "TSF/Base1" 
 {
     Properties 
 {
     [MaterialToggle(_TEX_ON)] _DetailTex ("Enable Detail texture", Float) = 0     //1
     _MainTex ("Detail", 2D) = "white" {}                                        //2
     _ToonShade ("Shade", 2D) = "white" {}                                          //3
     [MaterialToggle(_COLOR_ON)] _TintColor ("Enable Color Tint", Float) = 0     //4
     _Color ("Base Color", Color) = (1,1,1,1)                                    //5    
     [MaterialToggle(_VCOLOR_ON)] _VertexColor ("Enable Vertex Color", Float) = 0//6        
     _Brightness ("Brightness 1 = neutral", Float) = 1.0                            //7    
 }
   
 Subshader 
 {
     Tags { "RenderType"="Opaque" }
     LOD 250
     ZWrite On
        Cull Back
     Lighting Off
     Fog { Mode Off }
     
     Pass 
     {
         Name "BASE"
         CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             #pragma fragmentoption ARB_precision_hint_fastest
             #include "UnityCG.cginc"
             #pragma glsl_no_auto_normalization
             #pragma multi_compile _TEX_OFF _TEX_ON
             #pragma multi_compile _COLOR_OFF _COLOR_ON

             
             #if _TEX_ON
             sampler2D _MainTex;
             half4 _MainTex_ST;
             #endif
             
             struct appdata_base0 
             {
                 float4 vertex : POSITION;
                 float3 normal : NORMAL;
                 float4 texcoord : TEXCOORD0;
             };
             
              struct v2f 
              {
                 float4 pos : SV_POSITION;
                 #if _TEX_ON
                 half2 uv : TEXCOORD0;
                 #endif
                 half2 uvn : TEXCOORD1;
              };
            
             v2f vert (appdata_base0 v)
             {
                 v2f o;
                 o.pos = mul ( UNITY_MATRIX_MVP, v.vertex );
                 float3 n = mul((float3x3)UNITY_MATRIX_IT_MV, normalize(v.normal));
                 normalize(n);
                 n = n * float3(0.5,0.5,0.5) + float3(0.5,0.5,0.5);
                 o.uvn = n.xy;
                  #if _TEX_ON
                 o.uv = TRANSFORM_TEX ( v.texcoord, _MainTex );
                 #endif
                 return o;
             }

               sampler2D _ToonShade;
             fixed _Brightness;
             
             #if _COLOR_ON
             fixed4 _Color;
             #endif
             
             fixed4 frag (v2f i) : COLOR
             {
                 #if _COLOR_ON
                 fixed4 toonShade = tex2D( _ToonShade, i.uvn )*_Color;
                 #else
                 fixed4 toonShade = tex2D( _ToonShade, i.uvn );
                 #endif
                 
                 #if _TEX_ON
                 fixed4 detail = tex2D ( _MainTex, i.uv );
                 return  toonShade * detail*_Brightness;
                 #else
                 return  toonShade * _Brightness;
                 #endif
             }
         ENDCG
     }
 }
 Fallback "Legacy Shaders/Diffuse"
 }

Comment
Add comment · Show 3
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 meat5000 ♦ · Apr 29, 2016 at 07:22 AM 0
Share

Toonshader works fine for me. $$anonymous$$ake sure the filename is "Our Toonshader Vol. 3".

It may not compile properly until you have done this for ALL the new shaders you have added, na$$anonymous$$g them as the name is designated in the scripts.

avatar image tanoshimi meat5000 ♦ · Apr 29, 2016 at 08:28 AM 1
Share

Just to clarify - shaders don't care about the filename, it's only C# scripts where the class name needs to match the filename.

avatar image meat5000 ♦ tanoshimi · Apr 29, 2016 at 09:43 AM 0
Share

Ok fair play. Last time I wrote a shader though, I did encounter some problems when I came to use it as a result of an incorrect name. It wasnt a compile error. I'll have to go back and investigate.

2 Replies

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

Answer by tanoshimi · Apr 29, 2016 at 08:30 AM

I suspect the cause of your problem is explained somewhat in your description "C# Shader Scripts"... shaders are not C# scripts, and if you're starting off writing a shader by going to project -> Create C# script, you've already gone wrong.

You should go to Project -> Create Shader to input code for a shader.

Comment
Add comment · 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
0

Answer by Cubicle · Apr 29, 2016 at 02:43 PM

@tanoshimi, thank you! That was the issue. I was using C# instead of .shader in an attempt to add shaders. I just tested the scripts/shaders and they work fine. Thank you @meat5000 for chiming in!

----Solved

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Shader compiler error - failed to read correct magic number 2 Answers

Errors with ENDCG in shaders 1 Answer

Parse Error on OutlinedDiffuse Shader 0 Answers

Is it possible to use scripts without MonoBehaviour on GameObjects? 1 Answer

Prefabs made in Unity are insanely slow, and don't show textures. 0 Answers


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