How to add transparency to a shader!?

I want to make it so that this shader can read the alpha properties from a texture and apply them. I cant seem to get it to work. :frowning: The shader is below. Please help!

Shader "Planet" {
    Properties {
      _MainTex ("Diffuse(RGB) Spec(A)", 2D) = "white" {}
      _BumpMap ("Bumpmap", 2D) = "bump" {}
      _RimColor ("Rim Color", Color) = (0.26,0.19,0.16,0.0)
      _RimPower ("Rim Power", Range(0.5,8.0)) = 3.0
      _SpecColor ("Specular Color", Color) = (0.5,0.5,0.5,1)
   _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 
    }
    SubShader {
      Tags { "RenderType" = "Opaque" }
      CGPROGRAM
      
       #pragma surface surf SimpleSpecular
   float _Shininess;
   
      half4 LightingSimpleSpecular (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
          half3 h = normalize (lightDir + viewDir);
          half diff = max (0, dot (s.Normal, lightDir));
          float nh = max (0, dot (s.Normal, h));
          float spec = pow (nh, 48.0);
          half4 c;
          c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec * s.Alpha * _Shininess * _SpecColor) * (atten * 2);
          c.a = s.Alpha;
          return c;
      }
            
      struct Input {
          float2 uv_MainTex;
          float2 uv_BumpMap;
          float3 viewDir;
      };
      sampler2D _MainTex;
      sampler2D _BumpMap;
      float4 _RimColor;
      float _RimPower;
      
      void surf (Input IN, inout SurfaceOutput o) {
          o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
          o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
          half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
          o.Emission = _RimColor.rgb * pow (rim, _RimPower);
          o.Alpha = tex2D (_MainTex, IN.uv_MainTex).a;
      }
      ENDCG
    } 
    Fallback "Diffuse"
  }

I took a look at your shader and added alpha to it. I also optimized the fact that you sample your texture twice, once for rgb and once for your alpha. It’s better to store the tex2D in a fixed4, so you only need to sample your texture once.

the ‘alpha’ keyword was added and the RenderType was set to ‘Transparent’

Here’s your new shader:

Shader "Planet" {
    Properties {
      _MainTex ("Diffuse(RGB) Spec(A)", 2D) = "white" {}
      _BumpMap ("Bumpmap", 2D) = "bump" {}
      _RimColor ("Rim Color", Color) = (0.26,0.19,0.16,0.0)
      _RimPower ("Rim Power", Range(0.5,8.0)) = 3.0
      _SpecColor ("Specular Color", Color) = (0.5,0.5,0.5,1)
   _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 
    }
    SubShader {
      Tags { "RenderType" = "Transparent" }
      CGPROGRAM

       #pragma surface surf SimpleSpecular alpha
   float _Shininess;

      half4 LightingSimpleSpecular (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
          half3 h = normalize (lightDir + viewDir);
          half diff = max (0, dot (s.Normal, lightDir));
          float nh = max (0, dot (s.Normal, h));
          float spec = pow (nh, 48.0);
          half4 c;
          c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec * s.Alpha * _Shininess * _SpecColor) * (atten * 2);
          c.a = s.Alpha;
          return c;
      }

      struct Input {
          float2 uv_MainTex;
          float2 uv_BumpMap;
          float3 viewDir;
      };
      sampler2D _MainTex;
      sampler2D _BumpMap;
      float4 _RimColor;
      float _RimPower;

      void surf (Input IN, inout SurfaceOutput o) {
		  fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
          o.Albedo = c.rgb;
          o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
          half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
          o.Emission = _RimColor.rgb * pow (rim, _RimPower);
          o.Alpha = c.a;
      }
      ENDCG
    } 
    Fallback "Diffuse"
  }

Feel free to mark as answered if this is what you need.

Cheers :wink: