Search Unity

How to add an alpha mask to this shader ?

Discussion in 'Scripting' started by yellowelephant, Aug 7, 2014.

  1. yellowelephant

    yellowelephant

    Joined:
    Aug 7, 2014
    Posts:
    7
    I'm running out of ideas and everything I tried so far just causes errors.
    DAE have an idea of how to add an alpha mask (texture, b/w) to this shader (like a cutout)?
    I'm starting to lose my mind.

    Code (Shaderlab):
    1.     Shader "Void"
    2.     {
    3.         Properties
    4.         {
    5.             _MainTex ("Base (RGB)", 2D) = "white" {}
    6.         }
    7.        
    8.         SubShader
    9.         {
    10.             Pass
    11.             {
    12.                 Tags { "RenderType"="Opaque" }
    13.                 LOD 200
    14.            
    15.                 CGPROGRAM
    16.                 #pragma vertex vert
    17.                 #pragma fragment frag
    18.                 #include "UnityCG.cginc"
    19.    
    20.                 sampler2D _MainTex;
    21.                 float4 _MainTex_ST;
    22.    
    23.                 struct v2f
    24.                 {
    25.                     float4  pos : SV_POSITION;
    26.                     float4  scrPos;
    27.                 };
    28.    
    29.                 v2f vert(appdata_base v)
    30.                 {
    31.                     v2f o;
    32.                     o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    33.                     o.scrPos = ComputeScreenPos(o.pos);
    34.                     return o;
    35.                 }
    36.    
    37.                 fixed4 frag(v2f i) : COLOR
    38.                 {
    39.                     float2 uv = (i.scrPos.xy / i.scrPos.w);
    40.                     fixed4 c = tex2D(_MainTex, uv);
    41.                     return c;
    42.                 }
    43.            
    44.                 ENDCG
    45.             }
    46.         }
    47.            
    48.         FallBack "Diffuse"
    49.     }