Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Clipping objects "behind" a higher plane

Discussion in 'ARCore' started by njgreb, Aug 31, 2017.

  1. njgreb

    njgreb

    Joined:
    Mar 17, 2016
    Posts:
    1


    I have been playing with ARCore a bit this morning (and I am pretty new to Unity). Any thoughts on how to clip part of an object if it is "behind" a higher plane? You can see in this picture, their is a surface detected that is the coffee table and then the chair on a surface further back that is lower. Would be nice to clip the legs of the chair out so the coffee table effectively blocked them as it would be in reality.

    Not sure if this is something ARCore can do (now or in the future) or something I can implement myself in my tests.
     
  2. robson_depaula

    robson_depaula

    Joined:
    Sep 30, 2014
    Posts:
    35
    Hi @njgreb I think this can be achieved by modifying the shader on the material used to display the plane meshes.

    In the HelloARExample, if you change the PlaneGrid material to one that is transparent but is capable of occlusion you'll have the intended result (I suppose).

    This was more easily achieved using Tango, since they provided the shader capable of doing that. I'll attach it here so you can try (Apache Licensed, AFAIK).

    Code (CSharp):
    1. Shader "Tango/PointCloud (Occlusion)" {
    2.     SubShader {
    3.         Tags { "Queue" = "Background-1" }
    4.         Pass {
    5.             ColorMask 0
    6.        
    7.             CGPROGRAM
    8.             #pragma vertex vert
    9.             #pragma fragment frag
    10.  
    11.             #include "UnityCG.cginc"
    12.  
    13.             struct appdata
    14.             {
    15.                float4 vertex : POSITION;
    16.             };
    17.      
    18.             struct v2f
    19.             {
    20.                float4 vertex : SV_POSITION;
    21.                float size : PSIZE;
    22.             };
    23.          
    24.             v2f vert (appdata v)
    25.             {
    26.                 v2f o;
    27.                 o.vertex = UnityObjectToClipPos(v.vertex);
    28.                 o.size = 30;
    29.                 return o;
    30.             }
    31.          
    32.             fixed4 frag (v2f i) : SV_Target
    33.             {
    34.                 return fixed4(1, 1, 1, 1);
    35.             }
    36.             ENDCG
    37.         }
    38.     }
    39. }
    40.  
     
    HenryAsh likes this.
  3. HenryAsh

    HenryAsh

    Joined:
    Apr 11, 2017
    Posts:
    12
  4. eyeofhorus

    eyeofhorus

    Joined:
    Oct 10, 2013
    Posts:
    9
    I'm trying out the occlusion shader but seems it's not clearing the frames and shows a black surface on my mesh plane, any clue?

    Screen Shot 2018-06-04 at 10.32.34 PM.png
     
  5. robson_depaula

    robson_depaula

    Joined:
    Sep 30, 2014
    Posts:
    35
    Hi @eyeofhorus, not sure what are you using the shader for. I would like to emphasize that it is written to work with Google AR Core or Google Tango camera prefabs.

    Cheers