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