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

Since I can't use stencil buffers with HRDP: How can I (un)mask objects thru certain other objects?

Discussion in 'High Definition Render Pipeline' started by Ruceus, Feb 5, 2021.

  1. Ruceus

    Ruceus

    Joined:
    Feb 5, 2021
    Posts:
    2
    Okay, first I'm going to explain what I want to do (and already did):

    Imagine a single plane in an empty scene with nothing else around it.
    When you look at it from the front you can see a room "inside" that plane.
    It is usually "not there" or "not visible" when you look behind the plane. It is only visible when you look through the plane from the front, but as I said there is nothing behind the thin gate.

    Well, actually the room exists in the scene right behind the gate, but it is not rendered. It will only be rendered when you look at it "through" that plane (I call these "gates").
    The trick is quite simple, when you know the basics of a stencil buffer. I wrote a shader for the gate and one for the interior objects to be rendered just like that with some tutorials (eg. https://www.ronja-tutorials.com/post/022-stencil-buffers/).
    On top of that: I can create multiple "dimensions" since I can adress a specific stencil buffer using a reference number for masking (or unmasking if you want).

    The big problem I have now is: My game does not use the HDRP at the moment, but I want and need the HDRP to create all other effects for my game as it is so nice and easy with the ShaderGraph!
    Sad but true, the HDRP/ShaderGraph does not support access to the stencil buffer which is essential for my effect. THIS CAN'T BE IT!

    Now the final question for you guys:
    Can you help me find an HDRP applicable alternative that is easy to manage in my scenes that can handle multiple dimensions (simply small rooms) at once? I think I need around 20 dimensions at a time, so using 20 RenderTextures and cameras won't work.
    I was also having a look at Unity's new Custom Pass Volumes in v2020.2, but I don't really get to
    know how to code them (yet?).
    Do you have any other ideas? I really seek here for help on my last try to find a way for this.
    Maybe the great grand @bgolus can find a way in his immense shader knowledge to bless my project. You really carry the shader community on this forum, big thanks to you! And as well a big thanks in advance to everyone who can help me solving this issue that haunts me for almost a year now.

    Here are some example images using the common stencil buffer method:

    Screenshot 2021-02-05 020805.jpg
    Screenshot 2021-02-05 020839.jpg Screenshot 2021-02-05 020903.jpg Screenshot 2021-02-05 021402.jpg
     
    Last edited: Feb 5, 2021
  2. Camarent

    Camarent

    Joined:
    Feb 19, 2014
    Posts:
    168
  3. Ruceus

    Ruceus

    Joined:
    Feb 5, 2021
    Posts:
    2
    Oh wow, why couldn't I find this thread while searching for those same keywords? And I also never knew of this repository!
    It seems like these shaders won't work on my first try. I'm going to have a deeper look at these, maybe customize them. Thanks for now, I gonna update on this after I've tried some things!