cancel
Showing results for 
Search instead for 
Did you mean: 

Unity troubleshooting latency notes

jjerald
Honored Guest
I have my nvidia graphics card setttings to always NOT wait on vertical sync. My opinion is that simulator sickness is worse than tearing artifacts. Personally I don't notice tearing unless I am explicitly looking for it. I may not always visually notice latency when not looking for it but I do risk feeling additional latency and not being able to play as long.

Someone that played my VRJam game provided some feedback that the game felt slow and that resulted in him not feeling well. I started to investigate this by playing with vertical sync and some other settings (since I don't know how others have their graphics card configured). Unfortunately I found for Unity, turning vsync on adds significant latency. Of course some latency is expected when waiting on vsync but it is looking like about 3 frames or ~50 milliseconds of additional latency (60 Hz update rate when waiting on vsync, ~80 Hz update rate when not waiting on vsync). 50 additional milliseconds of latency in an HMD is very noticeable and makes the game difficult to play for long without feeling nauseous.

I also found the following line in OVRCameraController.cs that gets called if you have Edit->Project Settings->Quality set to "Fantastic".
QualitySettings.vSyncCount = 1;
This means that if you have your graphics card vertical sync settings to "use the 3D application settings" then you will wait on vsync even if you set within Unity Edit->Project Settings->Quality->Vsync Count to "Don't Sync". In other words for the "Fantastic" setting the Unity UI vsync setting is ignored. Because of this I comment out the above line of code so the "Fantastic" Unity UI vsync setting works as intended. This wouldn't be that bad if 0-1 frames of latency latency was added as should happen when waiting on vysnc but ~3 frames of latency is very bad. I also played with the QualitySettings.maxQueuedFrames but could not see a difference.

I also played with the nvidia setting "Maximum pre-rendered frames" that I previously had set to "Use the 3D application setting". I found when I set this to "1" (and waiting on vsync) then there is less latency but some form of jitter occurs when moving your head. Setting it to "2" or higher results in smooth movement but more latency. Not waiting on vsync with the max pre-rendered frames set to 1 results in low latency with no jitter.

It is possible that some of these issues may be specific to my computer/environment. I am using the following:
1. Windows 7 (Windows 7 Basic theme since the Windows Aero theme adds a frame of latency)
2. Unity 4.2.1
3. Nvidia GTX 680m (Triple buffering off)
4. Tested with both single monitor and dual monitors without noticeable difference
5. DirectX 11

Is anyone else experiencing similar or related latency issues on other systems? This seems like a major risk of users getting sick, especially once we all start shipping to users that don't understand latency or have their graphics cards settings optimized for VR.

Jason
12 REPLIES 12

drash
Heroic Explorer
That's disturbing if Unity's vsync is adding ~3 frames worth of latency. I've also commented out that line in OVRCameraController that forces vsync on -- I don't like that it's forced on despite the quality settings. I haven't really been able to pin it down but sometimes I can feel the latency from Unity's vsync big time (I feel sorta drunk), and sometimes not at all (feels just like with vsync off). Is this possibly a perceptual thing, like perhaps I can sense the latency if I'm tired but not if I'm wide awake, or vice versa?

Interesting comments on the "Maximum pre-rendered frames" setting in Nvidia control panel. I just tried setting this to 1 as you mentioned, and I thought I perceived a drastic improvement, but then switching back and forth between "Use the 3D application setting" and 1, I can't really tell anymore. The effect must be pretty subtle or I'm going crazy or something. 🙂

Anonymous
Not applicable
Thank you for posting this! I had no idea it was forcing vsync. I will comment that out as soon as I get home from work tonight. It explains a bit of confusion I've been having recently. After some drastic performance improvements, I turned off vsync to see if I was getting closer to my goal of 70-80fps, but it just kept hovering right around 60.. Thought it might be coincidence but this explains it!

chaosgrid
Explorer
While testing the Hydra latency, I also found that VSync in Unity adds significant delay (as you said, about 3 frames).
However, I'm not sure if the head tracking of Oculus was affected, because that always seemed very smooth and low latency.. maybe Oculus is doing some tricks here? Or is the headtracking also laggy for you with VSync? I mean, 3 frames (50+ msec) are definately noticeable.

ChrisJD
Honored Guest
"drash" wrote:
I haven't really been able to pin it down but sometimes I can feel the latency from Unity's vsync big time (I feel sorta drunk), and sometimes not at all (feels just like with vsync off).


This might be slightly off-topic but if you're noticing that in the same game session maybe it's the mag correction being applied. I was noticing times where things felt off and after some playing around I determined that it was when the magnetic yaw correction was being applied. I haven't tried tweaking the mag correction at all yet to see if I can find better settings.

jjerald
Honored Guest
"drash" wrote:
That's disturbing if Unity's vsync is adding ~3 frames worth of latency. I've also commented out that line in OVRCameraController that forces vsync on -- I don't like that it's forced on despite the quality settings. I haven't really been able to pin it down but sometimes I can feel the latency from Unity's vsync big time (I feel sorta drunk), and sometimes not at all (feels just like with vsync off). Is this possibly a perceptual thing, like perhaps I can sense the latency if I'm tired but not if I'm wide awake, or vice versa?

There are a ton of factors. There is some scientific evidence for some of those factors but not others. That is one of the things that makes studying latency perception so challenging.

"drash" wrote:
Interesting comments on the "Maximum pre-rendered frames" setting in Nvidia control panel. I just tried setting this to 1 as you mentioned, and I thought I perceived a drastic improvement, but then switching back and forth between "Use the 3D application setting" and 1, I can't really tell anymore. The effect must be pretty subtle or I'm going crazy or something. 🙂


The way I test latency is by rotating my head very quickly and to look for the scene first moving with your head and then moving back in the opposite direction to its intended position. A better objective way to measure latency is to take video of the Rift in front of the monitor. Then count the number of frames from when the Rift starts moving to the time the scene starts to move. Note your monitor will have a different response then the Rift but at least you can tell the differences between settings. Take multiple measurements to get more accurate estimates.

The latency meter that Oculus is supposedly releasing soon will make testing these sort of changes much easier.

Jason

jjerald
Honored Guest
"phillipfoshee" wrote:
Thank you for posting this! I had no idea it was forcing vsync. I will comment that out as soon as I get home from work tonight. It explains a bit of confusion I've been having recently. After some drastic performance improvements, I turned off vsync to see if I was getting closer to my goal of 70-80fps, but it just kept hovering right around 60.. Thought it might be coincidence but this explains it!


Yes and whats worse is if you wait on vsync and dip below 60 Hz then the frame rate will actually drop to 30 Hz due to just missing the vysnc signal and then having to wait another frame.

Jason

jjerald
Honored Guest
"chaosgrid" wrote:
While testing the Hydra latency, I also found that VSync in Unity adds significant delay (as you said, about 3 frames).
However, I'm not sure if the head tracking of Oculus was affected, because that always seemed very smooth and low latency.. maybe Oculus is doing some tricks here? Or is the headtracking also laggy for you with VSync? I mean, 3 frames (50+ msec) are definately noticeable.


Yeah magnetic correction can sometimes add some similar "swimming" effects. I have played with magnetic correction with another non-Oculus HMD system and have not been happy with the results due to the magnetic field changing relative to the magnetometer as you change the position of your head. I haven't had a chance to play with the Oculus magnetic correction yet. Hopefully it is a better solution than what I was trying.

In the case I was testing, it was definitely a latency issue since I have magnetic correction off.

Oculus has some prediction code which can make it seem much faster. Because it is using a gyroscope, prediction can work quite well for up to about 30 milliseconds of latency. Once you start predicting too far you start noticing overshoot and that can make it worse than no prediction.

Jason

rincewind
Honored Guest
So no any fix for that yet?

I've made a scene and while I run it in the editor everything is perfect.
When i run the compiled one with "fantastic" graphics settings i notice that lag with tracking.

drash
Heroic Explorer
"jjerald" wrote:
I also found the following line in OVRCameraController.cs that gets called if you have Edit->Project Settings->Quality set to "Fantastic".
QualitySettings.vSyncCount = 1;
This means that if you have your graphics card vertical sync settings to "use the 3D application settings" then you will wait on vsync even if you set within Unity Edit->Project Settings->Quality->Vsync Count to "Don't Sync". In other words for the "Fantastic" setting the Unity UI vsync setting is ignored. Because of this I comment out the above line of code so the "Fantastic" Unity UI vsync setting works as intended. This wouldn't be that bad if 0-1 frames of latency latency was added as should happen when waiting on vysnc but ~3 frames of latency is very bad. I also played with the QualitySettings.maxQueuedFrames but could not see a difference.


Searching (duckduckgo'ing) "maxQueuedFrames" on the web took me to this post in first couple of hits. 🙂

Just as a random follow-up regarding the QualitySettings.maxQueuedFrames value making a difference or not, the latency tester shows that if vsync is off, maxQueuedFrames does not seem to make a difference (only tested 0 and 1). But if vsync is on, then each maxQueuedFrames seems to add another 20ms of latency.

Vsync Off + 0 MaxQueuedFrames = ~20ms
Vsync Off + 1 MaxQueuedFrames = ~20ms
Vsync On + 0 MaxQueuedFrames = ~40ms
Vsync On + 1 MaxQueuedFrames = ~60ms

So that's that.

Really looking forward to future Rifts getting that core latency down so that I can feel comfortable with vsync on. Right now it's tough not having the best of both worlds just yet!