private static void GetHighlight( XnaHSL baseHSL, PaletteGenerator generator, PaletteParameters parameters, out XnaHSL highlight, out XnaHSL specular) { Color baseSpecular = PaletteGenerator.BaseSpecularColor(baseHSL.GetColor()); // Tint yellow XnaHSL specularHSL = new XnaHSL(baseSpecular); // If greyscale, simply treat the hue as yellow if (float.IsNaN(specularHSL.Hue)) { specularHSL = specularHSL.SetHue(60); } specularHSL = specularHSL.LerpHue(60, parameters.YellowLight); specularHSL = specularHSL.SetSaturation(MathHelper.Lerp( specularHSL.Saturation, 1f, parameters.YellowLight)); specularHSL = specularHSL.SetLightness(MathHelper.Lerp( specularHSL.Lightness, Math.Max(0.5f, specularHSL.Lightness), parameters.YellowLight)); // Add specular specularHSL = specularHSL.SetLightness(MathHelper.Lerp( specularHSL.Lightness, 1f, generator.Specularity)); // Reduce the lightness if the base color is darker than the generator color if (generator.BaseLightness > 0 && baseHSL.Lightness < generator.BaseLightness) { float lightnessDiff = generator.BaseLightness - baseHSL.Lightness; specularHSL = specularHSL.SetLightness(specularHSL.Lightness - (lightnessDiff)); } float highlightAmount = 0.5f; // If the base color is sufficiently bright, lighten the specular // to keep the contrast from getting too low float lightnessRatio = (baseHSL.Lightness - 0.5f) * 2f; if (lightnessRatio > 0) { specularHSL = specularHSL.SetLightness( MathHelper.Lerp(specularHSL.Lightness, 1f, lightnessRatio)); highlightAmount = MathHelper.Lerp(0.5f, 1f, lightnessRatio); } // Get highlight XnaHSL highlightHSL = XnaHSL.Lerp(baseHSL, specularHSL, highlightAmount); highlight = highlightHSL; specular = specularHSL; }
private static void GetShadow( XnaHSL baseHSL, PaletteGenerator generator, PaletteParameters parameters, out XnaHSL shadow, out XnaHSL darkest) { XnaHSL blackHSL = new XnaHSL( baseHSL.Hue, baseHSL.Saturation * generator.ShadowAmount, generator.BlackLevel, baseHSL.Alpha); // If the base color is sufficiently bright, lighten the darker shades float lightnessRatio = (baseHSL.Lightness - 0.5f) * 2f; if (lightnessRatio > 0) { blackHSL = blackHSL.SetSaturation(blackHSL.Saturation * (1f - lightnessRatio * 0.95f)); float blackLuma = Color_Util.GetLuma(blackHSL.GetColor()); // Increase the lightness by more if it's a color with a low // luma to lightness ratio float lumaRatio = 1f; if (blackLuma > 0) { lumaRatio = blackHSL.Lightness / blackLuma; } blackHSL = blackHSL.SetLightness( MathHelper.Lerp(blackHSL.Lightness, MathHelper.Lerp(blackHSL.Lightness, 1f, 0.25f), lightnessRatio * lumaRatio)); } // Tint black and shadow blue blackHSL = blackHSL.LerpHue(240, parameters.BlueShadow); blackHSL = blackHSL.SetSaturation(MathHelper.Lerp(blackHSL.Saturation, 1f, parameters.BlueShadow / 4f)); XnaHSL shadowHSL = XnaHSL.Lerp(blackHSL, baseHSL, generator.ShadowAmount); shadowHSL = shadowHSL.SetSaturation(MathHelper.Lerp(blackHSL.Saturation, baseHSL.Saturation, 0.5f)); shadowHSL = shadowHSL.SetHue(blackHSL.Hue); shadowHSL = shadowHSL.LerpHue(baseHSL.Hue, 0.25f); shadow = shadowHSL; darkest = blackHSL; }