Best way to blend colors in tile lighting? (XNA)
- by Lemoncreme
I have made a color, decent, recursive, fast tile lighting system in my game. It does everything I need except one thing: different colors are not blended at all:
Here is my color blend code:
return (new Color(
(byte)MathHelper.Clamp(color.R / factor, 0, 255),
(byte)MathHelper.Clamp(color.G / factor, 0, 255),
(byte)MathHelper.Clamp(color.B / factor, 0, 255)));
As you can see it does not take the already in place color into account. color is the color of the previous light, which is weakened by the above code by factor. If I wanted to blend using the color already in place, I would use the variable blend.
Here is an example of a blend that I tried that failed, using blend:
return (new Color(
(byte)MathHelper.Clamp(((color.R + blend.R) / 2) / factor, 0, 255),
(byte)MathHelper.Clamp(((color.G + blend.G) / 2) / factor, 0, 255),
(byte)MathHelper.Clamp(((color.B + blend.B) / 2) / factor, 0, 255)));
This color blend produces inaccurate and strange results. I need a blend that is accurate, like the first example, that blends the two colors together.
What is the best way to do this?