Skip to content

Instantly share code, notes, and snippets.

@halgrimmur
Created August 13, 2018 18:18
Show Gist options
  • Save halgrimmur/4ee589e379997d98dac10c67db889f9e to your computer and use it in GitHub Desktop.
Save halgrimmur/4ee589e379997d98dac10c67db889f9e to your computer and use it in GitHub Desktop.
Mixing Colors in Unity, Water-Color style, by (negative) Averaging!
// Calculates the average of all colors in the list.
// Normal averaging would yield additive color mixing,
// ... i.e. the way *light* of color would mix.
// Colored liquids, like water colors, mix in a
// subtractive way, though, i.e. red+blue = purple.
// See https://en.wikipedia.org/wiki/Color_mixing
Color GetSubtractiveAverageColor(List<Color> colors)
{
var invertedColorSum = Color.black;
foreach (var color in colors)
{
invertedColorSum += Color.white - color;
}
return Color.white - invertedColorSum / colors.Count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment