Aug
14
2013

RiftVideoPlayer - first encounter with the Oculus Rift

As long as I waited for my DevKit to be delivered, I dreamed of watching some 3D videos with it. So I downloaded all video players I could find made for the Rift and in the end, some were really exciting. But none was really the thing I wanted. Something simple, with an in game menu to select a video and a mechanism to watch a movie while lying down. And because I hacked around with Windows Media Foundation for another project I am working on, I thought that something like this would be the best entry into the world of Rift. 

3D video playing

It was not particularly easy to play video in unity. Especially videos in 3D or a variety of formats. I had to write an extension that does the hard work. I know it has been done before, but it was clearly something I wanted to explore. My first version was based on the Media Foundation, but it couldn't handle MKV containers so well. When I recognized that, I decided to support playback via libVLC. I should have done that from the beginning. It is so much easier to do. So now RiftVideoPlayer can play back videos with both engines preferring VLC if it is installed.

System Requirements

  • Video card compatible with Direct3D 11
  • Oculus Rift
  • Windows 7 or later
  • optional: VLC 2.x

Navigation

If you know the navigation of the standard Unity3D Rift demos, than you know the navigation of the "player" already. I also kept the stuff to adjust the vision in. With spacebar you have access to this screen.
RiftVideoPlayer will start with a menu where you can load a movie. Navigate between the menu elements with right/left keys and hit return/A to select an item. You can dismiss the menu by hitting backspace/start.

Gamepad Keyboard Function
Start Backspace          Show/hide main menu
A Return Select item
Left/Right Left/Right Jump between items
Up/Down Up/Down Used in listbox to select file
L1 Page Up Move screen up relative to current position (rotates around)
R1 Page Down Move screen down relative to current position (rotates around)
Left Analogue Stick W/A/S/D Move around
Right Analogue Stick        Look around

 

Command line

Following command line arguments are supported:

RiftVideoPlayer [movie filename] [-sbs]

Use -sbs for 3D side by side video. All arguments are optional. If you do not provide a movie to play, you can select one from inside the player.

Remarks

  • You have to calibrate the magnetic sensor of the rift by looking into all directions. After that the on screen hint will go away. This prevents drifting of the screen over time.
  • Before you select a movie for playback, please select the display mode (2D/3D).
  • The player uses VLC if it is installed (HKEY_LOCAL_MACHINE\SOFTWARE\VideoLAN\VLC\InstallDir is set). Otherwise it will use Windows Media foundation, which will result in some files not beeing able to be played.
  • In the sources is an Unity3D editor extension included that allows to run the current scene on the rift using my ForceToRift tool. It is triggered by Shift-B or via the menu item Debug/Run on Rift. You can include this in other projects too. Just copy the script RunOnRift.cs and adjust the path to my tool.

Downloads

If you have any questions (including source code related stuff) or remarks feel free to comment on this post. I have to thank all those, who tried their video player version for the rift. Most of them are really good and were a source of inspiration.

Aug
14
2013

Unity3D, Oculus Rift and the fullscreen problem

A problem that got me frustrated since I unpacked my Rift and started the first Unity3D demo was, that there was no way to force the demo to run fullscreen on a secondary monitor (-adapter did not work for me). There are two workarounds that worked for me somehow:

  • Change the primary display to the rift
  • Use display mirroring

However, both solutions are not really acceptable. The first one has some side effects like the taskbar beeing on the rift, windows opening there becoming inaccessible and so on. Mirroring works quite well if you have a primary display with a resolution up to 1920x1200. Since I own a 30" monitor, that forced me to use a lower resolution on it. Not very nice in the long run. Display mirroring also introduces some lags on the rift which are quite irritating.

Road to solution

So I thought about it for a while and remembered a tool that could capture screens from Direct3D applications through a hooking mechanism (see http://spazzarama.com/2011/03/14/c-screen-capture-and-overlays-for-direct3d-9-10-and-11-using-api-hooks/). From there it was quite easy to introduce a new hook that would link into IDXGISwapChain.SetFullscreenState where you are able to set a target output. Exactly what I wanted. An hour later the thing really worked - cool. No more display mirroring, my primary display beeing the one I am used to.

Solution

All this led to a small command line tool that can force any(?) Direct3D 11 application to output on the Oculus Rift.

Requirements

  • Direct3D 11 application and graphics card
  • .NET Framework 4
  • obviously an Oculus Rift DevKit 1 (later DevKits can be used if code is modified - device detection looks for device id containing OVR0001)

Usage

Extract the ZIP file anywhere you like. As I said, the tool is a command line tool. So bring up a command prompt and enter the following:

ForceToRift.exe [PathToExeToStart] [additional arguments to pass to exe]

After hitting return you should see some debug output and your target application should start on the Rift. Remember that this only works for Direct3D 11 applications. So if you have a Unity3D Demo that was compiled for Direct3D9 you can try the following:

ForceToRift.exe [Direct3D9App.exe] --force-d3d11

 

Downloads

  • Binaries
  • Source code (be aware that it is not really cleaned up, but it works for me, the interesting part is in DXHookD3D11.cs)

You are free to use and modify this as you want.

TextBox