Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Making a layer visible only when viewed through a mask

Discussion in 'Shaders' started by skigoddard, Sep 15, 2014.

  1. skigoddard

    skigoddard

    Joined:
    Sep 2, 2012
    Posts:
    4
    Hello everyone,

    I'm new to the whole shader thing, and I was wondering if someone could offer some assistance. I'm trying to make it to where, as the title says, a layer in my game is only visible when viewed through a mesh. Kind of like a reverse mask, or a portal. I don't have Unity pro, so I'm trying to figure out how to do this without using render textures or stencil buffers. I found a shader for a regular mask, but I can't figure out how to create an inverted mask, and after countless days of searching the web and browsing the forums, I've decided to give up and come to you guys. So, if it isn't too much trouble, could someone help point me in the right direction? Like I said, I'm new to this, so see if you can find a simple example.

    Thank you!
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    You can use a depthmask shader on a mesh, along with two cameras, where the second camera displays only the desired layer.

    --Eric
     
  3. skigoddard

    skigoddard

    Joined:
    Sep 2, 2012
    Posts:
    4
    Thanks, it worked!!

    In case you're wondering what I'm working on, a screenshot: Screen Shot 2014-09-15 at 9.34.43 PM.png