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

Question URP - Getting alpha format by mesh?

Discussion in 'Shader Graph' started by Alberto_N, Mar 2, 2021.

  1. Alberto_N

    Alberto_N

    Joined:
    Mar 2, 2021
    Posts:
    5
    Hello,

    I've encountered a problem that I can't seem to find a proper solution... I have a shader that I followed a tutorial to make and it works just fine, but I'm also using AR Foundation face tracking. What I need to do is get the mask applied by the facetrack, and once it goes past a plane in the scene, the mask would have a shader applied that makes anything behind it (including the mask itself) invisible.

    That tutorial that I have mentionated later somewhat does what I want, but in a circular shape. Is it possible to get the mask's format and send it to the material's alpha? I am kinda lost at how or where to find something like this, as there is some see-through tutorials but only for when the object is behind, not in front.

    The idea is to create something similiar to this spark AR's effect:
     
  2. Alberto_N

    Alberto_N

    Joined:
    Mar 2, 2021
    Posts:
    5
    Just an update; I managed to make the effect I wanted using stencil buffer shaders.

    I followed this example and applied that shader to the material of face prefab, then followed this one for another stencil that blocks anything from rendering behind it. You could make it by just cutting the camera far plane, but the facemask prefab stays way too close to the camera (about 0.3~0.5 in Z) and that causes any shaders to show black lines. I then placed the water plane in front (0.2) and the render blocker plane behind (~0.7) and I got a very similiar effect to what I desired.