I want to understand how does Color.Lerp works in unity.
According to this page it is quite clear to understand how to use it but I'm interested in how it is implemented. Does it work on RGB channels? and how? In the docs it says that the t factor is clamped between 0 and 1 so i wonder to know on which values Lerp works with Color.

up vote 5 down vote accepted

Color.Lerp in Unity works just as any lerp implementation, which works like this:

float lerp(float a, float b, float t)
    t = clamp01(t);
    return a + (b - a) * t;

Or with multiple components, like Color:

Color lerp(Color a, Color b, float t)
    t = clamp01(t);
    return new Color(
        a.r + (b.r - a.r) * t,
        a.g + (b.g - a.g) * t,
        a.b + (b.b - a.b) * t,
        a.a + (b.a - a.a) * t
  • 4
    tl;dr: it lerps each RGBA channel separately. – Philipp Dec 22 '15 at 14:35

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.