Search Unity

alpha test in fragment shader doesn't work on Mac and iPhone?

Discussion in 'Shaders' started by william7ba, Apr 21, 2012.

  1. william7ba

    william7ba

    Joined:
    Jan 28, 2012
    Posts:
    4
    Hi,
    I want to do alpha test in fragment shader, it works fine in windows, but not in Mac or iPhone, I changed to alpha blend, it works on all platforms, but the rendering order give me some problem. I simplified my code to test alphatest like below, still not working on Mac or iPhone. Anyone has an idea?


    Subshader {
    Tags { "RenderType"="Opaque" }
    Pass {

    AlphaTest GEqual [_AlphaCutoff]

    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    #pragma fragmentoption ARB_precision_hint_fastest

    sampler2D _MainTex;

    half4 frag( v2f i ) : COLOR
    {
    half4 col;
    col = tex2D(_MainTex, i.uv.xy);

    return col;
    }
    ENDCG
    }
    }
     
  2. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Please put your code in the appropriate tags.
    That shader should be in the AlphaTest queue.
    There is no fixed function Alpha Test hardware on iOS devices that could use that shader. Use an actual discard instruction. (I don't know what Unity might try to do, behind the scenes, but it doesn't matter, due to the AlphaTest command being obsolete.)
     
  3. william7ba

    william7ba

    Joined:
    Jan 28, 2012
    Posts:
    4
    Thank you very much Jessy!
    a clip in fragment shader fix my problem.
     
    Last edited: Apr 21, 2012
  4. Yeowza

    Yeowza

    Joined:
    May 9, 2014
    Posts:
    48
    @william7ba, Would you mind posting your code? I think I am doing the same thing.