I’ve been working on upgrading our projects to 5.1 to take advantage of the new native Rift integration. However, I haven’t been able to fade the screen (e.g. a fade to black when changing screens) when in VR mode.
I’ve tried a couple things. One is to use OnGUI and draw a rectangle over the screen. The other is to wait until the end of the frame and use the GL functions to draw a quad over the screen. I can’t see any errors or issues that I can diagnose - it works fine when VR is off, and doesn’t appear at all when VR is on.
I’m sure this has something to do with the way Unity is rendering the scene in VR mode, under the hood. My guess is that there’s some pre-render step where it’s splitting the camera into two and doing who-knows-what that the user can’t see or control. Unfortunately, I can’t find any documentation or explanation that would help me find a solution. The fact that OnGUI doesn’t work doesn’t surprise me so much, but GL should be the equivalent of creating a temporary mesh over the camera, so that’s a little weird to me.
Has anyone else been able to figure out a way to screen fade in 5.1? I suppose I could directly create a gameObject in front of the camera with a quad and a custom material that always renders over the rest of the scene, but that seems like a hack.
Here’s the code I’ve tried:
//after creating a 1x1 texture
void OnGUI()
{
GUI.color = color;
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), fadeTexture);
}
//option 2: this is called after WaitForEndOfFrame()
private void DrawQuad(Color aColor)
{
Debug.Log("Calling drawquad");
fadeMaterial.SetPass(0);
GL.PushMatrix();
GL.LoadOrtho();
GL.Begin(GL.QUADS);
GL.Color(aColor);
GL.Vertex3(0, 0, -1);
GL.Vertex3(0, 1, -1);
GL.Vertex3(1, 1, -1);
GL.Vertex3(1, 0, -1);
GL.End();
GL.PopMatrix();
}