Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Depth mask - vuforia AR Portal effect

Discussion in 'Shaders' started by ONOROFF, Jan 4, 2016.

  1. ONOROFF

    ONOROFF

    Joined:
    Dec 18, 2013
    Posts:
    5
    Hi,

    I am creating an AR app that allows you to open a portal to a new world and look inside.

    I have a shading problem to solve, here is a video explaining my issue (it was easier than trying to explain):


    So in a nutshell I am currently using geometry with a hole cut through it, then applying a depth mask shader which is simply rendering nothing through to the video texture generated by vuforia. However I'd like to control the mask that occludes the cube using a texture or perhaps a shader forge node. This will allow me to have lots of creative control over how this "portal" looks and behaves.

    Would love some advice!

    Thanks in advance.

    Ben.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    I would just use shader forge and have the video mapped to the plane using the screen space UVs and using alpha transparency so you can do soft edged effects.
     
  3. ONOROFF

    ONOROFF

    Joined:
    Dec 18, 2013
    Posts:
    5
    Thanks!

    I took your advice and got the video texture working with shader forge. Only problem now is the UV mapping. The video texture is the entire video from the camera fed into a square texture, therefore what ever the users camera/screen resolution is, the mapping from screen space needs to be managed.

    See screen grab attached for the current UV mapping problem I have. You'll see that although the video mapped to the geometry in screen space, the video is not aligned correctly. For this to be working properly, the video texture needs to work like a projection from the camera. For reference the correctly aligned image in the background is the vuforia "background plane". This works because it is locked to the camera, however my geometry needs to move around as it needs to be parented to the tracker.

    UnityVuforiaVideoBackground.jpg

    I have also attached a screen grab of my shader forge node tree for reference.

    ShaderForgeNodeTree.jpg

    So, what can I do to adjust the mapping of the video texture to behave as per the vuforia video background?

    Really hurting my brain so thanks in advance for any help!!
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
  5. ONOROFF

    ONOROFF

    Joined:
    Dec 18, 2013
    Posts:
    5
    Thanks got that working well. In the end I just needed to change the Texture tile and offset. Has to be adjusted per device though, think its something to do with camera resolution/aspect ratio vs screen resolution. My mac laptop is 1:1 between the webcam and the screen, but the Samsung S6 phone needs completely different settings.
     
  6. Serhii-Horun

    Serhii-Horun

    Joined:
    Apr 12, 2015
    Posts:
    151
    Hi! Can you share shader code? I need to make portal like that