Don't know how to enable alpha using mobile shader

I am new to unity and am developing for iPhone. I come from writing engines on both ios and Android. So I am well acquainted with writing shaders and render context for Alpha. I just don’t know how this works in Unity.

If I switch to the standard shader, I see the texture alpha kick on in the editor. But if I switch to mobile diffuse, I don’t see any alpha. I look at the shaders and sure enough, the shader is outputting the alpha.

So it must be a context issue. How do I enable alpha? I tried this with a custom shader:

    SubShader {
         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
        
        // Tags { "RenderType"="Opaque" }
        LOD 200
       
        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input {
            float2 uv_MainTex;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

        void surf (Input IN, inout SurfaceOutputStandard o) {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo =  c.rgb;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG
    }

Still no alpha (I haven’t actually sent this to a device, this is just what I am seeing in the editor–which I am assuming I should be able to see the alpha, correct?) What am I doing wrong here?
Thanks in advance

I’m no shader expert but I think you need to specify a blend mode, something like:

Blend SrcAlpha OneMinusSrcAlpha

I tested that. Still don’t see it. So the code now reads:

SubShader {
         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
Blend SrcAlpha OneMinusSrcAlpha
    
        // Tags { "RenderType"="Opaque" }
        LOD 200

How about adding something like:

#pragma surface surf Lambert alpha

Just after:

CGPROGRAM

I’m just guessing here, so sorry if I’m wasting your time a bit.

That is actually closer–thank you! Though I had to change it slightly to:

#pragma surface surf Standard alpha

The alpha has kicked on, but I still see the specular. This seems to be the right direction though.

Okay, this works:

#pragma surface surf Standard alpha:fade

However, I’m surprised this was required. This seems surprisingly technical to get alpha context kicked on. But, I can’t speak authoritive. I’ve now used Unity for approximately 3 hours. :wink:

1 Like

Excellent - glad you got it working!