Unity3D tutorial: 2D game skill effects

In our 2D graphics games, a large number of light and shadow and skill special effects are indispensable, such as the realization of magic effects in Diablo II. Fortunately, we have a powerful CPU to achieve Alpha blending and color saturation blending for us. Next, let's discuss How to use these methods to achieve the skill special effects we need in the game.

    1. Alpha blending effect
    Alpha blending allows us to mix an image with another image in a certain proportion (as shown in Figure 1), but ordinary Alpha blending is not suitable for skill special effects in games. It shows that at this time we only need to add some data to make the mixing more accurate. In order to achieve this effect, we add Alpha channel data to the image (as shown in Figure 2), and then we mix according to the channel data to get as Does the blending effect in Figure 3 look more like a special effect now?
    However, there are still problems. As long as you observe carefully, it is not difficult to find that there are black shadows around the special effects in Figure 3. This seems to add a little flaw to our skill effects. Why is this so? Because our program performs different degrees of Alpha blending processing according to the channel data on the image, but the RGB color value is actually closer to black (R=0, G=0, B=0) at the edge of the special effect, once this After mixing, there will definitely be black edges around, but you can rest assured that here we can use a simple trick to easily avoid black edges, that is, fill the RGB color map in Figure 2 with a gray background, so that after mixing There will be no black borders, at least not as obvious as before. There is no final rendering here, and the final effect should be realized by your own program.

 

 

 

 2. Color saturation special effects

    Compared with Alpha blending, color saturation is more suitable for the production of special effects. In terms of performance and effect, color saturation is better than Alpha blending (as shown in Figure 4). Perhaps because the algorithm of color saturation is too simple, there are few introductions. Let’s introduce the method of color saturation first. The mixing formula: R1, G1, B1: the source color

    value of the image pixel;

    R2, G2 , B2 : source color value of basemap pixels;

    R = R1 + R2; ( IF R > 255 THEN R = 255 ) G

    = G1 + G2 ; ( IF G > 255 THEN G = 255 )

    B = B1 + B2; ( IF B > 255 THEN B = 255 )

    R, G, B is the mixed result we need.

    You may think that such complex calculations are better than Alpha blending in terms of performance. Of course, if all you use are regular CPU instructions, then indeed, the performance is not as fast as Alpha, but now MMX instructions have been used as CPU instructions. The basic instruction, MMX instruction has a CPU instruction of saturation plus, which can be operated very conveniently. I have to thank the CPU manufacturer for its contribution.

    Well, both methods have been introduced. It can be said that this is basically capable of meeting the needs of 2D games. Next, let us make the game more exciting.

 

Guess you like

Origin blog.csdn.net/weixin_55688630/article/details/128402360