Framerate-independent stair-step smoothing
Posted: Fri Feb 22, 2013 10:02 pm
Here's another one. The problem with stair-step smoothing is that it accumulates lots of tiny floats; run fast enough and precision errors build up. Here's a stab at fixing it. all changes to view.c, so declare these at the top:
Now find the "smooth out stair step ups" block and replace with:
Finally add the following function and call it from somewhere in R_NewMap:
So, instead of accumulating lots of tiny deltas we're working off absolute differences with far lower precision loss.
Code: Select all
float v_oldz, v_stepz;
float v_steptime;
Code: Select all
// smooth out stair step ups
if (cl.onground && ent->origin[2] - v_stepz > 0)
{
v_stepz = v_oldz + (cl.time - v_steptime) * 80; // BJP Quake used 160 here
if (v_stepz > ent->origin[2])
{
v_steptime = cl.time;
v_stepz = v_oldz = ent->origin[2];
}
if (ent->origin[2] - v_stepz > 12)
{
v_steptime = cl.time;
v_stepz = v_oldz = ent->origin[2] - 12;
}
r_refdef.vieworigin[2] += v_stepz - ent->origin[2];
view->origin[2] += v_stepz - ent->origin[2];
}
else
{
v_oldz = v_stepz = ent->origin[2];
v_steptime = cl.time;
}
Code: Select all
void V_NewMap (void)
{
v_oldz = v_stepz = 0;
v_steptime = 0;
}