Search Unity

How do I fix my sprite after aplying this unlit shader?

Discussion in 'Shaders' started by strepzdesign, Apr 5, 2019.

  1. strepzdesign

    strepzdesign

    Joined:
    Feb 28, 2018
    Posts:
    14
    I was trying to make my character glow once he is behind something, it worked out but now my player sprite is like this: Captura de Ecrã (53).png
    I followed this tutorial right here (
    ) here is the complete code for the shader from that video:

    Code (CSharp):
    1. Shader "N3K/AlwaysVisible"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Texture", 2D) = "white" {}
    6.         _Color("Visible", Color) = (0,0,0,0)
    7.        
    8.     }
    9.     SubShader
    10.     {
    11.         Tags { "Queue"="Transparent" }
    12.         LOD 100
    13.  
    14.         Pass{
    15.  
    16.             Cull Off
    17.             ZWrite Off
    18.             ZTest Always
    19.             CGPROGRAM
    20.             #pragma vertex vert
    21.             #pragma fragment frag
    22.             #include "UnityCG.cginc"
    23.             struct appdata
    24.             {
    25.                 float4 vertex : POSITION;
    26.            
    27.             };
    28.  
    29.             struct v2f
    30.             {
    31.            
    32.                 float4 vertex : SV_POSITION;
    33.             };
    34.             float4 _Color;
    35.             v2f vert (appdata v)
    36.             {
    37.                 v2f o;
    38.                 o.vertex = UnityObjectToClipPos(v.vertex);
    39.            
    40.                
    41.                 return o;
    42.             }
    43.            
    44.             fixed4 frag (v2f i) : SV_Target
    45.             {
    46.                
    47.                 return _Color;
    48.             }
    49.             ENDCG
    50.         }
    51.         Pass
    52.         {
    53.             CGPROGRAM
    54.             #pragma vertex vert
    55.             #pragma fragment frag
    56.            
    57.            
    58.             #include "UnityCG.cginc"
    59.  
    60.             struct appdata
    61.             {
    62.                 float4 vertex : POSITION;
    63.                 float2 uv : TEXCOORD0;
    64.             };
    65.  
    66.             struct v2f
    67.             {
    68.                 float2 uv : TEXCOORD0;
    69.            
    70.                 float4 vertex : SV_POSITION;
    71.             };
    72.  
    73.             sampler2D _MainTex;
    74.             float4 _MainTex_ST;
    75.            
    76.             v2f vert (appdata v)
    77.             {
    78.                 v2f o;
    79.                 o.vertex = UnityObjectToClipPos(v.vertex);
    80.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    81.                
    82.                 return o;
    83.             }
    84.            
    85.             fixed4 frag (v2f i) : SV_Target
    86.             {
    87.                 // sample the texture
    88.                 fixed4 col = tex2D(_MainTex, i.uv);
    89.            
    90.                 return col;
    91.             }
    92.             ENDCG
    93.         }
    94.     }
    95. }
    96.  
    plz help me find a solution, ty
     
  2. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    You have two problems. First, your first pass needs to sample your sprite to get the alpha information you need. Second, you need a Blend operation for each to make them transparent.
     
  3. strepzdesign

    strepzdesign

    Joined:
    Feb 28, 2018
    Posts:
    14
    How exactly do I do that? Its my first time working with shaders so Idk much