The best way to combine colors in lighting tiles? (Xna)

I made a color, decent, recursive, fast tile lighting system in my game. It does everything I need, except for one thing: different colors do not mix at all:

Light Colors Not Blending

Here is my color combination 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 into account the already set color. color- the color of the previous light, which is weakened by the above code on factor. If I wanted to mix using an existing color, I would use a variable blend.

The following is an example of a combination that I tried with an error 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 mix produces inaccurate and strange results. I need a mixture that is accurate, like the first example that combines two colors together.

What is the best way to do this?

+4
1

, , , - :

return (new Color(
   (byte)MathHelper.Clamp(((color.R / factor_1 + blend.R / factor_2)), 0, 255),
   (byte)MathHelper.Clamp(((color.G / factor_1 + blend.G / factor_2)), 0, 255),
   (byte)MathHelper.Clamp(((color.B / factor_1 + blend.B / factor_2)), 0, 255)));

, , , (255,0,0) (0,255,0), (255,255,0), ? , , - (128, 128, 0). , , factor_2, . this. ( : [)

0

Source: https://habr.com/ru/post/1543632/


All Articles