1
\$\begingroup\$

I am using Unity 2019.1.4f1 (personal) in regular 3D mode. I want to make a material for a plane that will cause everything behind that plane to be invisible.

I want a character who steps through a doorway to appear to disappear into "hammerspace" when he passes the door frame. I will post pictures in a minute.

Blender concept (note how space after the doorframe is successfully occluded): enter image description here

Unity WIP (note how path after doorway is not yet occluded): enter image description here

\$\endgroup\$
  • \$\begingroup\$ I think you'll need to modify the shader used to draw the object(s) being culled too. Without that, the only ways to communicate about your shape to the unmodified culled object shader drawn later are via things like the depth & stencil buffer, which can express your culling object's silhouette but not its thickness along the view direction. (You can cull everything behind its front faces, for instance, which is not the same as culling everything inside its volume) \$\endgroup\$ – DMGregory Jun 7 at 5:02
  • \$\begingroup\$ Culling everything behind a plane would also work. I am not trying to make a fancy effect, I just need to make a piece of the scenery dissapear/invisible, so when a character goes through a doorway they seem to disappear into hammerspace \$\endgroup\$ – hatinacat2000 Jun 7 at 14:31
  • \$\begingroup\$ Ahh, that's easier. It's usually better to ask about the exact case you need to solve, rather than generalizing it to a more universal problem. Quite often, the general problem is much harder to solve, while the specific case can admit efficient shortcuts. \$\endgroup\$ – DMGregory Jun 7 at 14:56
2
\$\begingroup\$

You can do this with the depth buffer.

This shader will cause an object to write its depth to the depth buffer, without actually drawing anything.

Any content behind this object's front faces that tries to draw after it in the rendering order will fail the depth test and abort drawing those pixels.

If you need some content to be hidden but not others, then one way to solve it is to play with the Render Queue for each material - sandwiching this material before the object you want to hide, but after the objects you want to show through it.

Shader "Custom/DepthReserve"
{
    Properties
    {
    }
    SubShader
    {
        Tags { "RenderType" = "Opaque" "Queue"="Geometry-1" }
        LOD 100

        Blend Zero One

        Pass
        {

        }
    }
}

If you want to be more selective about what gets hidden / not, then you'll likely want to modify the shader of the object being hidden, to eg. check the stencil buffer or do a test against a custom render texture to determine whether it's allowed to draw here.

\$\endgroup\$
  • \$\begingroup\$ Bingo! Thank you, sir! \$\endgroup\$ – hatinacat2000 Jun 7 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.