当前位置:网站首页>[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
}
}
}
边栏推荐
- 【#Unity Shader#自定义材质面板_第二篇】
- 1034 Head of a Gang
- Diffusion (multi-source search)
- Application of IT service management (ITSM) in Higher Education
- lxml模块(数据提取)
- One of the characteristic agricultural products that make Tiantou village, Guankou Town, Xiamen into a "sweet" village is
- SystemVerilog learning-10-validation quantification and coverage
- Make: g++: command not found
- Picture server project test
- 【LeetCode】Day91-存在重复元素
猜你喜欢

HCM Beginner (IV) - time

Movable mechanical wall clock

【企业数据安全】升级备份策略 保障企业数据安全

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

IT服务管理(ITSM)在高等教育领域的应用

Make Tiantou village sweet. Is Xianjing taro or cabbage the characteristic agricultural product of Tiantou Village

C语言课设物业费管理系统(大作业)

自开发软件NoiseCreater1.1版本免费试用

Index method and random forest to realize the information of surface water body in wet season in Shandong Province

蚂蚁新村田头村变甜头村 让厦门灌口镇田头村变甜头村的特色农产品之一是
随机推荐
pycharm 配置jupyter
交换机配置软件具有的作用
C语言课设图书信息管理系统(大作业)
Make Tiantou village sweet. Is Xianjing taro or cabbage the characteristic agricultural product of Tiantou Village
Distributed lock implementation
FPGA - clocking -02- clock wiring resources of internal structure of 7 Series FPGA
SystemVerilog learning-09-interprocess synchronization, communication and virtual methods
Promise
Uniapp tree level selector
【ManageEngine】如何实现网络自动化运维
How does the port scanning tool help enterprises?
Tidb database characteristics summary
Diffusion (multi-source search)
C XML help class
Mysql 表分区创建方法
三分钟带你快速了解网站开发的整个流程
Make: g++: command not found
端口扫描工具对企业有什么帮助?
Flink practice -- multi stream merge
虚幻 简单的屏幕雨滴后处理效果