当前位置:网站首页>[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
}
}
}
边栏推荐
- 连续四年入选Gartner魔力象限,ManageEngine卓豪是如何做到的?
- Recueillir des trésors dans le palais souterrain (recherche de mémoire profonde)
- golang panic recover自定义异常处理
- 让厦门灌口镇田头村变“甜头”村的特色农产品之一是
- SystemVerilog learning-09-interprocess synchronization, communication and virtual methods
- C语言课设职工信息管理系统(大作业)
- 数据库产生死锁了请问一下有没有解决办法
- Mysql 表分区创建方法
- Although pycharm is marked with red in the run-time search path, it does not affect the execution of the program
- 【ManageEngine卓豪 】助力世界顶尖音乐学院--茱莉亚学院,提升终端安全
猜你喜欢

C语言课设学生选修课程系统(大作业)

DHT11 temperature and humidity sensor

【KV260】利用XADC生成芯片温度曲线图

SQL语句

Discrimination between left and right limits of derivatives and left and right derivatives

Transformer le village de tiantou en un village de betteraves sucrières

连续四年入选Gartner魔力象限,ManageEngine卓豪是如何做到的?

HCM Beginner (I) - Introduction
![[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
![[automatic operation and maintenance] what is the use of the automatic operation and maintenance platform](/img/14/756d566744d6e4a988a284c5b30130.png)
[automatic operation and maintenance] what is the use of the automatic operation and maintenance platform
随机推荐
Diffusion (multi-source search)
three. JS summary
webapck打包原理--启动过程分析
【Unity Shader 消融效果_案例分享】
69 cesium code datasource loading geojson
ManageEngine卓豪助您符合ISO 20000标准(四)
[ManageEngine] how to realize network automatic operation and maintenance
地宮取寶(記憶化深搜)
讓田頭村變甜頭村的特色農產品是仙景芋還是白菜
[automatic operation and maintenance] what is the use of the automatic operation and maintenance platform
FPGA - clocking -02- clock wiring resources of internal structure of 7 Series FPGA
10-golang运算符
Index method and random forest to realize the information of surface water body in wet season in Shandong Province
请求模块(requests)
Promise
伪装请求头库: anti-useragent
【#Unity Shader#自定义材质面板_第一篇】
Mysql 表分区创建方法
[summary of knowledge points] chi square distribution, t distribution, F distribution
Functions of switch configuration software