[Feng yuchong] The shader of the unity3d tutorial book: 13th about Alpha Mixing

Source: Internet
Author: User
If the original article needs to be reproduced, please note: Reprinted from Fengyu Chong unity3d tutorial Institute

    
Lecture on shader 13th
Alpha hybrid



Alpha blending is transparent. In the final phase of grating. For example, if we add a material to a model, the color value calculated at a certain point is called the source, and the accumulated color value before the point is called the target.
Syntax blend off Not mixedBlend srcfactor dstfactor Srcfactor is the source coefficient, and dstfactor is the final color of the target coefficient. = (The vertex color value calculated by the shader * Source coefficient) + (cumulative vertex color * Target coefficient)
Property (value entered on srcfactor and dstfactor) One 1Zero 0Srccolor
Source RGB value, for example (0.5, 0.4, 1)Srcalpha   Source a value,
For example, 0.6 dstcolor RGB values of the hybrid target, such as (0.5, 0.4, 1)Dstalpha   The A value of the hybrid target, such as 0.6 oneminussrccolor (1, 1 )- Srccoloroneminussrcalpha 1- Srcalphaoneminusdstcolor (1, 1)
- Dstcoloroneminusdstalpha 1- Dstalpha
Algorithm example: (Note: The value range of R, G, B, A, x, y, and z is [0, 1].)
(R, G, B) * A = (R * a, G * a, B * A) (R, G, B) * (x, y, z) = (R * X, G * y, B * z) (R, G, B) + (X, y, z) = (R + X, G + Y, B + Z)(R, G, B )- (X, y, z) = (R-X, G-y, B-Z)

   Add the blend code to the shader used by the leaf Blend zero one:Only display the RGB part of the background, without Alpha transparent channel processing. Blend oneZero:Only display the RGB part of the texture. No Alpha transparent channel is available.  Channel A is 0, that is, the transparent area is also rendered. Blend oneOne:Pasters and backgrounds are superimposed without Alpha transparent channels. Only the superposition of color RGB values is closer to that of white (, 1. Blend srcalphaZero: only display texturesTexture processing with Alpha transparent channels. However, the transparent part in the texture, that is, the black part is not displayed in color, because the source color is multiplied by the Alpha value 0, and the color of the blending target is multiplied by zero 0, which is also 0. Therefore, the color of the transparent part is (0, 0, 0)

Blend srcalphaOneminussrcalpha:Final color = source color * Source transparency value + target color * (1-source transparency value) The most common transparent blending method. The high part of the texture's Alpha value is displayed, while the mixed background is light. The texture of the part with a high alpha value is highlighted, while the background is realistic. Example: (1) assume that the texture has an opaque red dot,
Color (,). The background color is opaque blue. Color (0, 0, 1, 1)Final color = (, 0) * 1 + (, 1) * (1-1) = (, 0)Conclusion 1: When the texture Alpha value is 1, only the texture is displayed and the background is not displayed.
(2) assume that the texture has a transparent red dot,
Color (,), the background color is transparent, but the value of channel B is 1, that is, the final color of color (,) = (, 0) * 0 + (, 1) * (1-0) = (, 1)Conclusion 2: When the texture Alpha value is 0, only the mixed target is displayed as the background. If the texture is not displayed but the target Alpha value is 0, the background of this point is transparent, but we have shown it, which is incorrect. Experience: In the texture with Channel A, the null position is not only the value of A is 0, but also the RGB value is 0, otherwise it is prone to errors. (3) assume that the texture has a translucent red dot,
Color (0.8, 0,). The background color is opaque blue. Color (0, 0, 1, 1)Final color = (0.8, 0) * 0.8 + (0.8, 1) * (1-0.2) = (, 0)And if 0.8 is changed to 0.2, the final color = (0.2, 0) * 0.2 + (0.2, 1) * (1-0.8) = (, 0)Conclusion: The larger the texture Alpha value, the more color the texture is. The smaller the Alpha value, the more color the mixed target is.
The blend combination has been mentioned so much. More Combinations need to be used by themselves. Now, let's look back at the introduction in the fifth lecture. Is there a sudden sensation?

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.