Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unknown shader error

Discussion in 'Shaders' started by HelloJinxie, Nov 12, 2019.

  1. HelloJinxie

    HelloJinxie

    Joined:
    Nov 7, 2019
    Posts:
    20
    I am following THIS tutorial. And for some reason, its not working due to having an error for the second last "}" but if i remove it, it causes more issues. I'm just trying to recolor specific RGB elements.

    Code (CSharp):
    1. Shader "Custom/ColorTint"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Particle Texture", 2D) = "white" {}
    6.         _TintColorRed("Tint Color Red", Color) = (0.5,0.5,0.5,0.5)
    7.         _TintColorGreen("Tint Color Green", Color) = (0.5,0.5,0.5,0.5)
    8.         _TintColorBlue("Tint Color Blue", Color) = (0.5,0.5,0.5,0.5)
    9.     }
    10.     SubShader
    11.     {
    12.             Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
    13.             Blend SrcAlpha OneMinusSrcAlpha
    14.             AlphaTest Greater .01
    15.             ColorMask RGB
    16.             Cull Off Lighting Off ZWrite Off
    17.             BindChannels
    18.             {
    19.                 Bind "Color", color
    20.                 Bind "Vertex", vertex
    21.                 Bind "TexCoord", texcoord
    22.             }
    23.  
    24.             CGPROGRAM
    25.             #pragma vertex vert
    26.             #pragma fragment frag
    27.             //#pragma fragmentation ARB_presision_hunt_fastest
    28.             #pragma multi_compile_particles
    29.  
    30.             #include "UnityCG.cginc"
    31.  
    32.             sampler2D _MainTex;
    33.             fixed4 _TintColorRed;
    34.             fixed4 _TintColorGreen;
    35.             fixed4 _TintColorBlue;
    36.  
    37.             struct appdata_t
    38.             {
    39.                 float4 vertex : POSITION;
    40.                 float2 texcoord : TEXCOORD0;
    41.             }
    42.  
    43.             struct v2f
    44.             {
    45.                 float4 vertex : POSITION;
    46.                 float2 texcoord : TEXCOORD0;
    47.             }
    48.  
    49.             float4 _MainTex_ST;
    50.  
    51.             v2f vert(appdata_t v)
    52.             {
    53.                 v2f o;
    54.                 0.vertex = UnityObjectToClipPos(v.vertex);
    55.                 0.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
    56.                 return 0;
    57.             }
    58.  
    59.             simpler2D _CameraDepthTexture;
    60.             float _InvFade;
    61.  
    62.             fixed4 frag(v2f i) : COLOR
    63.             {
    64.                 float4 baseColor = tex2D(_MainTex, i.texcoord);
    65.                 float alpha = baseColor.a;
    66.                 baseColor = alpha * (baseColor.r * _TintColorRed + baseColor.g * _TintColorGreen + baseColor.b * _TintColorBlue);
    67.                 baseColor.a = 1.0f - step(alpha, 0.1);
    68.                 return baseColor;
    69.             }
    70.             ENDCG
    71.     }
    72.     FallBack "Diffuse"
    73. }
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    You're missing
    Pass
    and associated
    {}
    s.
     
  3. HelloJinxie

    HelloJinxie

    Joined:
    Nov 7, 2019
    Posts:
    20
    Why did it work fine in the video without one?

    Also should I just add this at the end of the code?

    Code (CSharp):
    1. Pass
    2. {
    3.  
    4. }
     
    Last edited: Nov 13, 2019
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    You should check the video you posted again... because it does have a Pass.
     
  5. HelloJinxie

    HelloJinxie

    Joined:
    Nov 7, 2019
    Posts:
    20
    I didn't even notice that! But now its saying
    "Parse error: Syntax error, unexpected $end" and the line that's the problem is the final "}"
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    You probably need another }

    You’ve got a litany of other errors after that too. Good luck.