当前位置:网站首页>[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
}
}
}
边栏推荐
- B-树系列
- SystemVerilog learning-10-validation quantification and coverage
- 阶乘约数(唯一分解定理)
- JDBC connection pool
- Factorial divisor (unique decomposition theorem)
- Flink practice -- multi stream merge
- FPGA - 7 Series FPGA internal structure clocking-01-clock Architecture Overview
- [ManageEngine Zhuohao] use unified terminal management to help "Eurex group" digital transformation
- 高阶-二叉平衡树
- To sort out the anomaly detection methods, just read this article!
猜你喜欢
随机推荐
【ManageEngine卓豪】移动终端管理解决方案,助力中州航空产业数字化转型
Using Baidu map to query national subway lines
码力十足学量化|如何在财务报告寻找合适的财务公告
浅谈SIEM
[leetcode] day91- duplicate elements exist
Although pycharm is marked with red in the run-time search path, it does not affect the execution of the program
【Unity Shader 描边效果_案例分享第一篇】
记磁盘扇区损坏导致的Mysql故障排查
XAF Bo of dev XPO comparison
idea 好用插件汇总!!!
连续四年入选Gartner魔力象限,ManageEngine卓豪是如何做到的?
SQL语句
Make: g++: command not found
SQL中DML语句(数据操作语言)
【企业数据安全】升级备份策略 保障企业数据安全
Functions of switch configuration software
Transformer le village de tiantou en un village de betteraves sucrières
[ManageEngine Zhuohao] the role of LAN monitoring
Projects and dependencies in ABP learning solutions
C语言课设学生考勤系统(大作业)









