In the first two days, I will introduce Alpha-beding technology to handle transparent light and shadow effects. In this time, I will introduce some other commonly used pixel mixing methods, which are generally used in the game to handle the light and shadow effect. "Alpha-beding" has been said before, the so-called alpha-beding is actually mixing the source pixels and target pixels in accordance with the value of "alpha" mixed vector, generally used to process translucent effects. "Additive-Blending" is that additive-beding is a method of mixing the pixel and the target pixel with a saturated method. Generally used to handle light sources, such as fire amputation of explosions, etc. Let's take a look at the additive-beding process between two pixels. The first step, first separate the RGB components of the source pixel and the target pixel, then add the corresponding color component, if the result of a component exceeds the maximum value of the component, the component is saturated, if The result is exceeded the maximum allowed value to take the maximum allowed value), and finally the three color components are re-incremented by a pixel output. In this process, in order to separate the three color components in the pixel, we generally use the method of mask. As for the specific three mask values: Rmask, Gmask, and Bmask, you can return from DDPixelFormat in DirectDraw (Of course, you can do a variety of flexibility according to your own needs). In the illustrative routine given below, we assume that RMASK, GMASK, and BMASK have been stored in the bit mask value of the RGB three color components, and the maximum value of the three color components is 255, and Source and Dest are directed. Pixel of pixels and target pixels.
Unsigned long tdest = 0; unsigned long t; t = (* source & rmask) (* dest & rmask); if (t> rmask) t = rmask; tdest | = t; t = (* source & gmask) (* DEST & GMASK); if (t> gmask) T = gmask; tdest | = T; t = (* source & bmask) (* dest & bmask); if (t> bmask) T = Bmask; TDest | = T; * DEST = (unsigned short) TDEST;