The function lerp() is a common function in programming languages:
lerp(a, b, t) = a + t * (b - a).
Now for very many situatons I have an inverse function:
fraction(x, a, b) = (x - a) / (b - a).
This function is built so that
lerp(a, b, fraction(x, a, b)) == x
and
fraction(lerp(a, b, t), a, b) == t
However I'm not happy with the name "fraction". Is there a common name for this function?
GLSL's built-in functions include:
mix(), which works like your lerp() function.smoothstep(), which works like your inverse-lerp function combined with hermite smoothing and a x = clamp(x, 0.0, 1.0).
You could consider the name linearstep() for your implementation.
Unity's API includes:
Lerp()/LerpUnclamped()InverseLerp(), which does exactly what your inverse-lerp function does.
Note: I wouldn't use the name fraction()— it seems that it would be easily confused with fract()/frac(), which do something completely different.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With