Custom Transparent Material on AR Mesh

  • Issue category: Meshing / ARDK Documentation
  • Device type & OS version: Android / iOS
  • Host machine & OS version: Windows 10
  • Issue Environment : Unity Mock
  • ARDK version: 2.3.1
  • Unity version: 2021.3.9f1

Description of the issue:

I wish to apply a custom material to the generated meshes that has a texture with transparency. Think something similar to the grid texture that is applied by default to the plane finding in the example scenes.

Unfortunately it seems that no matter what I do or what kind of shader I use, as soon as I apply a texture to a transparent shader material, the mesh goes entirely solid with no sign of the actual texture.

There was another thread created that was a similar problem, but the OP never responded and so it didn’t go anywhere. The documentation link that was posted in the thread also seems to be broken.

My guess is that this mesh is being generated without proper UV mapping, but how am I meant to get around this? It’s especially annoying that I can’t find anything in the documentation that mentions anything about this.

Solid color transparency working fine.
image

Transparent texture not even showing.
image

Even a normal, non-transparent texture doesn’t show.
image

Hi Sean,

Thank you for reaching out to Lightship Support! If I understand correctly, you want to overlay the “sky” mask with a transparent texture but aren’t seeing the expected result. You also mentioned that there was another thread on the forums with a similar issue that was unfortunately left with a cliffhanger. Could you please send me the shader code, the texture you’re trying to apply, and the link to the thread you’re referring to? If you would prefer to keep your content private, feel free to DM me instead. In the meantime, I will try to reproduce your issue to the best of my ability.

Thanks,

Maverick L.

No, not the sky mask. The mesh generated by your real time meshing scripts. I never once mentioned anything about the sky.

Here’s the other thread

As for the shader and texture, that isn’t necessary. I tried every shader that comes packaged with Unity and every combination of import settings for multiple different kinds of texture files.

Thank you for the clarification! Now that we’re on the same page, I can find a solution for you.

Once again I want to thank you for bearing with me here. I have excellent news! I was able to find a solution! Due to the mesh chunking, you can’t just apply the material to each chunk and expect the result you’re anticipating. You have to write a shader that draws your texture based on world space coordinates so you get something that covers the entire mesh. I’ve written a sample shader that accomplishes this and supports tiling and the alpha channel. You can use this as a reference for your own.

In my testing, my goal was to overlay a transparent texture of a basketball over the mesh.

Shader "Worldspace Shader" {
    Properties {
        _Color ("Main Color", Color) = (1,1,1,1)
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _Scale ("Texture Scale", Float) = 1.0
    }

    SubShader {
        Tags { "RenderType"="Opaque" "Queue"="AlphaTest" }
        LOD 200

        Cull Off ZWrite On ZTest LEqual Blend One Zero

    CGPROGRAM
    #pragma surface surf Lambert alpha
    sampler2D _MainTex;
    fixed4 _Color;
    float _Scale;

    struct Input
    {
        float3 worldNormal;
        float3 worldPos;
    };

    void surf(Input IN, inout SurfaceOutput o)
    {
        float2 UV;
        fixed4 c;

        if (abs(IN.worldNormal.x) > 0.5)
        {
            UV = IN.worldPos.yz; // side
            c = tex2D(_MainTex, UV * _Scale);
        }
        else if(abs(IN.worldNormal.z) > 0.5)
        {
            UV = IN.worldPos.xy; // front
            c = tex2D(_MainTex, UV * _Scale);
        }
        else
        {
            UV = IN.worldPos.xz; // top
            c = tex2D(_MainTex, UV * _Scale);
        }

        o.Albedo = c.rgb * _Color;
        o.Alpha = tex2D(_MainTex, UV).a;
    }

    ENDCG
    }

Fallback "VertexLit"
}

Hi Sean,

Just checking in. Were you able to achieve what you were looking for with the aid of that sample? Do you have any further questions or concerns?

Best,
Maverick L.