arfoundation-samples icon indicating copy to clipboard operation
arfoundation-samples copied to clipboard

Surface Occlusion

Open craftercis opened this issue 8 years ago • 2 comments

Can we use Surface Occlusion in ARFoundation?

so that you, for example, stand behind a wall and that you will no longer be able to see your object. And is it possible to give the ground a collider so that if you throw something in AR that also stays on the ground. And why cant we use the ARCore light estimation shaders

Examples:

https://www.youtube.com/watch?v=yrSGzoo1Ikw https://www.youtube.com/watch?v=vzbz8UgM_qc

craftercis avatar Sep 19 '18 11:09 craftercis

Both are possible. For occlusion, you just need to use a shader that only writes to the Z buffer, and assign that to your ARPlane's MeshRenderer's material. Something like this should work:

Shader "AR/Occlusion"
{
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        Tags { "Queue" = "Geometry-1" }
        ZWrite On
        ZTest LEqual
        ColorMask 0

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            
            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
            };

            struct v2f
            {
                float4 vertex : SV_POSITION;
            };

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                return o;
            }
            
            fixed4 frag (v2f i) : SV_Target
            {
                return fixed4(0.0, 0.0, 0.0, 0.0);
            }
            ENDCG
        }
    }
}

For the collision, you just need a MeshCollider on your ARPlane. The AR Default Plane prefab used in the sample already has this.

tdmowrer avatar Sep 19 '18 17:09 tdmowrer

We have a sample that demonstrates how to achieve this: https://github.com/Unity-Technologies/arfoundation-samples#planeocclusion

mdurand42 avatar Apr 20 '20 22:04 mdurand42