Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Lower the Vive's frame rate

Discussion in 'AR/VR (XR) Discussion' started by majedzayer, Mar 2, 2017.

  1. majedzayer

    majedzayer

    Joined:
    Mar 23, 2016
    Posts:
    4
    Hello there,

    I would like to know if there's a way through which I could lower the frame rate of the Vive. Please note that I have already tried the following:
    • Added the following two lines of code in the body of the Start() method of my script:
      Code (CSharp):
      1. QualitySettings.vSyncCount = 0;
      2. Application.targetFrameRate =  myDesiredTargetFrameRate;
    • Commented the following lines of code at SteamVR_Render.cs:
      Code (CSharp):
      1. // Ensure various settings to minimize latency.
      2.         Application.targetFrameRate = -1;
      3.         Application.runInBackground = true; // don't require companion window focus
      4.         QualitySettings.maxQueuedFrames = -1;
      5.         QualitySettings.vSyncCount = 0; // this applies to the companion window
    And it didn't work. Please also note that doing step #1 in a fresh non-steamvr unity project brings down the frame rate. So I guess that there's something specific to the Vive that takes over my control to lower the frame rate.

    Please let me know if you need more info.
     
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    The vive is basically a monitor, you're trying to control the framerate of your application.

    If you use vsync, you can't use target frame rate. Target frame rate isn't even guaranteed, it's more like a ceiling than anything else. I don't know if steam vr has any quality setting plugs but you can search the solution to find out and suppress them.

    Maybe a little context into what you're trying to do would help.
     
  3. majedzayer

    majedzayer

    Joined:
    Mar 23, 2016
    Posts:
    4
    Hello LaneFox,

    Thanks for the prompt and detailed answer. Yes, I keep mixing the hardware and the software, which confuses others.

    I thought that setting the value of vSyncCount to zero will just turn off the synchronization between the screen's refresh rate the application's, giving me freedom to set the targetFrameRate, which is a wish more than a command, as you said. Please correct me if that's a misunderstanding.

    I searched all of steamVR's source code under their "Scripts" folder, and the only relevant lines of code that I found were the ones I commented them above as I mentioned in the post.

    I am trying to do collect data, the position of the Vive controller specifically, by recording it's
    Code (CSharp):
    1. transform.position
    vector at every call of
    Code (CSharp):
    1. Update()
    in a csv file. I would like to compare that with a different tracking data source that runs at the same time. The challenge is that the other tracking device has a sampling rate that is half the sampling rate of SteamVR's (i.e. 50 fps vs 100 fps). That's why I thought of reducing the refresh rate of SteamVR from 100 fps to 50 fps. Raising the refresh rate of the other tracking device is not an option.

    Thanks.
     
  4. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    Interesting.

    Well AFAIK you cannot guarantee a rate like hz in an application like this, its not like a deterministic os but you can use FixedUpdate() to record the data and probably get close to where you want to be. You can adjust the timestep of FixedUpdate, which can be ~ correlated to hz.
     
  5. majedzayer

    majedzayer

    Joined:
    Mar 23, 2016
    Posts:
    4
    Thanks LaneFox. I did an initial test and it seems that this has solved it.

    This is what I had in the Start() method:
    Code (CSharp):
    1. void Start()
    2. {
    3.    Time.fixedDeltaTime = 1/desiredSamplingRate;
    4. }
    In my case, desiredSmplingRate was set to 50 to get 50 readings per second. If it didn't go well after I implement the end-to-end script, I will post what happened for others to know.

    In either cases, thanks again LaneFox :)
     
    LaneFox likes this.
  6. bregu

    bregu

    Joined:
    May 7, 2014
    Posts:
    4
    Hi!

    I've came across a similar problem in my experiment as I had to sample consistently at 100Hz. I played with FixedUpdate, InvokeRepeating you name it. None of them gave me consistent results as they seems to be bound to the main unity thread - yes! even the FixedUpdate.

    Long story short I used a separate thread in combination with static class for data collection. Technically it makes no difference as the values are only updated at update frequency anyway but at least sampling rate is consistent ;)