Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
Anonymous's avatar
Anonymous
11 years ago

Tired of simple mirror window? This one weird trick...

I was just helping someone out with their project with a requirement to have a menu system on the regular window, and a separate VR view without the GUI.

Using Unity native VR and messing around with this project, I discovered OnGUI() will display its output to the main screen window as long as you have mirroring disabled by setting VRSettings.showDeviceView to false after the app starts (must be set at runtime). I hope this is a feature and not a bug because it opens up some new local multiplayer gameplay options (one player in VR, one player on window).

Even though this is legacy UI stuff, you can do some cool things with OnGUI(). The most significant here is you can draw a texture to a rect window with various fill, stretch, and crop options, and the texture can be a render texture from another camera. Currently Unity doesn't allow selecting which cameras are for VR and which would be for the main window. But if you give a camera a rendertexture, it will stop tracking the headset and can be placed anywhere in the scene, including being controlled by another character controller that responds to keyboard/mouse input. By combining a camera with rendertexture with OnGUI DrawTexture, you can render another camera out to the main window. You can actually render out as many cameras as you want and display them in various frames in the non-VR window. In addition, the mouse interaction works with the legacy OnGUI() stuff, so you non-VR screen can have some UI controls that are not seen in the VR view. You could probably make new UI screen space work as well with a bit more work (I might try that next). You could make some cool multiplayer games out of this where one player is using main window, and other player is using headset + controllers.

To show how this works, here is a sample 2-player-same-computer game project, demo, & a screenshot. Player on desktop screen attempts to hit VR player with one of the 2 objects using the GUI buttons to move the objects. VR player uses controller to attempt to avoid the objects the other player is pushing around. Score goes up when VR player is hit. The scene contains 3 cameras. 1 VR camera on OVRPlayerController/OVRCameraRig, and 2nd camera that follows player head and renders to a small texture seen in the screenshot to give a small mirror of the player view, and a 3rd fixed camera that is game overview used by desktop player. Render performance shouldn't be too bad as the render texture sizes can be kept small.

Screen show of what is seen on desktop display:
dualview.PNG

Source project (unitypackage):
https://www.dropbox.com/s/ex28dh9p1goix ... ckage?dl=0

Demo (executable):
https://www.dropbox.com/s/lvnnuo0kn0gbw ... w.zip?dl=0

Built with 5.1.3p2 Unity which is what I would recommend for now.

Enjoy!

ccs

1 Reply

Replies have been turned off for this discussion
  • I've been doing a similar trick recently but with Canvas UI and render mode "Screen Space - Overlay". It will be rendered to the mirror window (or full screen view) and *not* displayed in the Rift View. The standard input manager event system also works so the desktop can interact with buttons, etc (like in your demo with OnGUI()).

    I too am hoping it is a feature not a bug!