reprinted from the Wind Yu Chong Unity3d Tutorial College
Alpha Blending, Chinese translation alpha blendblending is the control of transparency. In the final phase of rasterization. Here for example we put a material for a model, then at a point calculated that the color value is called the source, and the point before the accumulated color value, called the target. GrammarBlend Off does not mixBlend srcfactor dstfactor srcfactor is the source factor, and Dstfactor is the target factorFinal color = (shader calculated point color value * source factor) + (point cumulative color * target factor) attributes (values filled to srcfactor,dstfactor)One 1Zero 0Srccolor The RGB value of the source, for example (0.5,0.4,1)a value of the Srcalpha source, such as 0.6Dstcolor RGB values for mixed targets for example (0.5,0.4,1)Dstalpha A value for the mixed target such as 0.6Oneminussrccolor (1,1,1)-SrccolorOneminussrcalpha 1-srcalphaOneminusdstcolor (1,1,1)-DstcolorOneminusdstalpha 1-dstalpha examples of algorithms:(Note: The R,g,b,a,x,y,z value range 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 in the leaves
Blend Zero One: displays only the RGB portion of the background, no alpha transparent channel processing.
Blend One zero:onlyDisplays the RGB portion of the map with no alpha transparent channel processing.
A channel of 0 that should be transparent place also rendered out.
Blend One One:Map and background overlay, no alpha transparent channel processing. Only the color RGB value overlay is closer to White (1,1,1).
Blend Srcalpha Zero: Show only stickers, the map contains alpha transparent channel processing. However, the transparent part of the map, that is, the black part has no color to display because the source color is multiplied by the alpha value of 0, 0, and the color of the blend target is multiplied by zero 0, which is also 0. So the transparent part shows the color as (0,0,0)
Blend srcalpha Oneminussrcalpha:Final color = Source color * Source Transparency value + target Color * (1-source transparency value) the most common transparent blending method. The portion of the high alpha value of the map is displayed, while the blend background is very light. And the high alpha part, the map appears light, and the background is real. Example: (1) Assuming that the map has an opaque red dot, color (1,0,0,1), the point background color is opaque blue color (0,0,1,1) Final color = (1,0,0) * 1+ (0,0,1) * (1-1) = (1,0,0)Conclusion One: The map alpha value is 1 o'clock, only the map is displayed, the background is not displayed(2) Assume that the map has a transparent red dot, color (1,0,0,0), the point background color is transparent, but the B channel value is 1, that is, color (0,0,1,0) Final color = (1,0,0) * 0+ (0,0,1) * (1-0) = (0,0,1)Conclusion Two: The map alpha value is 0 o'clock, only the blend target is the background and the map is not displayed.But the target alpha value is 0, that is, the background of the point is transparent, and we show it, which is not right.experience: A map with a channel, empty place not only a value of 0,rgb value is also 0, otherwise error prone. (3) Assume that the map has a translucent red dot, color (1,0,0,0.8), the point background color is opaque blue color (0,0,1,1) Final color = (1,0,0) * 0.8+ (0,0,1) * (1-0.8) = (0.8,0,0.2) and if 0.8 becomes 0.2, the final color = (1,0,0) * 0.2+ (0,0,1) * (1-0.2) = (0.2,0,0.8)Conclusion: The larger the map alpha value, the more the color tends to be mapped; the smaller the alpha value, the more the color tends to the mixed targetBlend combination of the situation first said so much, more combinations need to try to use, now please look back to see the introduction of the five, is there a sense of a sudden feeling?
Unity3d Tutorial Shader: 13th, alpha mixing