cancel
Showing results for 
Search instead for 
Did you mean: 

Camera Clear flags not working properly on Gear VR

dyfer
Honored Guest
Hi !

I'm trying to make a very simple thing that is working great in Unity but not behaving has expected in the Gear VR.
I'm using Unity 5.4.1p4 and Oculus utilities &Plugin 1.8.

I have two OVRCameraRigs prefabs in my scene. The first prefab is rendering the "Camera1" layer only and the second prefab is set up to render the "Camera2" layer. The first prefab cameras have the Clear Flags set to Solid Color and a Depth of 0. The second prefab cameras are set to Don't Clear and have a Depth of 1.

I have 3 cubes in this scene: ForeGround, Middle and BackGround. Middle is on the "Camera1" layer while ForeGround & BackGround are on "Camera2" layer.

Here is the result in Unity (working has expected, I can see the 3 cubes) :

3xvg8llba4bo.png

And here is the result in the Gear VR ( ForeGround & BackGround are rendered on top of the Middle cube) :

f2jvyapsbrv5.png

Am I doing anything wrong or is it a known bug? Because I can't find anything about it and don't know how to fix that.
Thank you very much for your help !
6 REPLIES 6

vrdaveb
Oculus Staff
I can't reproduce this. Does this scene work for you?

dyfer
Honored Guest
Thank you for your help!

Your scene works on my side BUT it is not exactly what I am trying to do.
To reproduce my problem:
• Deactivate your Camera (4)
• On the Camera (0) add FPSWeapon to the Culling Mask list.

You'll see that the Cube (4) correctly renders on top of others in Unity but appears to be behind other cubes in the Gear VR.

vrdaveb
Oculus Staff
I don't have a layer named FPSWeapon in my project, but I assume it's layer 4, which Cube (4) is in. Since Cameras 1-3 have "Don't Clear" as their Clear Flags, I would actually expect them to render on top of Camera (0). Please set the clear flags to "Depth Only" to make Cube (4) render on top.

dyfer
Honored Guest
Well if I set the Cameras 1-3 to "Depth Only", Cube (4) renders behind the others.

Here is a simple scene with only two cameras and 3 cubes so you can see for yourself : Download Here 
Camera 1 renders cube 1 & 3
Camera 2 renders cube 2

I just want them to appear in the right order. You'll see the scene is working in Unity but is broken if you build it to the Gear vr.

vrdaveb
Oculus Staff
Ok, I see what you mean. You want the "BackGround" box to z fail behind the "Middle" box. Camera 2 doesn't re-use the depth data from Camera 1 and there is z fighting between the current content rendered by Camera 2 and the content Camera 2 rendered in the previous frame. Interestingly, while the Rift output in 5.4 is correct, the Camera 2 preview in the Scene view has the same artifact as Gear VR. It's also worth noting that on Rift, the Oculus SDK allocates the eye buffers while on Gear VR, Unity allocates them for this version.

vrdaveb
Oculus Staff
This looks like a bug in Unity's depth buffer management. We will take a look. In the meantime, you may have to use painter's algorithm and render back-to-front to get the correct ordering.