当前位置:网站首页>[unity shader amplify shader editor (ASE) Chapter 9]
[unity shader amplify shader editor (ASE) Chapter 9]
2022-07-01 06:25:00 【The king of scrolls is coming】
1. To continue Chapter eight ASE effect
Streamer Shader Complete code blocks and node connections are at the top !
To facilitate observation , Here you are Chapter eight ASE Full node connection of the effect .
What is shown below is ASE The effect of the eighth part is a complete code block .
Shader "Samples/Light Flow"
{
Properties
{
// Keyword enumeration ,0 position X Direction ,1 by Y Direction .
[KeywordEnum(x,y)] _Flow_Diretion("Flow_Diretion", Float) = 0
_FlowSpeed("Flow Speed", Float) = 1
_Tex("Tex", 2D) = "white" {
}
_Color("Color", Color) = (0,1,1,1)
}
SubShader
{
Tags {
"RenderType"="Transparent" "Queue"="Transparent" }
Blend One One
Cull Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
//————————————————————————————————————————————————————————————————————
// Define enumeration keywords
#pragma shader_feature_local _FLOW_DIRETION_X _FLOW_DIRETION_Y
//————————————————————————————————————————————————————————————————————
struct v2f
{
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
sampler2D _Tex;
float _FlowSpeed;
float4 _Color;
float4 _Tex_ST;
v2f vert (appdata_base v)
{
v2f o;
o.texcoord = TRANSFORM_TEX(v.texcoord,_Tex);
o.vertex = UnityObjectToClipPos(v.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float2 texcoord;
//————————————————————————————————————————————————————————————————————
// Judge the flow direction
#if _DIRECTION_X
texcoord = float2(i.texcoord.x + _Time.x * _Speed,
i.texcoord.y);
#elif _DIRECTION_Y
texcoord = float2(i.texcoord.x,
i.texcoord.y + _Time.x * _Speed,);
#endif
//————————————————————————————————————————————————————————————————————
return tex2D(_Tex,texcoord) * _Color;
}
ENDCG
}
}
}
2.Shader Code block explanation
2.1.Properties Code block
- About Properties The code rules can be seen in the previous Properties Introduce , What I don't understand Leave a comment .
Shader "Samples/Light Flow"
{
Properties
{
// Keyword enumeration ,0 position X Direction ,1 by Y Direction .
[KeywordEnum(x,y)] _Flow_Diretion("Flow_Diretion", Float) = 0
_FlowSpeed("Flow Speed", Float) = 1
_Tex("Tex", 2D) = "white" {
}
_Color("Color", Color) = (0,1,1,1)
}
- Open the mapping attribute of streamer effect _Tex And color attributes _Color
- For the convenience of selecting the flow direction of the beam , Attribute is required _DIRECTION Before adding [KeywordEnum(x,y)] Keyword enumeration instruction , In this way, you can select from the material panel through the following options .
That is to say :[KeywordEnum(x,y)] _Flow_Diretion("Flow_Diretion", Float) = 0 - add to _Speed It is used to adjust the flow speed of the light beam .
2.2.SubShader Code block
- because Shader Effect needs to be used Blending function , So you need to SubShader Set both the render type and the render queue to “Transparent”. Then set the blending mode to “Blend one one”, And turn off geometry culling . The code block is as follows :
SubShader
{
Tags {
"RenderType"="Transparent" "Queue"="Transparent" }
Blend One One
Cull Off
2.3.Pass Compile instruction code block
- In the compile instruction , add to shader_feature The instruction defines the direction of flow X and Y The enumeration keywords of are
_FLOW_DIRETION_Xand_FLOW_DIRETION_Y. as follows :
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
//————————————————————————————————————————————————————————————————————
// Define enumeration keywords
#pragma shader_feature_local _FLOW_DIRETION_X _FLOW_DIRETION_Y
//————————————————————————————————————————————————————————————————————
besides , You can also use “multi_compile” Instructions . About customizing material panel content , You need to make a separate article . Portal ------------------------------------------------
2.4. Declare attribute variables 、 Get data code block
- Relatively easy , The previous chapter has a detailed introduction , for example Pass Third articles .
struct v2f
{
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
sampler2D _Tex;
float _FlowSpeed;
float4 _Color;
float4 _Tex_ST;
2.5. Vertex shader code block
- It is introduced in the comments of the code block .
v2f vert (appdata_base v)
{
v2f o;
// use TRANSFORM_TEX() The macro calculates the texture coordinates of the beam .
o.texcoord = TRANSFORM_TEX(v.texcoord,_Tex);
// Use UnityObjectToClipPos() Function to get the coordinates of cutting space vertices , Then pass it to the clip shader .
o.vertex = UnityObjectToClipPos(v.vertex);
return o;
}
2.6. Fragment shader code block
- In the fragment shader , Judge by enumerating keywords :
- When the flow direction is X when , The time variable is added to the texture coordinates X On weight ;
- When the flow direction is Y when , The time variable is added to the texture coordinates Y On weight .
- Then the beam texture is sampled using the calculated texture coordinates ,
- Finally multiply by the color attribute , Return to the clip shader .
fixed4 frag (v2f i) : SV_Target
{
float2 texcoord;
//————————————————————————————————————————————————————————————————————
// Judge the flow direction
#if _DIRECTION_X
texcoord = float2(i.texcoord.x + _Time.x * _Speed,
i.texcoord.y);
#elif _DIRECTION_Y
texcoord = float2(i.texcoord.x,
i.texcoord.y + _Time.x * _Speed,);
#endif
//————————————————————————————————————————————————————————————————————
return tex2D(_Tex,texcoord) * _Color;
}
ENDCG
}
}
}
边栏推荐
- [ManageEngine Zhuohao] mobile terminal management solution, helping the digital transformation of Zhongzhou aviation industry
- 记磁盘扇区损坏导致的Mysql故障排查
- [enterprise data security] upgrade backup strategy to ensure enterprise data security
- Solve the problem of garbled files uploaded by Kirin v10
- C语言课设学生信息管理系统(大作业)
- What are the functions of LAN monitoring software
- High order binary balanced tree
- Top 10 Free 3D modeling software for beginners in 2022
- SystemVerilog learning-07-class inheritance and package use
- Transformer le village de tiantou en un village de betteraves sucrières
猜你喜欢
![[postgraduate entrance examination advanced mathematics Wu Zhongxiang +880 version for personal use] advanced mathematics Chapter II Basic Stage mind map](/img/c0/299a406efea51f24b1701b66adc1e3.png)
[postgraduate entrance examination advanced mathematics Wu Zhongxiang +880 version for personal use] advanced mathematics Chapter II Basic Stage mind map

Freeswitch dial the extension number

Understanding of C manualresetevent class

SQL语句

B-树系列

Promise
![[self use of advanced mathematics in postgraduate entrance examination] advanced mathematics Chapter 1 thinking map in basic stage](/img/54/f187e22ad69f3985d30376bad1fa03.png)
[self use of advanced mathematics in postgraduate entrance examination] advanced mathematics Chapter 1 thinking map in basic stage

C语言课设学生信息管理系统(大作业)

68 cesium code datasource loading czml

SystemVerilog learning-10-validation quantification and coverage
随机推荐
json模块
【#Unity Shader#自定义材质面板_第二篇】
HCM Beginner (II) - information type
【Unity Shader 消融效果_案例分享】
交换机配置软件具有的作用
SQL语句
【Unity Shader 描边效果_案例分享第一篇】
三分钟带你快速了解网站开发的整个流程
Promise
【#Unity Shader#Amplify Shader Editor(ASE)_第九篇】
Projects and dependencies in ABP learning solutions
手把手教你实现一个深度学习框架...
three. JS summary
端口扫描工具对企业有什么帮助?
HDU - 1501 Zipper(记忆化深搜)
HCM Beginner (III) - quickly enter pa70 and pa71 to browse employee information PA10
C语言课设销售管理系统设计(大作业)
让田头村变甜头村的特色农产品是仙景芋还是白菜
讓田頭村變甜頭村的特色農產品是仙景芋還是白菜
Mysql 表分区创建方法