Why deltas fluctuate and how to fix them

Hey, I'm working on an open source game engine and I started looking at frame delta fluctuations and how to best correct for them. I found a simple solution that other devs can implement in their games to eliminate the stutter caused by frame rate fluctuations. I wrote two articles about it, my first article describes the technical details and code, my second article is a thought experiment to help people understand what's going on.

http://frankforce.com/?p=2636 - Time delta smoothing
http://frankforce.com/?p=3522 - A rendering thought experiment

Here is my code that fixes the issue. This goes at the very top of your update, before your normal fixed time step update or anything else that uses the delta time...

Code:
// this buffer keeps track of the extra bits of time
static float deltaBuffer = 0;

// add in whatever time we currently have saved in the buffer
delta += deltaBuffer;

// calculate how many frames will have passed on the next vsync
const int refreshRate = GetMonitorRefreshRate();
int frameCount = (int)(delta * refreshRate + 1);

// if less then a full frame, increase delta to cover the extra
if (frameCount <= 0)	frameCount = 1;

// save off the delta, we will need it later to update the buffer
const float oldDelta = delta;

// recalculate delta to be an even frame rate multiple
delta = frameCount / (float)refreshRate;

// update delta buffer so we keep the same time on average
deltaBuffer = oldDelta - delta;

Here's a slide from AMD talking about the issue to help illustrate the issue I am correcting...

gng7rNV.png


I'd really like to get some intelligent discussion going on about the issue, but it's been difficult. There is not a very good understanding of time delta fluctuations and it seems like expert programmers are dismissing this as a novice issue. I've been in the industry a very long time at major studios, going indie now. Take a look at this video of my open source game engine as proof that I must know something about computer graphics.

Anyway, what do you guys think? Do you do anything to help smooth out your delta like averaging or capping? Can anyone try my code in their engine and see if it makes a difference?
 
Back
Top