Zhuang Dong's TA Notes (13) <Special Effects-Blending Mode: Four Main Transparent Channel Usages AC , AB , AD , Custom Blending >
Show results:
text:
1. Outline of Special Effects:
1. Special effects and transparency
2. Special effects and motion
3. Special effects and reflections
2. Special effects: AC: alpha cut.
1. AlphaCutout AC
2. Code · AC:
1. About the use of AC in shader: key code >> Clip(alpha - _Cutoff)
_MainTex ("RGBA: RGB: color map, A: transparent paste", 2d)="gray"{}
_Cutoff("Cutoff", range(0,1))=0.5
clip(var_mainTex.a - _Cutoff);
Then, the transparent paste is completed. This knowledge is used in the practice of the dota2 shader in lesson 12.
2. Regarding the meaning of modifying SubshaderTags :
There will be 2 Tags under the subshader , one is called Subshader Tags and the other is called Pass Tags.
Under these two Tags , different declaration contents will be compatible.
Multiple Subshaders can appear in the script, anddifferent RenderTypes (rendering types) can be modified for different Subshader Tags .
This section only introduces the content under Subshader Tags :
1. RenderType: Remember the corresponding default TransparentCutout.
Transparent, or opaque, here it is set to transparent, because special effects films are mostly transparent.
2. ForceNoShadowCasting : Turn off the projection True.
Because in special effects, shadows are generally not used or rarely used, and it will increase consumption.
3. ignoreProjectoro: Do not respond to the projector, close as True.
Close the response of the project, (There is not much explanation here, let me understand it first, and I will have a perceptual understanding when I get in touch with it later)
3. Special effects need to enable Tilng offset
uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
code snippet:
Shader "Unlit/Sc013_AC02"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Cutout("透贴",Range(0,1))=0.5
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass {
Name "FORWARD"
Tags {
"LightMode"="ForwardBase"
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_instancing
#include "UnityCG.cginc"
#pragma multi_compile_fwdbase_fullshadows
#pragma target 3.0
UNITY_INSTANCING_BUFFER_START( Props )
// UNITY_DEFINE_INSTANCED_PROP( float4, _Color)
UNITY_INSTANCING_BUFFER_END( Props )
uniform sampler2D _MainTex;uniform float4 _MainTex_ST;
uniform float _Cutout;
//输入结构
struct VertexInput
{
float4 vertex : POSITION;
float2 uv0 : TEXCOORD0;
};
//顶点输出结构
struct VertexOutput
{
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
};
//输出结构>>>顶点shader>>>输出结构
VertexOutput vert (VertexInput v)
{
VertexOutput o = (VertexOutput)0;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv0 = TRANSFORM_TEX (v.uv0,_MainTex);
return o ;
}
//色彩输出结构
float4 frag(VertexOutput i) : COLOR
{
float4 var_mainTex = tex2D(_MainTex,i.uv0);
clip(var_mainTex.a - _Cutout);
return float4(var_mainTex);//输出最终颜色
}
ENDCG
}
}
}
3. Special effects: AB: alpha blend:
1. AlphaBlend AB:
2. Code · AB:
Subshader Tags 下 :
1. RenderType: Remember the corresponding default TransparentCutout.
2. ForceNoShadowCasting : Turn off the projection True.
3. ignoreProjectoro: Do not respond to the projector, close as True.
4. Newly added Queue: rendering queue modified to the corresponding TransparentCutout
1. Control the rendering order and when it is rendered.
2. When rendering opaque objects , do a rendering from front to back ; when rendering transparent objects , render from back to front .
3. Because , before rendering a transparent object , you need to know what is behindthe transparent object before rendering to an opaque object.
How to control the front and back sequence ? Youneed to usethe rendering queue.
4、Queue: = "Transparent"
Mixing of Pass Tags :
1、Blend One / srcAlpha OneMinusSrcAlpha;
src represents the source Alpha transparency channel , oneMinus 1- , srcAlpha the source transparency channel .
The translation is: 1 - source transparent paste .
(There is not much explanation here, let Zhuang understand it first, and you will have a perceptual understanding when you come into contact with it later).
混合方法1:Blend One OneMinusSrcAlpha // 修改混合方式One/SrcAlpha OneMinusSrcAlpha
混合方法2:Blend SrcAlpha OneMinusSrcAlpha // 修改混合方式One/SrcAlpha OneMinusSrcAlpha
Blend One OneMinusScrAlpha == traditional writing.
Blend SrcAlpha OneMinusSrcAlpha == premultiplied writing.
code snippet:
Shader "Unlit/Sc013_AB02"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Cutout("透贴",Range(0,1))=0.5
}
SubShader
{
Tags {
"Queue"="Transparent"
"RenderType"="Transparent"
}
LOD 100
Pass {
Name "FORWARD"
Tags {
"LightMode"="ForwardBase"
}
Blend One OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_instancing
#include "UnityCG.cginc"
#pragma multi_compile_fwdbase_fullshadows
#pragma target 3.0
UNITY_INSTANCING_BUFFER_START( Props )
// UNITY_DEFINE_INSTANCED_PROP( float4, _Color)
UNITY_INSTANCING_BUFFER_END( Props )
uniform sampler2D _MainTex;uniform float4 _MainTex_ST;
uniform float _Cutout;
//输入结构
struct VertexInput
{
float4 vertex : POSITION;
float2 uv0 : TEXCOORD0;
};
//顶点输出结构
struct VertexOutput
{
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
};
//输出结构>>>顶点shader>>>输出结构
VertexOutput vert (VertexInput v)
{
VertexOutput o = (VertexOutput)0;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv0 = TRANSFORM_TEX (v.uv0,_MainTex);
return o ;
}
//色彩输出结构
float4 frag(VertexOutput i) : COLOR
{
float4 var_mainTex = tex2D(_MainTex,i.uv0);
float opacity = var_mainTex.a * _Cutout;
float3 finalRGB = var_mainTex * opacity;
return float4(finalRGB,opacity);//输出最终颜色
}
ENDCG
}
}
}
4. Special effects: AD: alpha add
1. Additive AD:
2. Code · AD:
There is not much difference between AB and AD, the only difference is under Pass Tags, Blend One One.
code snippet:
Shader "Unlit/Sc013_AD02"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Cutout("透贴",Range(0,1))=0.5
}
SubShader
{
Tags {
"Queue"="Transparent"
"RenderType"="Transparent"
}
LOD 100
Pass {
Name "FORWARD"
Tags {
"LightMode"="ForwardBase"
}
Blend One One
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_instancing
#include "UnityCG.cginc"
#pragma multi_compile_fwdbase_fullshadows
#pragma target 3.0
UNITY_INSTANCING_BUFFER_START( Props )
// UNITY_DEFINE_INSTANCED_PROP( float4, _Color)
UNITY_INSTANCING_BUFFER_END( Props )
uniform sampler2D _MainTex;uniform float4 _MainTex_ST;
uniform float _Cutout;
//输入结构
struct VertexInput
{
float4 vertex : POSITION;
float2 uv0 : TEXCOORD0;
};
//顶点输出结构
struct VertexOutput
{
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
};
//输出结构>>>顶点shader>>>输出结构
VertexOutput vert (VertexInput v)
{
VertexOutput o = (VertexOutput)0;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv0 = TRANSFORM_TEX (v.uv0,_MainTex);
return o ;
}
//色彩输出结构
float4 frag(VertexOutput i) : COLOR
{
float4 var_mainTex = tex2D(_MainTex,i.uv0);
float opacity = var_mainTex.a * _Cutout;
float3 finalRGB = var_mainTex * opacity;
return float4(finalRGB,opacity);//输出最终颜色
}
ENDCG
}
}
}
5. Effects: Tools · Blend Mode:
1. More mixed modes:
2. Mixing principle:
The relationship between Src and Dst is explained here , taking the PS layer as an example.
Src : The code name of the layer on the source is Src. or the main body of the object is the source.
Dst : The layer under the target , to be stacked, code-named Dst. Or the background behind it is the target.
SrcFactor :source multiplier, various forms are listed in the above figure.
DstFactor :Target multiplier, various forms are listed in the above figure.
Op : Mixed operator, addition,subtraction, multiplication and division.Various forms are listed in the above figure.
Example: Src * SrcFactor op Dst * DstFactor.
Source * Source Multiplier Addition, Subtraction, Multiplication and Division Destination * Destination Multiplier.
3. Art custom mixing panel:
1. Two operation panels:
No packaging, full exposure. Pre-packages are optional.
package, limited selection. A fixed selection will be determined later.
4. No encapsulation, fully exposed code implementation: (This lesson only introduces this, encapsulation will be introduced later)
5. Commonly used modes:
code snippet:
Shader "Unlit/Sc013_Blend02"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Cutout("透贴",Range(0,1))=0.5
[Enum(UnityEngine.Rendering.BlendMode)]
_BlendSrc("混合源乘子",int)=0
[Enum(UnityEngine.Rendering.BlendMode)]
_BlendDst("混合目标乘子",int)=0
[Enum(UnityEngine.Rendering.BlendOp)]
_BlendOp("混合运算符",int)=0
}
SubShader
{
Tags {
"Queue"="Transparent"
"RenderType"="Transparent"
}
LOD 100
Pass {
Name "FORWARD"
Tags {
"LightMode"="ForwardBase"
}
BlendOp [_BlendOp]
Blend [_BlendSrc] [_BlendDst]
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_instancing
#include "UnityCG.cginc"
#pragma multi_compile_fwdbase_fullshadows
#pragma target 3.0
UNITY_INSTANCING_BUFFER_START( Props )
// UNITY_DEFINE_INSTANCED_PROP( float4, _Color)
UNITY_INSTANCING_BUFFER_END( Props )
uniform sampler2D _MainTex;uniform float4 _MainTex_ST;
uniform float _Cutout;
//输入结构
struct VertexInput
{
float4 vertex : POSITION;
float2 uv0 : TEXCOORD0;
};
//顶点输出结构
struct VertexOutput
{
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
};
//输出结构>>>顶点shader>>>输出结构
VertexOutput vert (VertexInput v)
{
VertexOutput o = (VertexOutput)0;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv0 = TRANSFORM_TEX (v.uv0,_MainTex);
return o ;
}
//色彩输出结构
float4 frag(VertexOutput i) : COLOR
{
float4 var_mainTex = tex2D(_MainTex,i.uv0);
float opacity = var_mainTex.a * _Cutout;
float3 finalRGB = var_mainTex * opacity;
return float4(finalRGB,opacity);//输出最终颜色
//return opacity;
}
ENDCG
}
}
}