Search Unity

[SOLVED] #include "unityCG.cginc" results in malformed include warning, breaks shader

Discussion in 'Shaders' started by Yandalf, Aug 5, 2015.

  1. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Hello everyone!
    I'm very new to shader programming and have been scouring the web for a while in order to get some effects.
    I am now trying to add a new pass from sample code to my shader, but the includes in this pass seem to break and give me this warning: Malformed #include (no start quote found): #include "UnityCG.cginc"
    I've been looking for obvious typos and such but couldn't find a thing.
    The errors occur in the Pass, I'm including the source code (cobbled together from various sources) below:

    Code (CSharp):
    1. Shader "Toon/Diffuse" {
    2.    
    3.     Properties
    4.     {
    5.         _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
    6.         _MainTex ("Base (RGB)", 2D) = "white" {}
    7.         _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {}
    8.         _RampPower ("Toon Ramp Power", Range(0.0,1)) =1
    9.         _RimColor ("Rim Color", Color) = (1,1,1,1)
    10.         _RimPower ("Rim Power", Range(0.1,10)) = 2.5
    11.        
    12.         _DiffuseTreshold ("Lighting Treshold", Range(-1.1,1)) = 0.1
    13.     }
    14.  
    15.     SubShader
    16.     {
    17.         Tags { "RenderType"="Opaque" "LightMode" = "ForwardBase"}
    18.         LOD 200
    19.    
    20.         CGPROGRAM
    21.         #pragma surface surf ToonRamp
    22.        
    23.         sampler2D _Ramp;
    24.         float _RampPower;
    25.         float2 uv_MainTex : TEXCOORD0;          
    26.         // custom lighting function that uses a texture ramp based
    27.         // on angle between light direction and normal
    28.         #pragma lighting ToonRamp exclude_path:prepass
    29.         inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten)
    30.         {
    31.             #ifndef USING_DIRECTIONAL_LIGHT
    32.             lightDir = normalize(lightDir);
    33.             #endif
    34.            
    35.             half d = dot (s.Normal, lightDir)*0.5 + 0.5;
    36.             half3 ramp = tex2D (_Ramp, float2(d,d)).rgb;
    37.             float power = _RampPower;
    38.             float neutralramp = 0.5;
    39.            
    40.             half4 c;
    41.             c.rgb = s.Albedo * _LightColor0.rgb * ((ramp * power) + (neutralramp * (1-power))) * (atten * 2);
    42.             c.rgb = s.Albedo * _LightColor0.rgb;
    43.             c.a = 0;
    44.             return c;
    45.         }
    46.        
    47.        
    48.         sampler2D _MainTex;
    49.         half4 _Color;
    50.         float4 _RimColor;
    51.         float _RimPower;
    52.        
    53.         struct Input
    54.         {
    55.             float2 uv_MainTex : TEXCOORD0;
    56.             float3 viewDir;
    57.         };
    58.        
    59.         void surf (Input IN, inout SurfaceOutput o)
    60.         {
    61.             half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    62.             o.Albedo = c.rgb;
    63.             half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
    64.             o.Emission = (_RimColor.rgb * c) * pow (rim, _RimPower);
    65.             o.Alpha = c.a;
    66.         }
    67.        
    68.         ENDCG
    69.        
    70.         Pass
    71.         {
    72.             Blend DstColor Zero
    73.             Fog { Mode Off}
    74.            
    75.             CGPROGRAM
    76.             #pragma target 3.0
    77.             #pragma vertex vert
    78.             #pragma fragment frag
    79.             #pragma multi_compile_fwdbase
    80.             #pragma fragmentoption ARB_precision_hint_fastest
    81.             #include “UnityCG.cginc“
    82.             #include “AutoLight.cginc“
    83.            
    84.             struct appdata
    85.             {
    86.                 fixed4 vertex : POSITION;
    87.                 fixed4 color : COLOR;
    88.             };
    89.            
    90.             struct v2f
    91.             {
    92.                 fixed4 pos : SV_POSITION;
    93.                 fixed4 color : TEXCOORD0;
    94.                 LIGHTING_COORDS(1, 2)
    95.             };
    96.            
    97.             v2f vert (appdata v)
    98.             {
    99.                 v2f o;
    100.                 o.pos = mul( UNITY_MATRIX_MVP, v.vertex);
    101.                 o.color = 1;
    102.                 TRANSFER_VERTEX_TO_FRAGMENT(o)
    103.                 return o;
    104.             }
    105.            
    106.             fixed4 frag(v2f i) : COLOR
    107.             {
    108.                 fixed atten = LIGHT_ATTENUATION(i);
    109.                 fixed4 c = i.color;
    110.                 c.rgb *= atten;
    111.                 return c;
    112.             }
    113.             ENDCG
    114.         }
    115.     }
    116.     Fallback "Diffuse"
    117. }
    118.  
     
  2. smd863

    smd863

    Joined:
    Jan 26, 2014
    Posts:
    292
    You're using the curly double open quote (“) instead of the regular quotation mark ("). Make sure you're using an IDE for writing code and not a word processor for writing prose. Some text editors can probably do both so make sure you're in the correct mode or it may be messing with your syntax (by adding the fancy quotation marks, etc...).
     
    Yandalf likes this.
  3. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Holy crap, that's it? :eek: I'd never realised that, damn you copy-pasted code!
    Thank you very much for the help, I'll make sure to never ever gloss over quotations again :D