Forum Discussion

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

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.

17 Replies

Replies have been turned off for this discussion