Search Unity

Transparent shader not working on AR Mesh (iPadPro)

Discussion in 'AR' started by edwon, May 27, 2020.

  1. edwon

    edwon

    Joined:
    Apr 24, 2011
    Posts:
    266
    I'm trying to write a simple transparent shader that can have cutouts where the alpha on the texture is zero.

    I've written this simple shader, and it works great on an ARPlane but not on an ARMesh. No idea why. But this line seems suspicioius "Blend SrcAlpha OneMinusSrcAlpha" if I turn that line off or change the blending mode, I can see the ARMesh, but the texture isn't visible.

    I have all options enabled on the ARMeshManager, including texture coordinates.

    My friend who is also an AR Unity dev using iPadPro, thinks this is likely due to the ARMeshManager generating bad UV's on AR meshes.

    I'm also submitting a Unity Bug Report.

    (excuse the weird formatting)

    Shader "AR/Texture"
    {
    Properties
    {
    _MainTex ("Texture", 2D) = "white" {}
    _Cutoff ("Cutoff", Range (0,1)) = 1
    }
    SubShader
    {
    Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
    Blend SrcAlpha OneMinusSrcAlpha
    Cull Off
    Lighting Off
    ZWrite Off
    Fog { Color (0,0,0,0) }

    Pass
    {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag

    #include "UnityCG.cginc"

    struct appdata
    {
    float4 vertex : POSITION;
    float2 uv : TEXCOORD0;
    };

    struct v2f
    {
    float4 vertex : SV_POSITION;
    float2 uv : TEXCOORD0;
    };

    sampler2D _MainTex;
    float4 _MainTex_ST;
    float _Cutoff;

    v2f vert (appdata v)
    {
    v2f o;
    o.vertex = UnityObjectToClipPos(v.vertex);
    o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    return o;
    }

    fixed4 frag (v2f i) : SV_Target
    {
    fixed4 col = tex2D(_MainTex, i.uv);
    col.a *= _Cutoff;
    return col;
    }
    ENDCG
    }
    }
    }

     
    Last edited: May 27, 2020
    vmnetcetera likes this.