Search Unity

Question Sprite transparent shader not transparent help please

Discussion in 'Shaders' started by Tarrag, Dec 18, 2020.

  1. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    215
    Hello all, I'm learning shaders (trying!) can someone please tell me what's wrong with my transparent sprite shader please?

    I'm trying to make all pixels alpha transparent (line 42).

    I also tried to change the color of all pixels in line 43 but nothing changed in the image fed.

    Thank you for your help !

    Code (CSharp):
    1. Shader "Unlit/CameraBackgroundWithSomeTransparency "
    2. {
    3.     Properties
    4.     {
    5.         _MainTex("_CurrentSpriteTexture", 2D) = "white" {}
    6.         _Color("Color",Color)= (0.2,1,0.2,1)
    7.     }
    8.     SubShader
    9.     {
    10.         Tags { "Queue" = "Transparent" "RenderType" = "Transparent" }
    11.         Blend SrcAlpha OneMinusSrcAlpha
    12.         ZWrite Off
    13.         Pass
    14.         {
    15.             CGPROGRAM
    16.             #pragma vertex vert
    17.             #pragma fragment frag
    18.             #include "UnityCG.cginc"
    19.             struct appdata
    20.             {
    21.                 float4 vertex : POSITION;
    22.                 float2 uv : TEXCOORD0;
    23.             };
    24.             struct v2f
    25.             {
    26.                 float2 uv : TEXCOORD0;
    27.                 float4 vertex : SV_POSITION;
    28.             };
    29.             sampler2D _MainTex;
    30.             fixed4 _Color;
    31.             float4 _MainTex_ST;
    32.             v2f vert (appdata v)
    33.             {
    34.                 v2f o;
    35.                 o.vertex = UnityObjectToClipPos(v.vertex);
    36.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    37.                 return o;
    38.             }
    39.             fixed4 frag (v2f i) : COLOR
    40.             {
    41.                 fixed4 col = tex2D(_MainTex, i.uv);
    42.                 col.a = 0;
    43.                 //col.rgb *= _Color;//I tried this but it didn't change any colors for the background image
    44.                 return col;
    45.             }
    46.             ENDCG
    47.         }
    48.     }
    49. }