Unity3d Shader Official Tutorials Translation (11)----shader syntax: Pass's blending (mixed)

Source: Internet
Author: User
Tags reflection

Shaderlab syntax:blending Mix


Blending is used to make transparent objects.

Mixing is used to make transparent objects.


When graphics is rendered, after all shaders has executed and all textures has been applied, the pixels is written to The screen. How they was combined with the already there was controlled by the Blend command.

After all the shaders have been executed, all the textures are applied and all the pixels are ready to be rendered to the screen, using the blend command to manipulate the pixels for blending.

Guidance:

Blend blending is the technique of mixing source and target colors to create effects in some way. Mixing is commonly used to draw transparent or translucent objects. The alpha value that plays a key role in blending is actually mixing the source and target colors at a given rate to achieve varying degrees of transparency. An alpha value of 0 is completely transparent, and an alpha value of 1 is completely opaque. The blending operation can only be performed in RGBA mode, and the alpha value cannot be specified in the color index mode. The order in which objects are drawn affects the blending of OpenGL.

Reference article: http://hi.baidu.com/öùáááá/blog/item/5fc565445e19714a500ffebb.html
Syntax syntax
Blend OFF
Turn off blending
Turn off blending

Blend srcfactor Dstfactor Blend starting factor
Configure & Enable blending. The generated color is multiplied by the srcfactor. The color already on screen was multiplied by dstfactor and the both are added together.
Configure and turn on blending. Calculates the resulting color and srcfactore multiplication. The color on the screen is multiplied by the dstfactor, and then 2 colors are added.

Blend srcfactor Dstfactor, Srcfactora Dstfactora
Same as above, but use different factors for blending the alpha channel.
Same as above, but some factors are different. Srcfactora Dstfactora These factors are mixed using the alpha channel.

Blendop Min | Max | Sub | Revsub
Instead of adding blended colors together, do a different operation on them.
Instead of blending the added colors together, they do different things to them.

Properties Property

All following properties is valid for both Srcfactor & Dstfactor. Source refers to the calculated color, Destination are the color already on the screen.

All of the properties listed below are valid for Srcfactor & Dstfactor. Source refers to the calculated color, Destination refers to the color on the screen already. One
The value of One-use this to let either the source or the destination color come through fully.
A value of 1 uses this setting to allow the source or target color to pass completely.


Zero
The value zero-use this to remove either the source or the destination values.
A value of 0 uses this setting to delete the source or target value.


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


Srcalpha
The value of this stage was multiplied by the source alpha value.
The value of this stage is multiplied by the source alpha value.


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


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


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


Oneminussrcalpha
The value of this stage was multiplied by (1-source Alpha).
The value of this stage is multiplied by the value of (n-source Alpha).


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


Oneminusdstalpha
The value of this stage was multiplied by (1-destination Alpha).
The value of this stage is multiplied by the value (1-target alpha).



Details

Below is the most common blend types:

The following are the most commonly used blending types
Blend Srcalpha Oneminussrcalpha//alpha blending alpha blend
Blend one One//Additive add blend
Blend one Oneminusdstcolor//Soft Additive soft Add blend
Blend Dstcolor Zero//multiplicative multiply blend
Blend Dstcolor Srccolor//2x multiplicative twice times multiply blend
Example Example

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

Here's a small example of 1 shaders: Add a texture to the screen, whether it's already on the screen or not.
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 shaders: glass. It contains 2 pass
The first pass renders a lit, alpha-blended texture on to the screen. The alpha channel decides the transparency.
The first pass renders the light and renders the texture to the screen in alpha-blended form. 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 map at the top of the Alpha Blend window, using 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]
}
}
}
}

by www.J2meGame.com Original, reprint please explain

Unity3d Shader Official Tutorials Translation (11)----shader Syntax: Pass blending (mixed)

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.