Several commonly used pixel mixing methods

zhaozj2021-02-08  252

● Fan Yipe

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"

The previous has been said, 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"

As for additive-beding, the color component of the source pixel and the target pixel is mixed 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 & gmas) (* Dest & gmas);

IF (t> gmas) t = gmask;

TDEST | = T;

T = (* Source & Bmask) (* Dest & Bmask);

IF (t> bmask) t = bmask;

TDEST | = T;

* DEST = (unsigned short) TDEST;

This code uses a small trick to handle saturation operations, that is, the results are used to measure whether or not the saturation calculation process is to be made.

Subtractive-Blending

Contrary to additive-beding, Subtractive-beding is a method of mixing source pixels and target pixels with saturated methods. FreeMind really likes to use it to handle shadows, and the shadow effect processed in this method can naturally be integrated with the environment.

As for the process of subtractive-beding, I am very similar to additive-beding, I will not be jealous. The only thing to note is that when the color component of the target pixel subtracts the color component of the source pixel, if the result is less than the allowable minimum value, the result is taken as the allowable minimum value (usually zero).

"Other mixing methods"

People who have played Photoshop know that there are many kinds of mixing methods between pixels, such as Multiplicative, Divisive, Maximum, Minimum, etc., but these methods are relatively slow, and there are few more requirements for these effects in the game. So there is very little use in actual games. If you have any new ideas and good ideas, you may also notify you, good things, let everyone share it, huh, huh :)

转载请注明原文地址:https://www.9cbs.com/read-1304.html

New Post(0)