- Home /
vBlank Drift - Locking unity to the vBlank?
I'm working on a project where I need something to move -exactly- in time with the refresh rate of the screen (in my case, 60hz). vBlank gets really close to this, but there is a little drift, and this severely harms the look of my project. I have also tried syncing the motion with the "Time.frameCount", but that also leads to the same drift.
I have set the render settings to use vBlanks on single intervals (ie, 60hz), but it appears that it gets slightly out of sync when it cant completely render a frame. The object I'm displaying is just a cube in blank space, so it should render as fast as possible.
Any ideas?
Can you try to elaborate a little further on why you need to lock on to the actual rendering framerate? Is the framerate a key element in the project in a manner that prevents you from using FixedUpdate? You can totally control the rate at which something occurs using this method and Time.fixedDeltaTime ins$$anonymous$$d, if this is your goal.
Im outputting to a 3D display that uses a "sequential-frame" technique to get the two images. It refreshes at 60hz, and every other frame is a frame for an eye (ie. frame 1 is left, 2 right, 3 left, 4 right, so on). I have a script setup that moves the camera to the needed position every Update(). I'm not using FixedUpdate() because it does not lock to the vBlank. This method is very close to working, I -do- get a 3d image, but due to the drift, the eyes will invert every 5 seconds or so (causing a painful headache, heh).
That is probably one of the best possible reasons for needing to do this.
Answer by syclamoth · Oct 23, 2011 at 08:15 AM
How about this- change the Fixed-update time to be exactly 1/60 of a second, then in your Fixed Update render the camera manually using Camera.Render, to make sure that all the frames fall on the exact right times. Make sure that you disable the camera before doing this, since you will be manually managing all the camera work yourself. Pseudocode (mostly C#)-
void FixedUpdate()
{
// Move the camera to the right place, be it the left or the right eye
camera.Render();
}
Have you tried doing the rendering manually? I think that is the solution to your problem, there.
One added bonus to this method- you will never have any weirdness happening because of physics happening at a different time from the render step, because it all happens at the same time!
At first I thought it wasn't working, then I realized the display was incorrectly telling me it was in 3D mode. It wasn't switching the views, nothing worked, then I changed it's mode, and it was working fantastically. Near the bottom of the screen I get a bit of splitting, but that's much better than the eye-switching. We're going to be getting a more powerful video card soon, so that should fix the breakage.
Thanks for the help!
Your answer
Follow this Question
Related Questions
How does Time.deltaTime provide smoother physics functions? (Frame rate question) 2 Answers
Big frametime on iOS + intermittent cpu-waits-gpu 0 Answers
How to synchronize frame updates across a network of multiple (UDP) clients? 0 Answers
Animation frame size workaround? 0 Answers
Make Unity delay frame until VideoPlayer seek completed 0 Answers