public static HSBColor Lerp(HSBColor a, HSBColor b, float t) { float angle = Mathf.LerpAngle(a.h * 360f, b.h * 360f, t); while (angle < 0f) { angle += 360f; } while (angle > 360f) { angle -= 360f; } return(new HSBColor(angle / 360f, Mathf.Lerp(a.s, b.s, t), Mathf.Lerp(a.b, b.b, t), Mathf.Lerp(a.a, b.a, t))); }
public void Apply(ref Color c, ref float t, VPaintActionType type) { HSBColor hsb = new HSBColor(c); switch (type) { case VPaintActionType.Brightness: if (brightnessAdjustment < 1f) { hsb.b = Mathf.Lerp(0, hsb.b, brightnessAdjustment); } else if (1f < brightnessAdjustment) { hsb.b = Mathf.Lerp(hsb.b, 1f, brightnessAdjustment - 1f); } c = hsb.ToColor(); break; case VPaintActionType.Saturation: hsb.s *= saturationAdjustment; c = hsb.ToColor(); break; case VPaintActionType.HueShift: hsb.h += hueAdjustment / 360f; if (1f < hsb.h) { hsb.h--; } c = hsb.ToColor(); break; case VPaintActionType.Contrast: if (1 < contrastAdjustment) { c.a = Mathf.Pow(c.a + contrastThreshhold, contrastAdjustment) - contrastThreshhold; c.r = Mathf.Pow(c.r + contrastThreshhold, contrastAdjustment) - contrastThreshhold; c.g = Mathf.Pow(c.g + contrastThreshhold, contrastAdjustment) - contrastThreshhold; c.b = Mathf.Pow(c.b + contrastThreshhold, contrastAdjustment) - contrastThreshhold; } else { c = Color.Lerp(Color.grey, c, contrastAdjustment); } break; case VPaintActionType.TintColor: float tintOpa = tintColorOpacity; if (tintUseValue) { if (tintInvertUseValue) { tintOpa *= hsb.b; } else { tintOpa *= 1 - hsb.b; } } c = Color.Lerp(c, tintColor, tintOpa); break; case VPaintActionType.OpacityAdjustment: t = Mathf.Clamp01(t * opacityAdjustment); break; } }