Search Unity

Alpha mask shader working in Unity editor but not when deployed to iOS

Discussion in 'Shaders' started by crushforth, Aug 28, 2015.

  1. crushforth

    crushforth

    Joined:
    Jul 22, 2010
    Posts:
    113
    I have the following shader:

    Code (csharp):
    1.  
    2. Shader"Crop/TransparentWithAlphaMask"
    3. {
    4. Properties {
    5. _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
    6. _AlphaTex ("Alpha (RGB) Trans (A)", 2D) = "white" {}
    7. }
    8.  
    9. SubShader {
    10. Tags {"Queue"="Transparent"}
    11. LOD200
    12.  
    13. CGPROGRAM
    14. #pragma surface surf Lambert alpha
    15.  
    16. sampler2D _MainTex;
    17. sampler2D _AlphaTex;
    18.  
    19. structInput {
    20. float2 uv_MainTex : TEXCOORD0;
    21. float2 uv2_AlphaTex : TEXCOORD1;
    22. };
    23.  
    24. void surf (Input IN, inout SurfaceOutput o) {
    25. fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
    26. fixed4 alpha = tex2D(_AlphaTex, IN.uv2_AlphaTex);
    27. o.Albedo = c.rgb * alpha.a;
    28. o.Alpha = alpha.a;
    29. }
    30. ENDCG
    31. }
    32.  
    33. Fallback "Diffuse"
    34. }
    35.  
    It is supposed to mask the texture _MainTex with the alpha channel of texture _AlphaTex. They both require different UV sets (UV1 for _MainTex and UV2 for _AlphaTex)

    This shader works perfectly in the editor but not when deployed to an iOS device. Does anyone know what is causing this issue? What renders in a black version of the alpha mask and nothing else (because of this I know it is using the correct UV's for the mask texture).

    The mesh I'm using for this is a dynamically built mesh generated at runtime, with shadows casting/receiving/light probes disabled.

    Any help would be greatly appreciated.
     
  2. crushforth

    crushforth

    Joined:
    Jul 22, 2010
    Posts:
    113
    I found what my issue was. Going to post it here incase someone has a similar issue in the future. The reason everything was coming out black on iOS was I wasn't supplying normals for my mesh. Seems the desktop/standalone shaders show different results when no vertex normals are supplied. This is what was causing me to think my shader wasn't compatible with iOS.
     
  3. o1o101

    o1o101

    Joined:
    Jan 19, 2014
    Posts:
    639
    Hey, So what exactly did you do to fix it?
     
  4. crushforth

    crushforth

    Joined:
    Jul 22, 2010
    Posts:
    113
    I wasn't setting normals for my mesh so I set them with mesh.normals = normals (where normals is an array of Vector3's one per vertex). If you're seeing black geometry on iOs and not in the editor this could be the issue.