Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Julien-Lynge · Jul 15, 2015 at 07:25 PM · unity 5fadeoculusrift

5.1 + Oculus Rift: Screen Fade?

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();
     }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Julien-Lynge · Jul 15, 2015 at 09:05 PM

Figured it out after stumbling upon the 'Oculus Utilities for Unity'. (These are scripts that replace the old OVR stuff - I'd missed them earlier).

In a nutshell, it looks like the GL matrix wasn't working from the final state when I was trying to render the fade (after WaitForEndOfFrame, which takes place before the render events). The Rift code seems to later apply a different transformation which results in the effect not appearing on screen.

Non-technical explanation: The GL code above works, but you have to do it a bit later in each frame, otherwise the fade will appear off-screen.

The way to get this to work is to run this code in the OnPostRender phase. If you attach code like the following to each camera in the scene, they will forward the OnPostRender event to the screen fade script, and everything will work correctly:

 /// <summary>
 /// Attached to each active camera in scene while fading.
 /// </summary>
 class CameraFader : MonoBehaviour
 {
     // Based on OVRScreenFade
 #if UNITY_ANDROID && !UNITY_EDITOR
     void OnCustomPostRender()
 #else
     void OnPostRender()
 #endif
     {
         ScreenFade.DrawQuad();
     }
 }

This assumes that the DrawQuad method is public and static.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

getting the oculus rift dk2 to work in unity 5(hmd mode) 1 Answer

Oculus RIft DK1 and DK2 compatability 0 Answers

Font renders incorrectly 1 Answer

| DK2 Not Stereoscopic | Unity 5.1.2 | 1 Answer

Make a cartoon character talk 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges