Unity3d shader official tutorial translation (11) -- shader Syntax: Pass Blending (hybrid)

Source: Internet
Author: User
Shaderlab Syntax: blending Hybrid

Blending is used to make transparent objects.

Mixing is used to make transparent objects.

When graphics are rendered, After all shaders have executed and all textures have been applied, the pixels are written to the screen. how they are combined with what is already there is controlled by the blend command.

After all the pasters are executed, all textures are applied, and all pixels are ready to be presented to the screen, use the blend command to operate on these pixels for mixing.

Guidance:

Blend is a technology that combines the source and target colors to generate special effects in some way. A mixture is often used to draw transparent or translucent objects. The α value that plays a key role in blending is actually mixing the source and target colors at a given ratio to achieve different levels of transparency. If the α value is 0, it is completely transparent, and if the α value is 1, it is completely opaque. The hybrid operation can only be performed in rgba mode, and the α value cannot be specified in color index mode. The Rendering sequence of objects affects the mixed processing of OpenGL.

Reference: Workshop

Syntax blend off
Turn Off Blending
Disable Hybrid
Blend srcfactor dstfactor
Configure & enable blending. The generated color is multiplied by Srcfactor. The color already on screen is multiplied DstfactorAnd the two are added
Together.
Configure and enable hybrid. The calculated color is multiplied by srcfactore. The color already on the screen is multiplied by dstfactor, and then the two colors are added together.
Blend srcfactor dstfactor, srcfactora dstfactora
Same as abve, but use different factors for blending the alpha channel.
It is the same as above, but some factors are different. Srcfactora dstfactoraThese factors are mixed using alpha channels.
Blendop min | max | sub | revsub
Instead of adding blended colors together, do a different operation on them.
Instead of mixing the colors, you can perform different operations on them.
Properties

All following properties are valid for both srcfactor & dstfactor.SourceRefers to the calculated color,DestinationIs the color already on the screen.

All the attributes listed below are valid for srcfactor & dstfactor.SourceIs the calculated color,DestinationIt refers to the color of an existing screen.

One

The value of One-use this to let either the source or the destination color come through fully.
The value is 1. Use this setting to make the source or target color pass completely.

 

Zero

The value zero-use this to remove either the source or the destination values.
The value is 0. Use this setting to delete the source or target value.

 

Srccolor

The value of this stage is multiplied by the source color value.
The value of this phase is multiplied by the value of the source color.

 

Srcalpha

The value of this stage is multiplied by the source Alpha value.
The value of this phase is multiplied by the source Alpha value.

 

Dstcolor

The value of this stage is multiplied by frame buffer source color value.
The value of this phase is multiplied by the value of the source color in the source frame buffer.

 

Dstalpha

The value of this stage is multiplied by frame buffer source Alpha value.
The value of this phase is multiplied by the value of source alpha in the source frame buffer.

 

Oneminussrccolor

The value of this stage is multiplied by (1-source color ).
The value of this phase is multiplied by the value of (1-source color.

 

Oneminussrcalpha

The value of this stage is multiplied by (1-source alpha ).
The value of this phase is multiplied by the value of (1-source alpha.

 

Oneminusdstcolor

The value of this stage is multiplied by (1-destination color ).
The value of this phase is multiplied by the value of (1-target color.

 

Oneminusdstalpha

The value of this stage is multiplied by (1-destination alpha ).
The value of this phase is multiplied by the value of (1-Target Alpha.

 

Details details

Below are the most common blend types:

The following are the most frequently used hybrid types

Blend srcalpha oneminussrcalpha // alpha blending Alpha hybrid blend one // additive hybrid blend one hybrid Hybrid/soft additive soft addition hybrid blend dstcolor zero // multiplicative multiply hybrid blend dstcolor srccolor // 2x multiplicative 2x multiply
Example

Here is a small example shader that adds a texture to whatever is on the screen already:

Here is a small example of a shadow: Add a texture to the screen, whether or not it is already on the screen.

Shader "Simple Additive" {    Properties {        _MainTex ("Texture to blend", 2D) = "black" {}    }    SubShader {        Tags { "Queue" = "Transparent" }        Pass {            Blend One One            SetTexture [_MainTex] { combine texture }        }    }}

And a more complex one, glass. This is a two-pass shader:

1 more complex coloring tool: glass. It contains 2 pass

  1. The first pass renders a pair, alpha-blended texture on to the screen. The alpha channel decides the transparency.
    The first pass renders the light and the texture in an Alpha mixture to the screen. The alpha channel determines its transparency.

The second pass renders a reflection cubemap on top of the alpha-blended window, using additive transparency.

The second pass renders a reflection Cube Texture at the top of the alpha-mixed window and uses the additional transparency.

Shader "Glass" {    Properties {        _Color ("Main Color", Color) = (1,1,1,1)        _MainTex ("Base (RGB) Transparency (A)", 2D) = "white" {}        _Reflections ("Base (RGB) Gloss (A)", Cube) = "skybox" { TexGen CubeReflect }    }    SubShader {        Tags { "Queue" = "Transparent" }        Pass {            Blend SrcAlpha OneMinusSrcAlpha            Material {                Diffuse [_Color]            }            Lighting On            SetTexture [_MainTex] {                combine texture * primary double, texture * primary            }        }        Pass {            Blend One One            Material {                Diffuse [_Color]            }            Lighting On            SetTexture [_Reflections] {                combine texture                Matrix [_Reflection]            }        }    }} 
Original at www.j2megame.com. For more information, see.

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.