当前位置:网站首页>[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
}
}
}
边栏推荐
- FPGA - clocking -02- clock wiring resources of internal structure of 7 Series FPGA
- HCM Beginner (IV) - time
- 【KV260】利用XADC生成芯片温度曲线图
- Functions of switch configuration software
- json模块
- SystemVerilog learning-10-validation quantification and coverage
- ManageEngine卓豪助您符合ISO 20000标准(四)
- 数据库产生死锁了请问一下有没有解决办法
- [automatic operation and maintenance] what is the use of the automatic operation and maintenance platform
- [summary of problem thinking] Why is the register reset performed in user mode?
猜你喜欢

DHT11 temperature and humidity sensor

High order binary search tree

FPGA - 7 Series FPGA internal structure clocking-01-clock Architecture Overview

浅谈SIEM

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

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

High order binary balanced tree

B-树系列

Picture server project test

Index method and random forest to realize the information of surface water body in wet season in Shandong Province
随机推荐
Index method and random forest to realize the information of surface water body in wet season in Shandong Province
[ManageEngine Zhuohao] helps Julia college, the world's top Conservatory of music, improve terminal security
[postgraduate entrance examination advanced mathematics Wu Zhongxiang +880 version for personal use] advanced mathematics Chapter II Basic Stage mind map
XAF Bo of dev XPO comparison
What are the functions of LAN monitoring software
地宫取宝(记忆化深搜)
ManageEngine卓豪助您符合ISO 20000标准(四)
【ManageEngine卓豪】用统一终端管理助“欧力士集团”数字化转型
Solve the problem of garbled files uploaded by Kirin v10
kubeadm搭建kubenetes 集群(个人学习版)
【ManageEngine】终端管理系统,助力华盛证券数字化转型
扩散(多源广搜)
Using Baidu map to query national subway lines
webapck打包原理--启动过程分析
High order binary balanced tree
【#Unity Shader#自定义材质面板_第一篇】
Movable mechanical wall clock
Although pycharm is marked with red in the run-time search path, it does not affect the execution of the program
Functions of switch configuration software
HCM Beginner (III) - quickly enter pa70 and pa71 to browse employee information PA10