- Home /
Why does this cube occlude this sphere? (with pictures)
In front, I have a plane with the depth mask shader, which sets the render queue value to Geometry+10 (2010). This shader makes the plane not change any pixels, but still write to the depth buffer.
Behind the plane, I have a with the SetRenderQueue script attached (from the link above), and set its render queue value to 2020.
Behind the cube and slightly off center, I have a sphere with just the default material, giving it a render queue value of 2000.
Here is a picture of the scene
Here is a picture of the results through the camera
Why is the cube occluding the sphere?
Even though the cube is in front of the sphere, I didn't expect it to occlude it. Here is why:
I expected the sphere was drawn first since it has the lowest render queue value.
Next, the plane is drawn since it has a queue value of 2010. It doesn't change the already drawn sphere, but it does write new values to the depth buffer.
Last, it's the cube's turn who has a queue value of 2020. However, since the plane is closer to the camera than the cube is, and it wrote to the depth buffer, the cube should be completely occluded.
Everything seems to be as I expect, except for the fact that the cube is occluding the sphere. Why is this?
It might also be helpful to note that if I change the render queue value of the cube to above 2500, everything works exactly as I originally expected it to - the cube is completely occluded and the sphere is completely visible.
Answer by maccabbe · Apr 03, 2015 at 05:27 PM
This is because there is a culling depth test which happens before the fragments are actually drawn that stops anything behind the cube from being drawn in the first place. You need to turn ZWrite off in the cube's shader if you expect things behind the cube to be drawn.