Alpha-Blending Technology Overview

Source: Internet
Author: User

In today's games, whether 2D or 3D, alpha-blending technology is usually used in pursuit of transparent light and shade effects. Next, we will talk about Alpha-Blending Technology and briefly introduce the details of alpha-blending technology.Algorithm.

The so-called alpha-blending is actually mixing the source and target pixels according to the value of the "Alpha" hybrid vector. For ease of understanding, let's talk about the alpha-blending process between two pixels.

The first step is to separate the RGB color components of the source pixel from the target pixel, and then multiply the three color components of the source pixel by the Alpha value, then, multiply the three color components of the target pixel by the inverse value of Alpha, and then add the results according to the corresponding color components, divide the final result of each component by the maximum value of alpha (usually this step is done by shift, which is also the reason why the maximum value of Alpha is always a power of two ), finally, the three color components are combined into a pixel output.

In this process, we usually use the Mask Method to separate the RGB color components in pixels. As for the specific three mask values: rmask, gmask, and bmask, you can get the result from ddpixelformat in DirectDraw (of course, you can also perform various flexible processing as needed ).

In the descriptive routine given below, we assume that the rmask, gmask, and bmask have stored the bitmask values of RGB three color components. The maximum Alpha value is 256, source and DEST are pointers to source and target pixels.

Int ialpha = 256-* Alpha; // The Reverse value of alpha

* DEST = (rmask & (* Source & rmask) ** Alpha + (* DEST & rmask) * ialpha)> 8 )) | (gmask & (* Source & gmask) ** Alpha + (* DEST & gmask) * ialpha)> 8 )) | (bmask & (* Source & bmask) ** Alpha + (* DEST & bmask) * ialpha)> 8 ));

finally, what is alpha-blending? It's very easy. Let's try programming. If you are interested, I will introduce several other mixed methods next time. Please look forward to "several common pixel mixing methods 』.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.