Strange background color instead of alpha

HI

I am using custom shader which is build from unity standart sprite shader. Instead of transparent background I see orange color. Any ideas what I am doing wrong ? Thank you in advance for help. :slight_smile:

// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)

Shader "EgidCustom/Pulsing"
{
    Properties
    {
        [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
        _Color ("Tint", Color) = (1,1,1,1)
        [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
        [HideInInspector] _RendererColor ("RendererColor", Color) = (1,1,1,1)
        [HideInInspector] _Flip ("Flip", Vector) = (1,1,1,1)
        [PerRendererData] _AlphaTex ("External Alpha", 2D) = "white" {}
        [PerRendererData] _EnableExternalAlpha ("Enable External Alpha", Float) = 0
    }

    SubShader
    {
        Tags
        {
            "Queue"="Transparent"
            "IgnoreProjector"="True"
            "RenderType"="Transparent"
            "PreviewType"="Plane"
            "CanUseSpriteAtlas"="True"
        }

        Cull Off
        Lighting Off
        ZWrite Off
        Blend One OneMinusSrcAlpha

        Pass
        {
        CGPROGRAM
            #pragma vertex SpriteVert
            #pragma fragment SpriteFrag
            #pragma target 2.0
            #pragma multi_compile_instancing
            #pragma multi_compile _ PIXELSNAP_ON
            #pragma multi_compile _ ETC1_EXTERNAL_ALPHA
            #include "UnitySprites.cginc"

            float4 SpriteFrag(v2f_img i):Color
            {
                fixed4 color = tex2D (_MainTex, i.uv);

                #if ETC1_EXTERNAL_ALPHA
                // get the color from an external texture (usecase: Alpha support for ETC1 on android)
                color.a = tex2D (_AlphaTex, i.uv).r;
                #endif //ETC1_EXTERNAL_ALPHA

                return color;
            }

        ENDCG
        }
    }
}

I’m no shader expert, but shouldn’t the blend mode be: Blend **SrcAlpha** OneMinusSrcAlpha

?

1 Like

I tryed to replace on with SrcAlpha, but result was same.

does it work fine with default sprite shader?

this works for me, had to rename to SpriteFrag2 was getting some duplicate error,

            #pragma fragment SpriteFrag2
            #pragma target 2.0
            #pragma multi_compile_instancing
            #pragma multi_compile _ PIXELSNAP_ON
            #pragma multi_compile _ ETC1_EXTERNAL_ALPHA
            #include "UnitySprites.cginc"

            float4 SpriteFrag2(v2f i):Color
            {
                fixed4 color = tex2D(_MainTex, i.texcoord);
                #if ETC1_EXTERNAL_ALPHA
                    fixed4 alpha = tex2D (_AlphaTex, i.texcoord);
                    color.a = lerp (color.a, alpha.r, _EnableExternalAlpha);
                #endif
                color.rgb*=color.a; // this or either, Blend SrcAlpha OneMinusSrcAlpha
                return color;
            }
1 Like

Yes, it works with default sprite shader. Default sprite shader does not have fragment function. (Or is somehow hidden, really dont know how it works :slight_smile: ) Default sprite shader looks like code I posted but withou SpriteFrag function. But I need this function becouse I want do some effects on sprite :slight_smile:

Perfect. Thank you very much. For helping me out.