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?
Update:
I noticed that the reason simply adding them together and the above isn't working is because the light was spreading onto itself and blending with itself. I am going to try and prevent this by writing the light spread onto one array, a temporary one, not using blend
at all, only using the first method. After each light is finished with the recursion process I'll draw it to the main one using a custom pixel shader that will blend the light together properly. This may or may not solve my problem.