Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Linear interpolation
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Programming language support== Many libraries and [[shading language]]s have a "lerp" helper-function (in [[GLSL]] known instead as '''mix'''), returning an interpolation between two inputs <code>(v0, v1)</code> for a parameter <code>t</code> in the closed unit interval [0, 1]. Signatures between lerp functions are variously implemented in both the forms <code>(v0, v1, t)</code> and <code>(t, v0, v1)</code>. <syntaxhighlight lang="c" line> // Imprecise method, which does not guarantee v = v1 when t = 1, due to floating-point arithmetic error. // This method is monotonic. This form may be used when the hardware has a native fused multiply-add instruction. float lerp(float v0, float v1, float t) { return v0 + t * (v1 - v0); } // Precise method, which guarantees v = v1 when t = 1. This method is monotonic only when v0 * v1 < 0. // Lerping between same values might not produce the same value float lerp(float v0, float v1, float t) { return (1 - t) * v0 + t * v1; } </syntaxhighlight> This lerp function is commonly used for [[alpha blending]] (the parameter "{{var|t}}" is the "alpha value"), and the formula may be extended to blend multiple components of a vector (such as spatial ''x'', ''y'', ''z'' axes or ''r'', ''g'', ''b'' colour components) in parallel.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)