Interpretation of the shader Series 6 Written by CG in unity -- opacity and Mixing

Source: Internet
Author: User

1. opacity when we need to map two semi-transparent textures to a material ball, we will encounter the problem of mixing, because of the previous knowledge, we already know the part coloring tool and the main work behind it is to output the color and depth to the frame cache, so what is the form of mixing the colors of two textures on each pixel and finally outputting them to the frame cache.

1. Hybrid (blending)
One of the operations in the "frame-by-frame" section in the pipeline section in the previous article is the Hybrid Operation. It can be seen that the hybrid operation is an unprogrammable fixed function step.
In the hybrid operation, the color calculated in the fragment shader is called "Source color", and the existing color of the corresponding pixel in the frame cache is called "target color ". The blending operation combines the source color with the target color with some options.
Since it is a fixed function stage, we can only select these options and cannot write them.
The process of selecting the mixed options is to calculate the rgba color using the following equations:
Float4 result = srcfactor * fragment_output + dstfactor * pixel_color;


I still want to express the above equation in graphics:

In unity, the shader uses the shaderlab syntax to express the mixed operation process as follows:
 
Blend srcfactor dstfactor

The following table lists the options available for these two codes:

Option Code

Equivalent code

One

Float4 (1.0)

Zero

Float4 (0.0)

Srccolor

Fragment_output

Srcalpha

Float4 (fragment_output.a)

Dstcolor

Pixel_color

Dstalpha

Float4 (pixel_color.a)

Oneminussrccolor

Float4 (1.0)-fragment_output

Oneminussrcalpha

Float4( 1.0-fragment_output.a)

Oneminusdstcolor

Float4 (1.0)-pixel_color

Oneminusdstalpha

Float4 (1.0-pixel_color.a)


Float4 (1.0) is written as we have seen before. It is equivalent to float4 (1.0, 1.0, 1.0, 1.0)

And the component intervals of all vectors are [0, 1. 2. Sequence-independent opacity


1. Addition and Mixing


Interpretation of the shader Series 6 Written by CG in unity -- opacity and Mixing

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.