Skip to content
/ lerp Public

Frame rate independent linear interpolation function

License

Notifications You must be signed in to change notification settings

14islands/lerp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Frame rate independent linear interpolation function

This is a frame rate independent linear interpolation function based on this article. It uses https://www.npmjs.com/package/lerp under the hood.

var lerp = require('@14islands/lerp')

var res = lerp(a, b, t, frameDelta, targetFps);

Why?

Some devices only run at 30fps, for instance iOS in battery saving mode. Some devices run faster, for instance Oculus Quest 2 runs at 90 fps, Macbook M1 Max and gaming PCs run at 120 fps.

Usage

// classic lerp - works as expected
lerp(start, end, progress)

// Interpolates and adjusts for the frame delta. Default target is 60fps.
const frameDelta = clock.getDelta()
lerp(start, end, alpha, frameDeltaMs)

// Adjust for frame delta targeting a 120fps refresh rate.
const frameDelta = clock.getDelta()
lerp(start, end, alpha, frameDelta, 120)

Demo

Sandbox demo

License

MIT, see LICENSE.md for details.

About

Frame rate independent linear interpolation function

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published