Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  3. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

AR Foundation - occlusion object or shader?

Discussion in 'AR' started by newguy123, Dec 7, 2018.

  1. newguy123

    newguy123

    Joined:
    Aug 22, 2018
    Posts:
    558
    Hi guys

    I want the tracked AR Plane, to occlude anyhting that may be going below it. For example, if I have a cube of say 200cm X 200cm X 200cm, but the pivot is 0,0,0 and the cube is placed based on the pivot, so then half the cube will be below the plane, and the other half above the plane. I want the tracking plane to occlude the bottom half of the cube, so in camera view in AR, you'll see only half a cube, and then whatever is below it in real world.

    For example if the cube is placed on a table in the real world, but since the pivit is centered, half of the cube will be IN or below the table. Essentially I want to cut of that extra but and have it DYNAMIC, so when I move the cube up or down, it appears to grow taller or shorter. Makes sense?

    I've taken a look at this: https://docs.unity3d.com/Manual/OcclusionCulling.html
    ...but somehow that doesnt seem to be what I'm looking for, or they are exaplaining it in a too complicated way...
     
  2. dyuldashev

    dyuldashev

    Joined:
    Mar 3, 2016
    Posts:
    62
    Hello. Occlusion does not work in AR Kit and AR Core if that's what you are asking. In other words, real life objects are always behind the AR objects. You could have a 3D model standing 10 meters away from you, but if you put your hand in front of the camera, that object sits on your hand. If we had occlusion, AR objects would have behaved just like real life objects.
     
  3. newguy123

    newguy123

    Joined:
    Aug 22, 2018
    Posts:
    558
    No, I mean this: (which seem to also contain the answer, just didnt test it yet):

    ...from 14 minutes 46 seconds:

     
  4. michaelhaessig

    michaelhaessig

    Joined:
    Nov 9, 2018
    Posts:
    1
    i got occlusion working by creating a new material and selecting the shader > VR > spatial mapping > occlusion, then setting the material on the AR Default Plane Mesh Renderer Component. The AR Default Plane Prefab is referenced on the AR Plane Manager Script to apply it to all detected planes.
     
  5. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    940
  6. rehanashraf1997

    rehanashraf1997

    Joined:
    Feb 26, 2019
    Posts:
    1
    Can you please share the code or video about that?
     
  7. antonsem

    antonsem

    Joined:
    Dec 13, 2012
    Posts:
    14
    QUOTE="steego, post: 4519762, member: 21970"]Here is a shader that does this for LWRP https://gist.github.com/StigOlavsen/c75c78df4e704aeb5f904b6c851748ff[/QUOTE]

    Thank you, this is awesome! If anyone interested, I've updated the shader for URP 7.2.1: https://gist.github.com/antonsem/b294fa7b7443e017599ee7a87a22b8b4

    Does anyone know how can I create an x-ray effect? Whenever the camera is getting close the plane should become transparent revealing whatever is behind it.

    I mean something like this:
     
    Last edited: Feb 18, 2020
    soorya696 likes this.
  8. soorya696

    soorya696

    Joined:
    Dec 13, 2018
    Posts:
    71
    Thank you, this is awesome! If anyone interested, I've updated the shader for URP 7.2.1: https://gist.github.com/antonsem/b294fa7b7443e017599ee7a87a22b8b4

    Does anyone know how can I create an x-ray effect? Whenever the camera is getting close the plane should become transparent revealing whatever is behind it.

    I mean something like this:
    [/QUOTE]

    Thanks for your URP shader!
     
    antonsem likes this.
  9. soorya696

    soorya696

    Joined:
    Dec 13, 2018
    Posts:
    71
    @antonsem is it possible to make this shader not to receive shadows?
    I'm not familiar with writing shaders. Any help is much appreciated.
     
  10. Saicopate

    Saicopate

    Joined:
    Sep 25, 2017
    Posts:
    72
    It doesnt receive shadows. Would be nice if this shader would actually BLOCK shadows.
     
  11. JerinPWilson

    JerinPWilson

    Joined:
    Jan 16, 2020
    Posts:
    1
    @antonsem hello thanks for the shader but i tried to use it in a material but its its pink in colour. I know im supposed to add something but i don't know what or how please help. Thanks.
     
  12. edwon

    edwon

    Joined:
    Apr 24, 2011
    Posts:
    218
    I second this! This is a HUGE problem with AR apps, and as far as I can tell no one has found a way to solve this. I wish Unity just simply provided a default AR plane/mesh shader that can occlude, render shadows, and BLOCK shadows as well.

    I wrote more about the issue here https://forum.unity.com/threads/dou...s-planes-stacked-on-top-of-each-other.890200/
     
    Saicopate likes this.
  13. bostonvaulter

    bostonvaulter

    Joined:
    Jan 14, 2021
    Posts:
    12
    KirillKuzyk likes this.
unityunity