[Feng yuchong] unity3d tutorial book shader: 12th Alpha Testing

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

 
Lecture on shader 12th
Alpha Testing


Introduction: this and the next sections focus on Alpha, that is, the content related to transparent channels. Rgba, in which only RGB, red, green, and blue colors are displayed on the screen, and Alpha is not displayed in any color. A only supports color operations, especially multi-layer operations. For example, in the case of a single layer (0.8, 1, 0.8), the output is (0.8, 1) * 0.8, that is, light gray (0.8, 0.8, 0.8), and, 0.8) is equivalent. but if it is no longer a single layer and the background is green (0.8, 0.8), (0.8, 0.8,) does not know how to calculate it, and (, 1) yes. Can't read this introduction? It doesn't matter. Let's look at it. When I finish the fifth and sixth lectures, I will naturally understand it. What is a channel:The channel is an 8-bit grayscale image that can display 256 gray levels to represent the rgba value of the color. R = red, G = Green, B = blue, A = alhpa transparent value, RGB is the primary color channel, and a is the transparent channel. In the channel, use white instead of transparent to indicate the part to be processed (select region); use black to indicate the part that does not need to be processed (not selected region). The value range of all channels is [0,255]. but in the shader, the value range is [0, 1]. 0 and 1 correspond to 0 and 255. What is alpha channel:Definition: Generally, a graphics card has a 32-bit bus. The attached 8-bit signal is used to save invisible transparency signals for easy processing. This is the alpha channel. A white Alpha pixel is used to define an opaque color pixel, a black Alpha pixel is used to define a transparent pixel, and a gray scale between black and white is used to define a translucent pixel. In short, the alpha channel values are also [0,255] and shader []. The smaller the value, the more transparent the value. In the shader, 0 is transparent, nothing is displayed, and the editor is black. 1 is not transparent, all are displayed, the editor is displayed as white.

What is Alpha test:Alpha test: transparency test in Chinese. In short, the Alpha value of the point color value output by the last fragment function in V & F shader (that is, the output half4 of frag in the previous section) is compared with the fixed value. The alphatest statement is usually located at the starting position of pass. Syntax:First: alphatest off: not tested, full rendering; Second: Alpha comparator target Alpha value, where the target Alpha value ranges from 0 to 1. You can also use a parameter, for example, alphatest [varname]. Comparison operator:(X in the target Alpha value) always Full rendering (any x value)Never No RenderingGreater Rendering when the Alpha value of a vertex is greater than XGeuqal   If the Alpha value of a vertex is greater than or equal to X, rendering less When the Alpha value of a vertex is less than X, rendering lequal Rendering equal when the Alpha value of a vertex is less than or equal to X   Rendering when the Alpha value of a vertex is equal to XNotequal Rendering example when the Alpha value of a vertex is not equal to X: alphatest never 0 No rendering (this 0 can be any value, but it must be filled in)Alphatest always 0 Full rendering (this 0 can be any value, but it must be filled in)Alphatest off Full RenderingAlphatest greater 0.4 When Alpha is greater than 0.4, The disadvantage is that the edge is too sharp and the display is incomplete. The part with Alpha less than 0.4 is ignored.Alpha Blend The edge is soft, but the center is soft, and there is no physical feeling.Alphatest greater 0.4/alphatest lequal 0.4 is a mixture of more than 0.4 and less than 0.4. The effect is both physical feeling and Soft Edge.

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.