AnswerBun.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!

Related Questions

My GameObject keeps spawning when it shouldn’t

2  Asked on November 9, 2021 by michael-hampshire

     

Texture blends into one single color

1  Asked on November 9, 2021 by andrey-k

       

Player jitters when Jumping at object edges

1  Asked on November 9, 2021 by cgaudet

   

My bullets won’t bounce in Unity?

1  Asked on November 6, 2021 by kayra-yorulmaz

     

How to time draw images to the window in d3d8

0  Asked on November 2, 2021 by kite

 

Tank / turret animations

0  Asked on November 2, 2021 by lilkrit

   

Problems with recursive backtracking algorithm for a 3D maze

0  Asked on November 2, 2021 by janis-taranda

   

Add a sound to all the buttons in a project

3  Asked on November 2, 2021 by hamza-memon

   

Editing terrain in Blender

0  Asked on November 2, 2021

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir