Skip to main content
August 8, 2014

0.4.0 & Unity 4.5.2p3 DirectToRift: How-to

I've done a lot of experimenting and I have found what I feel are the best settings and methods for 0.4.0 and the latest patch release of Unity (4.5.2p3). These instructions might also work on older versions of Unity, but I updated to latest because the 4.5.2p2 release notes mentioned DX11 lag fixes and I wanted to make sure to grab those.

Important settings:

1. QualitySettings - Other - VSync Count - Don't Vsync
The new driver handles setting vsync for you. I found if vsync is on here, the app actually crashes on startup when using DirectToRift.exe and won't run. Turning it off allows app to start.

2. PlayerSettings - Resolution & Presentation - Default is Full Screen setting should be off. If your app is set to full screen, the 1st time you run it using DirectToRift.exe, it will crash. Next time you run it will work though (because DirectToRift.exe apparently changes setting to window mode during the crash). Window mode is apparently required for DirectToRift to work.

3. OVRCameraController - set Time Warp off - it appears Time Warp is not working with Unity at this point and causes judder and/or lag. Unfortunate since Time Warp works so well with the Oculus World Demo (that is not built in Unity)

4. OVRCameraController/OVRDevice - set Prediction on - I find 30ms (0.03 - the default) works great.

5. Set Rift Display Mode to "Direct HMD Access From Apps" in driver

DX11 project:

Just build & run, exit immediately by pressing ESC. Navigate to your project folder, and double-click [app]_DirectToRift.exe. If it crashes the 1st time, just retry. It should work on next run.

DX9 project:

You can have your project set to use DX9, but when you actually go to run DirectToRift.exe, it will give you a window with nothing rendered in it and Rift display won't turn on. To fix this, you can create a shortcut to DirectToRift.exe that forces dx11 mode. To do this right-click on [app]_DirectToRift.exe in your project folder, and choose Create Shortcut. Now right-click on new shortcut, and click Properties. In the Target box, add -force-d3d11 at the end (outside of the quotations if there are any). Double-click new shortcut. If it crashes the 1st time, just retry. It should work on next run.

Tearing:
Noticing tearing when running DirectToRift? I found this happens pretty frequently even though it is clear vsync is on and app is running at 75fps. I found a simple code fix. You can bind a key to toggle vsync. To clear the tearing, just hit the toggle key twice when you notice it. The tearing should disappear. Here is the code to add to OVRDevice.cs:


public static void ToggleVsync() {
if (HMD == null || !SupportedPlatform)
return;

uint caps = HMD.GetEnabledCaps();

uint current = caps & (uint)ovrHmdCaps.ovrHmdCap_NoVSync;
if (current == 0) {
// vsync is on - turn it off
caps |= (uint)ovrHmdCaps.ovrHmdCap_NoVSync;
} else {
// vsync is off - turn it on
caps &= ~(uint)ovrHmdCaps.ovrHmdCap_NoVSync;
}
HMD.SetEnabledCaps(caps);
}


Then in the OVRDevice.cs Update() I put a key binding to do this:

void Update()
{
if (HMD != null && Input.anyKeyDown && HMD.GetHSWDisplayState().Displayed)
HMD.DismissHSWDisplay();
if (Input.GetKeyDown(KeyCode.V))
ToggleVsync();
}


Now the 'V' key will toggle between vsync on and off. Toggle it off and on once and the tearing should disappear. A side benefit is you can see how fast your app will run with vsync off, although it will look terrible and hurt your eyes. I actually bound the above to a timer that does 1st toggle 5 seconds after app starts and 2nd toggle 1 second after that. That way the tearing is never an issue and I don't have to use the V key to correct the issue.


Other useful things to try:

'M' key to toggle mirroring. The window that is normally black should now have a mirror of what you see in Rift.
'T' key to toggle timewarp back on. I think you'll find like I did that Timewarp isn't working correctly here. It causes additional judder and/or lag.
'F1' key to toggle low persistence. Really impressive to see the difference.
    This topic has been closed for replies.

    17 replies

    New Participant
    September 15, 2014
    Bookmarked this post :D
    September 15, 2014
    I just downloaded 0.4.6 beta 18 yesterday. I'll try it out and see. 0.4.6 beta 18 has all the 4.5.3f3 fixes in it, so it should be working as well as that. I have been running 0.4.2 SDK + 4.5.3f3 for a while now without major issues.

    One thing I have noticed is it helps to restart the Oculus service occasionally because positional tracking seems to stop working sometimes. It seems to be affected by the computer going to sleep.

    I have also noticed I occasionally have to completely restart my computer to get lag/judder and/or tearing to go away. I have not yet figured out what the issue is there, but it may also have to do with the computer going to sleep and restoring. Task Manager doesn't show anything hogging resources. I might have to go digging through the windows logs to see if there is something going on there. The Rift seems very sensitive to an interrupts in the system.

    My app usually runs at 85fps and is super smooth on a fresh bootup. But right now, for instance, it still reports 85fps, but I'm getting tearing and judder. None of the earlier tricks in this post help, except for system restart.
    September 15, 2014
    Interesting, I found this recurring Error log msg in the windows event viewer application logs:

    The description for Event ID 0 from source OculusVR cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.

    If the event originated on another computer, the display information had to be saved with the event.

    The following information was included with the event:

    Error: {ERR-018} [HMD] WARNING: Modulation stop unverified!


    This error gets triggered whenever I start my app. I'm going to reboot and see if the message goes away. Perhaps this is the cause of the erratic behavior and need for a restart.
    September 15, 2014
    Confirmed a reboot makes this error found in the windows application logs go away. Hopefully Oculus can shed some light on this issue as it appears to be the source of judder/tearing that only a reboot can fix.
    September 15, 2014
    Tried out 4.6 beta 18. Works exactly the same as 4.5.3f3 for me in terms of judder/tearing. Looking forward to messing around with the GUI stuff (been using NGUI for a while now with some custom headtracking code that has worked pretty well).
    New Participant
    September 18, 2014
    Great! The problem about DirectToRift.exe has been bothering me for a week. I always doubt it's a bug of Unity Integration package, or some compatibility issues with my laptop.
    Up and Coming
    October 17, 2014
    great post, thanks a lot! was working on the issue for a while now and had super bizarre results across different platforms , this fixed it.