Created
August 13, 2018 18:18
-
-
Save halgrimmur/4ee589e379997d98dac10c67db889f9e to your computer and use it in GitHub Desktop.
Mixing Colors in Unity, Water-Color style, by (negative) Averaging!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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