TransWikia.com

How to hide objects behind an invisible plane?

Game Development Asked by hatinacat2000 on December 18, 2020

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

One Answer

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.

Correct answer by DMGregory on December 18, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP