0
\$\begingroup\$

I am developing a VR application in Unity where I have a 3D object (a plane) flying over the player's head. I am using a Skybox for the background and I want to make the plane "disappear" behind a building. I placed a cube over the building and I want to make it transparent (such that I still see the skybox behind it) but make the plane disappear as you can see in this picture.

enter image description here

It seems to work "fine" as long as I don't move the camera, but as soon as I move it, some artefacts appear (see the picture below)

enter image description here

I am using a shader I found online:

{
    Properties
    {
    }
    SubShader
    {
        Tags { "RenderType" = "Opaque" "Queue"="Geometry-1" }
        LOD 100

        ZWrite On
        ZTest Always

        Blend Zero One

        Pass
        {

        }
    }
}

Can anyone give me some advice or guide me towards a tutorial on how to properly set up this shader?

Note that I am a real beginner in all this and have almost no idea how shaders work.

\$\endgroup\$
4
  • \$\begingroup\$ What shader/material are you using to draw the buildings? It looks like it's doing some kind pf depth-based distortion, because that code you showed writes solely to the depth buffer. \$\endgroup\$
    – DMGregory
    Commented Jul 3, 2024 at 10:16
  • \$\begingroup\$ The buildings are just part of the skybox (a 360 degree image transformed into a skybox), that is why I am trying to add the invisible cube, such that the plane object disappears smoothly behind the fake building \$\endgroup\$ Commented Jul 3, 2024 at 11:27
  • \$\begingroup\$ I understand that, but I'm trying to figure out what skybox shader leads to the distortion we're seeing. Can you walk us through the complete steps to create a scene that demonstrates this problem, starting from a new, empty project? \$\endgroup\$
    – DMGregory
    Commented Jul 3, 2024 at 12:12
  • \$\begingroup\$ For the skybox part, I just take a 360 picture (generated from a software that downloads a 360 image from Google street view), change the texture shape to cube, then applying it to a material that I defined as skybox -> cubemap. I add a cube in the scene, that I position such that it would hide the building that is present in the skybox (from the POV of the XR rig) to which I applied the shader shown above. I am trying to make that cube invisible to the camera, but still hide the other game objects (the plane), such that it looks like the plane goes behind the building. \$\endgroup\$ Commented Jul 3, 2024 at 12:46

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.