Search Unity

Alpha not working properly

Discussion in 'Shaders' started by HelloJinxie, Dec 6, 2019.

  1. HelloJinxie

    HelloJinxie

    Joined:
    Nov 7, 2019
    Posts:
    20
    My issue, is that its showing black blocks around the character



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

    HelloJinxie

    Joined:
    Nov 7, 2019
    Posts:
    20
    Bump!
    I still haven't figured out the issue!
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    What happens if you just use the texture’s alpha directly rather than using the step?