In shader, we can also add texture maps in addition to the various light treatments we can set.
Use the settexture command to assign a texture to a shader.
Example code:
Shader"sbin/ff2" { //Map SamplingProperties {//variable Name ("description name", type) = value_color ("Main body", color) = (1,1,1,1) _ambient ("Ambient Light", color) = (0.3,0.3,0.3,0.3) _specular ("High-Gloss", color) = (1,1,1,1) //variable Name ("description name", Range (region minimum, region maximum) = default value_shininess ("High light intensity", Range (0,8))=4_emission ("Spontaneous Light", color) = (1,1,1,1) _constant ("Transparent channel", color) = (1,1,1,0.3) _maintex ("Textures", 2d) =""_secondtex ("Second Texture", 2d) =""} subshader {Tags {"Queue" = "Transparent"}Pass {Blend srcalpha oneminussrcalpha material {Diffuse[_color] ambien T[_ambient] specular[_specular] shininess[_shininess] emission[_emission] } Lighting on//Enable lightingSeparatespecular on//Specular Highlights//Texture PropertiesSettexture[_maintex] {//merges the current texture * All the materials and the color of care in front//primary represents the color after vertex illumination//Double Color * *//Quad ColorCombine texture * PrimaryDouble } //Second TextureSettexture[_secondtex] {//blends with the currently applied texture to all previously sampled results//Combine texture * Previous double//, the parameter after the number, it just takes the texture alpha channel, the front all the color alpha value is invalidatedconstantcolor[_constant] Combine texture* PreviousDouble, Texture *constant} } } //FallBack "Diffuse"}
:
Default Render Order Graph:
instruction Description :
settexture applying textures
Combine How to use when blending textures
Shader"examples/2 Alpha Blended Textures"{Properties {_maintex ("Base (RGB)", 2D) =" White"{} _blendtex ("Alpha Blended (RGBA)", 2D) =" White"{}} subshader {Pass {//Apply Base TextureSetTexture [_maintex] {combine texture}//Blend in the alpha texture using the LERP operatorSetTexture [_blendtex] {Combine texture lerp (texture) Previous}}} }
constantcolor Transparent Channel
Blend to make the final mix of alpha, making transparent game objects
Tags Control Rendering order
"Some notes in the official documentation"
Blend operations (mixed operation)
You can use the blending method:
|
|
Add |
ADD source and destination together. Source and Target are superimposed together |
Sub |
Subtract destination from source. Subtract from source |
Revsub |
Subtract source from destination. |
Min |
Use the smaller of source and destination. |
Max |
Use the larger of source and destination. |
Logicalclear |
Logical operation:clear (0) DX11.1only. |
Logicalset |
Logical Operation:set (1) DX11.1only. |
Logicalcopy |
Logical operation:copy (s) DX11.1only. |
logicalcopyinverted |
Logical operation:copy Inverted (!s) DX11.1only. |
Logicalnoop |
Logical Operation:noop (d) DX11.1only. |
Logicalinvert |
Logical Operation:invert (!d) DX11.1only. |
LogicalAnd |
Logical Operation:and (S & D) DX11.1only. |
Logicalnand |
Logical Operation:nand! (S & D) DX11.1only. |
Logicalor |
Logical Operation:or (S | d) DX11.1only. |
Logicalnor |
Logical Operation:nor! (S | d) DX11.1only. |
Logicalxor |
Logical Operation:xor (s ^ d) DX11.1only. |
Logicalequiv |
Logical operation:equivalence! (s ^ d) DX11.1only. |
Logicalandreverse |
Logical Operation:reverse and (S &!d) DX11.1only. |
logicalandinverted |
Logical operation:inverted and (!s & D) DX11.1only. |
Logicalorreverse |
Logical operation:reverse Or (S |!d) DX11.1only. |
logicalorinverted |
Logical operation:inverted Or (!s | d) DX11.1only. |
Blend factors (blend factor)
All following properties is valid for both Srcfactor & Dstfactor in the Blend command. Source refers to the calculated color, Destination are the color already on the screen . The blend factors is ignored if Blendop is using logical operations.
All instructions are mixed using the Srcfactor & Dstfactor method. The source refers to the color to be computed, and the destination is the color that is currently being displayed on the screen. If the logical operator is omitted, the Blendop method is used.
|
|
One |
The value of One-use this to let either the source or the destination color come through fully. |
Zero |
The value zero-use this to remove either the source or the destination values. |
Srccolor |
The value of this stage was multiplied by the source color value. |
Srcalpha |
The value of this stage was multiplied by the source alpha value. |
Dstcolor |
The value of this stage was multiplied by frame buffer source color value. |
Dstalpha |
The value of this stage was multiplied by frame buffer source alpha value. |
Oneminussrccolor |
The value of this stage was multiplied by (1-source color). |
Oneminussrcalpha |
The value of this stage was multiplied by (1-source Alpha). |
Oneminusdstcolor |
The value of this stage was multiplied by (1-destination color). |
Oneminusdstalpha |
The value of this stage was multiplied by (1-destination Alpha). |
Details (detail)
The following are the most common types of blends:
Blend SrcAlpha OneMinusSrcAlpha // 透明通道混合Blend One One // Additive 叠加Blend OneMinusDstColor One // Soft Additive 柔性叠加Blend DstColor Zero // Multiplicative 相乘Blend DstColor SrcColor // 2x Multiplicative
Twice times multiplication
Example (example)Here's a small example where you can add a textured texture to the screen:
" Simple Additive " { Properties { _maintex ("Texture to blend""black " {} } subshader { "Queue""Transparent " } Pass { Blend one one settexture [_maintex] {combine texture} } }}< /c22>
Tags syntax
Tags { "TagName1" = "Value1" "TagName2" = "Value2" }
Subshader syntax
Subshader { [Tags] [CommonState] Passdef [Passdef ...] }
[Unity] Shader (shader) texture map