public static float LerpUnclamped(float a, float b, float t) { a = Mathf.Repeat(a, 1f); b = Mathf.Repeat(b, 1f); float delta = Mathf.Abs(b - a); if (delta < 0.5f) { return(Math.LerpUnclamped(a, b, t)); } else if (delta > 0.5f) { if (a < b) { return(Mathf.Repeat(Math.LerpUnclamped(a + 1f, b, t), 1f)); } else { return(Mathf.Repeat(Math.LerpUnclamped(a, b + 1f, t), 1f)); } } else { if (a < b) { return(Math.LerpUnclamped(a, b, t)); } else { return(Mathf.Repeat(Math.LerpUnclamped(a, b + 1f, t), 1f)); } } }
/// <summary> /// Performs a linear interpolation between the two colors specified for each color channel independently. /// </summary> /// <param name="a">The first color to be interpolated between, corresponding to a <paramref name="t"/> value of 0.</param> /// <param name="b">The second color to be interpolated between, corresponding to a <paramref name="t"/> value of 1.</param> /// <param name="t">The parameter specifying how much each color is weighted by the interpolation. Typically within the range [0, 1], but does not need to be, and will not be clamped.</param> /// <returns>A new color that is the result of the linear interpolation between the two original colors.</returns> /// <remarks> /// <para>When specifying a <paramref name="t"/> value outside the range [0, 1], the resulting color may no longer be /// within the valid range of the color space, even if the two original colors are within the valid range.</para> /// </remarks> /// <seealso cref="Lerp(ColorCMY, ColorCMY, float)"/> public static ColorCMY LerpUnclamped(ColorCMY a, ColorCMY b, float t) { return(new ColorCMY( Math.LerpUnclamped(a.c, b.c, t), Math.LerpUnclamped(a.m, b.m, t), Math.LerpUnclamped(a.y, b.y, t), Math.LerpUnclamped(a.a, b.a, t))); }
public static float LerpBackwardUnclamped(float a, float b, float t) { a = Mathf.Repeat(a, 1f); b = Mathf.Repeat(b, 1f); if (a >= b) { return(Math.LerpUnclamped(a, b, t)); } else { return(Mathf.Repeat(Math.LerpUnclamped(a + 1f, b, t), 1f)); } }