public Color GetDesaturatedColor() { RXColorHSL hsl = RXColor.HSLFromColor(_upColor); hsl.s = 0.25f; hsl.l = 0.6f; return(RXColor.ColorFromHSL(hsl)); }
// // Math for the conversion found here: http://www.easyrgb.com/index.php?X=MATH // public static RXColorHSL HSLFromColor(Color rgb) { RXColorHSL c = new RXColorHSL(); float r = rgb.r; float g = rgb.g; float b = rgb.b; float minChan = Mathf.Min(r, g, b); //Min. value of RGB float maxChan = Mathf.Max(r, g, b); //Max. value of RGB float deltaMax = maxChan - minChan; c.l = (maxChan + minChan) * 0.5f; if (Mathf.Abs(deltaMax) <= 0.0001f) //This is a gray, no chroma... { c.h = 0; //HSL results from 0 to 1 c.s = 0; } else //Chromatic data... { if (c.l < 0.5f) { c.s = deltaMax / (maxChan + minChan); } else { c.s = deltaMax / (2.0f - maxChan - minChan); } float deltaR = (((maxChan - r) / 6.0f) + (deltaMax * 0.5f)) / deltaMax; float deltaG = (((maxChan - g) / 6.0f) + (deltaMax * 0.5f)) / deltaMax; float deltaB = (((maxChan - b) / 6.0f) + (deltaMax * 0.5f)) / deltaMax; if (Mathf.Approximately(r, maxChan)) { c.h = deltaB - deltaG; } else if (Mathf.Approximately(g, maxChan)) { c.h = (1.0f / 3.0f) + deltaR - deltaB; } else if (Mathf.Approximately(b, maxChan)) { c.h = (2.0f / 3.0f) + deltaG - deltaR; } if (c.h < 0.0f) { c.h += 1.0f; } else if (c.h > 1.0f) { c.h -= 1.0f; } } return(c); }
public static Color ColorFromHSL(RXColorHSL hsl) { return(ColorFromHSL(hsl.h, hsl.s, hsl.l)); }