Blocking invisible object?

I’d like to create a plane that occludes everything behind it but is essentially invisible, rendering only the skybox behind it. Is this possible? Following some googling, I tried using this:

Shader "Custom/InvisibleOccluder" {
    SubShader{
        Tags { "RenderType" = "Opaque" "Queue" = "Background" }
        Pass {
            Blend Zero One
        }
    }
}

But that didn’t seem to do anything. I’m using Deferred Rendering.

Bump?

That used to be possible when the background was drawn before opaque geometry. That shader intends to fill the z-buffer after the skybox is drawn, so everything else behind it will be rejected by the z-test.

Unity changed the render order for better performance though. So now the skybox is rendered after all other opaque geometry. That makes things a little trickier in your case. The easiest way will probably be:

  1. Use the above shader but at Queue Geometry-1
    This should block both the geometry and the background.
  2. Use a shader that clears the z-buffer to allow the background to come through. At Queue Background-1 with z-testing set to always and with a vertex shader that offsets the geometry to the far clip plane. This is really the tricky part. You’ll need an actual fragment shader for this.
  3. Use the above shader again at Queue Background+1 to also clip transparent geometry.
1 Like

What I’d do is make a shader that displays the skybox and then put that on your invisible block. So the block isn’t actually blocking any geometry - it just looks exactly like the skybox.

1 Like