Search Unity

Texture Mask working in Editor not on Devices!!

Discussion in '2D' started by cbothra, Jul 4, 2015.

  1. cbothra

    cbothra

    Joined:
    Mar 14, 2014
    Posts:
    125
    Hi,

    Right now I am facing a big problem.

    Please help me to get out of this issue. Here's my complete scenario:

    I created a Texture and put Unlit/Transparent Masked on it. In the Unlit/Transparent Masked shader, I put a another texture as mask in the shader which is working perfect in editor but when I create the apk and run it on device the the masking is no more effective. Following is the shader I am using:

    Code (CSharp):
    1. Shader "Unlit/Transparent Masked"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Base (RGB), Alpha (A)", 2D) = "black" {}
    6.         _Mask ("Alpha (A)", 2D) = "white" {}
    7.     }
    8.    
    9.     SubShader
    10.     {
    11.         LOD 200
    12.  
    13.         Tags
    14.         {
    15.             "Queue" = "Transparent"
    16.             "IgnoreProjector" = "True"
    17.             "RenderType" = "Transparent"
    18.         }
    19.        
    20.         Pass
    21.         {
    22.             Cull Off
    23.             Lighting Off
    24.             ZWrite Off
    25.             Fog { Mode Off }
    26.             Offset -1, -1
    27.             Blend SrcAlpha OneMinusSrcAlpha
    28.  
    29.             CGPROGRAM
    30.             #pragma vertex vert
    31.             #pragma fragment frag          
    32.             #include "UnityCG.cginc"
    33.  
    34.             sampler2D _MainTex;
    35.             sampler2D _Mask;
    36.             float4 _MainTex_ST;
    37.    
    38.             struct appdata_t
    39.             {
    40.                 float4 vertex : POSITION;
    41.                 float2 texcoord : TEXCOORD0;
    42.                 float2 texcoord1 : TEXCOORD1;
    43.                 fixed4 color : COLOR;
    44.             };
    45.    
    46.             struct v2f
    47.             {
    48.                 float4 vertex : SV_POSITION;
    49.                 float2 texcoord : TEXCOORD0;
    50.                 float2 texcoord1 : TEXCOORD1;
    51.                 fixed4 color : COLOR;
    52.             };
    53.    
    54.             v2f o;
    55.  
    56.             v2f vert (appdata_t v)
    57.             {
    58.                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    59.                 o.texcoord = v.texcoord;
    60.                 o.texcoord1 = v.texcoord1;
    61.                 o.color = v.color;
    62.                 return o;
    63.             }
    64.                
    65.             fixed4 frag (v2f IN) : COLOR
    66.             {
    67.                 half4 col = tex2D(_MainTex, IN.texcoord) * IN.color;
    68.                 col.a *= tex2D(_Mask, IN.texcoord1).a;
    69.                 return col;
    70.             }
    71.             ENDCG
    72.         }
    73.     }
    74.  
    75.     SubShader
    76.     {
    77.         LOD 100
    78.  
    79.         Tags
    80.         {
    81.             "Queue" = "Transparent"
    82.             "IgnoreProjector" = "True"
    83.             "RenderType" = "Transparent"
    84.         }
    85.        
    86.         Pass
    87.         {
    88.             Cull Off
    89.             Lighting Off
    90.             ZWrite Off
    91.             Fog { Mode Off }
    92.             Offset -1, -1
    93.             ColorMask RGB
    94.             Blend SrcAlpha OneMinusSrcAlpha
    95.             ColorMaterial AmbientAndDiffuse
    96.            
    97.             SetTexture [_MainTex]
    98.             {
    99.                 Combine Texture * Primary
    100.             }
    101.         }
    102.     }
    103. }
    104.  
    Thanks-in-advance.