Unity-Shader-Library

  1. 1. 前言
  2. 2. 内容
    1. 2.1. 1. 模拟音频
    2. 2.2. 2. 故障效果(红蓝通道偏移+UV扰动)
    3. 2.3. 3. Hue(色相、明度、饱和度)
    4. 2.4. 4. UV流动
    5. 2.5. 5. 序列帧图片播放
    6. 2.6. 6. 扫描光效果
    7. 2.7. 7. 过场黑幕
    8. 2.8. 8. 梦境效果
    9. 2.9. 9. 按轴向显示效果
    10. 2.10. 10. 屏幕特效
    11. 2.11. 11. 两种贴图切换
    12. 2.12. 12. 两个正多边形进行布尔运算或混合

前言

  • 记录一下日常或工作中用到的Unity Shader,以便需要时检索
  • 本篇Shader记录,格式为:序号-标题-效果-贴图资源-参数-代码-拓展内容,代码部分需要手动展开

内容

1. 模拟音频

  • 效果:

  • 贴图资源:

  • 参数:

  • 代码:
点此展开
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
Shader "Shiki/Yinpin"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Scale ("Scale", Range(1, 100)) = 30
_Pow ("Power", Range(0.1, 2)) = 1
_Reduce ("Reduce", Range(0, 100)) = 1
_BaseHeight ("BaseHeight", Range(0, 10)) = 0.1
[Toggle] _Toggle("Toggle", Float) = 1
_Lerp("Lerp", Range(0, 1)) = 1
_Sin ("Sin", Float) = 1
_Cos ("Cos", Float) = 0
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent"}
Blend SrcAlpha OneMinusSrcAlpha

Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag

#include "UnityCG.cginc"

struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float4 color :COLOR;
};

struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 color :COLOR;
};

sampler2D _MainTex;
float4 _MainTex_ST;
float _Scale;
float _Pow;
float _Reduce;
float _Toggle;
float _BaseHeight;
float _Lerp;
float _Sin;
float _Cos;

v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.color = v.color;
return o;
}

fixed4 frag (v2f i) : SV_Target
{
_Scale = floor(_Scale);
int halfScale = floor(_Scale * 0.5);
i.uv.xy *= _Scale;

fixed4 col = tex2D(_MainTex, i.uv);
fixed cola = col.a;
for(int j = 0; j < _Scale; j++)
{
if (floor(i.uv.x) == j)
{
float hmax = halfScale-1 - abs(ceil(i.uv.x) - halfScale) + 2 * frac(sin(dot(ceil(i.uv.x), float2(12.98, 78.233)))*43758.05453 + _Time.z) + frac(sign(sin(dot(ceil(i.uv.x)+ _Time.z/6, float2(12.98, 78.233))) )*43758.05453 );
hmax =pow(hmax, 1.05) - 2;
hmax =pow(hmax, 1.02);
hmax =pow(hmax, _Pow) - _Reduce;
hmax -= sin(dot(ceil(i.uv.x)+ _Time.z/20, float2(12.98, 78.233)))*_Sin;
hmax -= sin(dot(ceil(i.uv.x)+ _Time.z/200, float2(132.982, 738.2533)));
hmax -= cos(dot(ceil(i.uv.x)+ _Time.z/20, float2(12.298, 78.2233)))*_Cos;
hmax = clamp(hmax, _BaseHeight, halfScale);
hmax = lerp(hmax, _BaseHeight, _Lerp);
hmax = _Toggle == 1 ? hmax : _BaseHeight;
if (i.uv.y > halfScale + hmax || i.uv.y < halfScale - hmax || i.uv.x > _Scale-1.1)
{
col.a = 0;
}
else
{
col.a = 1;
}

}
}
col.a *= cola < 0.1 ? 0 : 1;
return col * i.color;
}
ENDCG
}
}
}

  • 拓展:
    • 在用于Timeline里K动画时,可以用顶点颜色的一个通道作为_Lerp参数

2. 故障效果(红蓝通道偏移+UV扰动)

  • 效果:

  • 参数:

  • 代码:
点此展开

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// Made with Amplify Shader Editor v1.9.3.2
// Available at the Unity Asset Store - http://u3d.as/y3X
Shader "Shiki/GuZhang"
{
Properties
{
_NoiseTex("NoiseTex", 2D) = "white" {}
_NoiseScale("NoiseScale", Range( 0 , 0.1)) = 0.1
_MainTex("_MainTex", 2D) = "white" {}
_NoiseXSpeed("_NoiseXSpeed", Float) = 1
_NoiseYSpeed("_NoiseYSpeed", Float) = 0
_RB_Offset("RB_Offset", Vector) = (0.03,0,-0.05,0)

}

SubShader
{


Tags { "RenderType"="Transparent" "Queue"="Transparent" }
LOD 100

CGINCLUDE
#pragma target 3.0
ENDCG
Blend SrcAlpha OneMinusSrcAlpha
AlphaToMask Off
Cull Back
ColorMask RGBA
ZWrite On
ZTest LEqual
Offset 0 , 0



Pass
{
Name "Unlit"

CGPROGRAM



#ifndef UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX
//only defining to not throw compilation error over Unity 5.5
#define UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input)
#endif
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_instancing
#include "UnityCG.cginc"
#include "UnityShaderVariables.cginc"


struct appdata
{
float4 vertex : POSITION;
float4 color : COLOR;
float4 ase_texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};

struct v2f
{
float4 vertex : SV_POSITION;
#ifdef ASE_NEEDS_FRAG_WORLD_POSITION
float3 worldPos : TEXCOORD0;
#endif
float4 ase_texcoord1 : TEXCOORD1;
float4 ase_color : COLOR;
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};

uniform sampler2D _MainTex;
uniform sampler2D _NoiseTex;
uniform float _NoiseXSpeed;
uniform float _NoiseYSpeed;
uniform float4 _NoiseTex_ST;
uniform float _NoiseScale;
uniform float4 _RB_Offset;


v2f vert ( appdata v )
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
UNITY_TRANSFER_INSTANCE_ID(v, o);

o.ase_texcoord1.xy = v.ase_texcoord.xy;
o.ase_color = v.color;

//setting value to unused interpolator channels and avoid initialization warnings
o.ase_texcoord1.zw = 0;
float3 vertexValue = float3(0, 0, 0);
#if ASE_ABSOLUTE_VERTEX_POS
vertexValue = v.vertex.xyz;
#endif
vertexValue = vertexValue;
#if ASE_ABSOLUTE_VERTEX_POS
v.vertex.xyz = vertexValue;
#else
v.vertex.xyz += vertexValue;
#endif
o.vertex = UnityObjectToClipPos(v.vertex);

#ifdef ASE_NEEDS_FRAG_WORLD_POSITION
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
#endif
return o;
}

fixed4 frag (v2f i ) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(i);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
fixed4 finalColor;
#ifdef ASE_NEEDS_FRAG_WORLD_POSITION
float3 WorldPosition = i.worldPos;
#endif
float2 texCoord15 = i.ase_texcoord1.xy * float2( 1,1 ) + float2( 0,0 );
float2 appendResult14 = (float2(_NoiseXSpeed , _NoiseYSpeed));
float2 uv_NoiseTex = i.ase_texcoord1.xy * _NoiseTex_ST.xy + _NoiseTex_ST.zw;
float2 panner10 = ( 1.0 * _Time.y * appendResult14 + uv_NoiseTex);
float2 appendResult18 = (float2(( texCoord15.x + ( (-0.5 + (tex2D( _NoiseTex, panner10 ).r - 0.0) * (0.5 - -0.5) / (1.0 - 0.0)) * _NoiseScale ) ) , texCoord15.y));
float4 break24 = ( (0.0 + (_NoiseScale - 0.0) * (1.0 - 0.0) / (0.1 - 0.0)) * _RB_Offset );
float2 appendResult26 = (float2(break24.x , break24.y));
float4 tex2DNode3 = tex2D( _MainTex, appendResult18 );
float2 appendResult27 = (float2(break24.z , break24.w));
float4 appendResult29 = (float4(tex2D( _MainTex, ( appendResult18 + appendResult26 ) ).r , tex2DNode3.g , tex2D( _MainTex, ( appendResult18 + appendResult27 ) ).b , tex2DNode3.a));


finalColor = ( appendResult29 * i.ase_color );
return finalColor;
}
ENDCG
}
}
CustomEditor "ASEMaterialInspector"

Fallback Off
}
/*ASEBEGIN
Version=19302
Node;AmplifyShaderEditor.RangedFloatNode;11;-1830.574,67.72733;Inherit;False;Property;_NoiseXSpeed;_NoiseXSpeed;3;0;Create;True;0;0;0;False;0;False;1;1;0;0;0;1;FLOAT;0
Node;AmplifyShaderEditor.RangedFloatNode;12;-1829.274,160.0273;Inherit;False;Property;_NoiseYSpeed;_NoiseYSpeed;4;0;Create;True;0;0;0;False;0;False;0;0;0;0;0;1;FLOAT;0
Node;AmplifyShaderEditor.TextureCoordinatesNode;9;-1675.158,-110.406;Inherit;False;0;8;2;3;2;SAMPLER2D;;False;0;FLOAT2;1,1;False;1;FLOAT2;0,0;False;5;FLOAT2;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.DynamicAppendNode;14;-1610.872,74.22719;Inherit;False;FLOAT2;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.PannerNode;10;-1384.673,-109.0727;Inherit;False;3;0;FLOAT2;0,0;False;2;FLOAT2;0,0;False;1;FLOAT;1;False;1;FLOAT2;0
Node;AmplifyShaderEditor.RangedFloatNode;19;-1135.771,125.3111;Inherit;False;Property;_NoiseScale;NoiseScale;1;0;Create;True;0;0;0;False;0;False;0.1;0.1;0;0.1;0;1;FLOAT;0
Node;AmplifyShaderEditor.SamplerNode;8;-1139.87,-148.3622;Inherit;True;Property;_NoiseTex;NoiseTex;0;0;Create;True;0;0;0;False;0;False;-1;668c5cbd895555247a9d985bc86082f7;a60345c2a57b966488b08c6c6578d094;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.TFHCRemapNode;21;-766.4503,251.023;Inherit;False;5;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0.1;False;3;FLOAT;0;False;4;FLOAT;1;False;1;FLOAT;0
Node;AmplifyShaderEditor.Vector4Node;23;-755.7201,505.0249;Inherit;False;Property;_RB_Offset;RB_Offset;5;0;Create;True;0;0;0;False;0;False;0.03,0,-0.05,0;0.03,0.15,-0.03,0.69;0;5;FLOAT4;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.TFHCRemapNode;30;-856.197,-123.453;Inherit;False;5;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;1;False;3;FLOAT;-0.5;False;4;FLOAT;0.5;False;1;FLOAT;0
Node;AmplifyShaderEditor.TextureCoordinatesNode;15;-949.364,-542.825;Inherit;False;0;-1;2;3;2;SAMPLER2D;;False;0;FLOAT2;1,1;False;1;FLOAT2;0,0;False;5;FLOAT2;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;22;-482.7201,363.0249;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT4;0,0,0,0;False;1;FLOAT4;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;20;-662.3416,-128.7689;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleAddOpNode;16;-660.3727,-492.8383;Inherit;True;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.BreakToComponentsNode;24;-313.7201,357.0249;Inherit;False;FLOAT4;1;0;FLOAT4;0,0,0,0;False;16;FLOAT;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4;FLOAT;5;FLOAT;6;FLOAT;7;FLOAT;8;FLOAT;9;FLOAT;10;FLOAT;11;FLOAT;12;FLOAT;13;FLOAT;14;FLOAT;15
Node;AmplifyShaderEditor.DynamicAppendNode;18;-374.5093,-495.9621;Inherit;False;FLOAT2;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.DynamicAppendNode;26;-95.62512,290.1249;Inherit;False;FLOAT2;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.DynamicAppendNode;27;-91.62512,480.1249;Inherit;False;FLOAT2;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.SimpleAddOpNode;25;178.6808,389.2386;Inherit;False;2;2;0;FLOAT2;0,0;False;1;FLOAT2;0,0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.SimpleAddOpNode;28;137.3749,206.1249;Inherit;False;2;2;0;FLOAT2;0,0;False;1;FLOAT2;0,0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.TexturePropertyNode;6;2.598404,-645.4363;Inherit;True;Property;_MainTex;_MainTex;2;0;Create;True;0;0;0;False;0;False;0a83f9be848c10041841b004689e02d6;b5ad082f61c500d4294842ce4f7f3f56;False;white;Auto;Texture2D;-1;0;2;SAMPLER2D;0;SAMPLERSTATE;1
Node;AmplifyShaderEditor.SamplerNode;4;373.9305,144.8178;Inherit;True;Property;_TextureSample2;Texture Sample 2;3;0;Create;True;0;0;0;False;0;False;-1;None;None;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.SamplerNode;2;374.7539,-454.3615;Inherit;True;Property;_TextureSample0;Texture Sample 0;1;0;Create;True;0;0;0;False;0;False;-1;None;None;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.SamplerNode;3;376.0417,-150.7332;Inherit;True;Property;_TextureSample1;Texture Sample 1;2;0;Create;True;0;0;0;False;0;False;-1;None;None;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.DynamicAppendNode;29;857.0964,-148.4408;Inherit;False;FLOAT4;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT4;0
Node;AmplifyShaderEditor.VertexColorNode;34;858.7769,38.08496;Inherit;False;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;32;-1260.176,541.6824;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SinTimeNode;31;-1499.841,427.8833;Inherit;False;0;5;FLOAT4;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.SaturateNode;33;-1090.832,549.2119;Inherit;False;1;0;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;35;1089.777,-31.91504;Inherit;False;2;2;0;FLOAT4;0,0,0,0;False;1;COLOR;0,0,0,0;False;1;FLOAT4;0
Node;AmplifyShaderEditor.TemplateMultiPassMasterNode;0;1164.958,-238.0224;Float;False;True;-1;2;ASEMaterialInspector;100;5;GuZhang;0770190933193b94aaa3065e307002fa;True;Unlit;0;0;Unlit;2;True;True;2;5;False;;10;False;;0;1;False;;0;False;;True;0;False;;0;False;;False;False;False;False;False;False;False;False;False;True;0;False;;False;True;0;False;;False;True;True;True;True;True;0;False;;False;False;False;False;False;False;False;True;False;0;False;;255;False;;255;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;False;True;1;False;;True;3;False;;True;True;0;False;;0;False;;True;2;RenderType=Transparent=RenderType;Queue=Transparent=Queue=0;True;2;False;0;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;0;;0;0;Standard;1;Vertex Position,InvertActionOnDeselection;1;0;0;1;True;False;;False;0
WireConnection;14;0;11;0
WireConnection;14;1;12;0
WireConnection;10;0;9;0
WireConnection;10;2;14;0
WireConnection;8;1;10;0
WireConnection;21;0;19;0
WireConnection;30;0;8;1
WireConnection;22;0;21;0
WireConnection;22;1;23;0
WireConnection;20;0;30;0
WireConnection;20;1;19;0
WireConnection;16;0;15;1
WireConnection;16;1;20;0
WireConnection;24;0;22;0
WireConnection;18;0;16;0
WireConnection;18;1;15;2
WireConnection;26;0;24;0
WireConnection;26;1;24;1
WireConnection;27;0;24;2
WireConnection;27;1;24;3
WireConnection;25;0;18;0
WireConnection;25;1;27;0
WireConnection;28;0;18;0
WireConnection;28;1;26;0
WireConnection;4;0;6;0
WireConnection;4;1;25;0
WireConnection;2;0;6;0
WireConnection;2;1;28;0
WireConnection;3;0;6;0
WireConnection;3;1;18;0
WireConnection;29;0;2;1
WireConnection;29;1;3;2
WireConnection;29;2;4;3
WireConnection;29;3;3;4
WireConnection;32;0;19;0
WireConnection;32;1;31;4
WireConnection;33;0;32;0
WireConnection;35;0;29;0
WireConnection;35;1;34;0
WireConnection;0;0;35;0
ASEEND*/
//CHKSM=CC8D4FA94542B4FA994824F1F95DA6E2BF1E8A0B

3. Hue(色相、明度、饱和度)

  • 代码:
点此展开

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// Made with Amplify Shader Editor v1.9.3.2
// Available at the Unity Asset Store - http://u3d.as/y3X
Shader "Shiki/Hue"
{
Properties
{
_TextureSample0("Texture Sample 0", 2D) = "white" {}
_HueAdjust("HueAdjust", Range( -1 , 1)) = 0
_ValueAdjust("ValueAdjust", Range( -1 , 1)) = 0
_SaturationAdjust("SaturationAdjust", Range( -1 , 1)) = 0
[HideInInspector] _texcoord( "", 2D ) = "white" {}

}

SubShader
{


Tags { "RenderType"="Transparent" "Queue"="Transparent" }
LOD 100

CGINCLUDE
#pragma target 3.0
ENDCG
Blend SrcAlpha OneMinusSrcAlpha
AlphaToMask Off
Cull Off
ColorMask RGBA
ZWrite Off
ZTest LEqual
Offset 0 , 0



Pass
{
Name "Unlit"

CGPROGRAM



#ifndef UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX
//only defining to not throw compilation error over Unity 5.5
#define UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input)
#endif
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_instancing
#include "UnityCG.cginc"


struct appdata
{
float4 vertex : POSITION;
float4 color : COLOR;
float4 ase_texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};

struct v2f
{
float4 vertex : SV_POSITION;
#ifdef ASE_NEEDS_FRAG_WORLD_POSITION
float3 worldPos : TEXCOORD0;
#endif
float4 ase_color : COLOR;
float4 ase_texcoord1 : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};

uniform sampler2D _TextureSample0;
uniform float4 _TextureSample0_ST;
uniform float _HueAdjust;
uniform float _SaturationAdjust;
uniform float _ValueAdjust;
float3 HSVToRGB( float3 c )
{
float4 K = float4( 1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0 );
float3 p = abs( frac( c.xxx + K.xyz ) * 6.0 - K.www );
return c.z * lerp( K.xxx, saturate( p - K.xxx ), c.y );
}

float3 RGBToHSV(float3 c)
{
float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
float4 p = lerp( float4( c.bg, K.wz ), float4( c.gb, K.xy ), step( c.b, c.g ) );
float4 q = lerp( float4( p.xyw, c.r ), float4( c.r, p.yzx ), step( p.x, c.r ) );
float d = q.x - min( q.w, q.y );
float e = 1.0e-10;
return float3( abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}


v2f vert ( appdata v )
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
UNITY_TRANSFER_INSTANCE_ID(v, o);

o.ase_color = v.color;
o.ase_texcoord1.xy = v.ase_texcoord.xy;

//setting value to unused interpolator channels and avoid initialization warnings
o.ase_texcoord1.zw = 0;
float3 vertexValue = float3(0, 0, 0);
#if ASE_ABSOLUTE_VERTEX_POS
vertexValue = v.vertex.xyz;
#endif
vertexValue = vertexValue;
#if ASE_ABSOLUTE_VERTEX_POS
v.vertex.xyz = vertexValue;
#else
v.vertex.xyz += vertexValue;
#endif
o.vertex = UnityObjectToClipPos(v.vertex);

#ifdef ASE_NEEDS_FRAG_WORLD_POSITION
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
#endif
return o;
}

fixed4 frag (v2f i ) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(i);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
fixed4 finalColor;
#ifdef ASE_NEEDS_FRAG_WORLD_POSITION
float3 WorldPosition = i.worldPos;
#endif
float2 uv_TextureSample0 = i.ase_texcoord1.xy * _TextureSample0_ST.xy + _TextureSample0_ST.zw;
float4 tex2DNode3 = tex2D( _TextureSample0, uv_TextureSample0 );
float3 hsvTorgb1 = RGBToHSV( tex2DNode3.rgb );
float3 hsvTorgb6 = HSVToRGB( float3(( hsvTorgb1.x + _HueAdjust ),( hsvTorgb1.y + _SaturationAdjust ),( hsvTorgb1.z + _ValueAdjust )) );
float4 appendResult7 = (float4(hsvTorgb6 , saturate( tex2DNode3.a )));


finalColor = ( i.ase_color * appendResult7 );
return finalColor;
}
ENDCG
}
}
CustomEditor "ASEMaterialInspector"

Fallback Off
}
/*ASEBEGIN
Version=19302
Node;AmplifyShaderEditor.SamplerNode;3;-955.8383,-47.848;Inherit;True;Property;_TextureSample0;Texture Sample 0;0;0;Create;True;0;0;0;False;0;False;-1;032996e4459cca641a6d4d89f436a478;4cd9fe53ba4453f40bda7bec8a4bf018;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.RGBToHSVNode;1;-554.5,-3.5;Inherit;False;1;0;FLOAT3;0,0,0;False;4;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3
Node;AmplifyShaderEditor.RangedFloatNode;5;-541.3859,367.7798;Inherit;False;Property;_HueAdjust;HueAdjust;1;0;Create;True;0;0;0;False;0;False;0;0;-1;1;0;1;FLOAT;0
Node;AmplifyShaderEditor.RangedFloatNode;10;-277.3328,-27.22626;Inherit;False;Property;_ValueAdjust;ValueAdjust;2;0;Create;True;0;0;0;False;0;False;0;0;-1;1;0;1;FLOAT;0
Node;AmplifyShaderEditor.RangedFloatNode;13;-468.0592,-210.9917;Inherit;False;Property;_SaturationAdjust;SaturationAdjust;3;0;Create;True;0;0;0;False;0;False;0;0;-1;1;0;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleAddOpNode;4;-204.4461,252.7277;Inherit;True;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleAddOpNode;11;83.66724,-156.2263;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleAddOpNode;12;-107.0592,-339.9918;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SaturateNode;9;139.7737,422.8393;Inherit;False;1;0;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.HSVToRGBNode;6;140.1472,48.45157;Inherit;True;3;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;4;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3
Node;AmplifyShaderEditor.DynamicAppendNode;7;508.9308,168.5919;Inherit;True;FLOAT4;4;0;FLOAT3;0,0,0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT4;0
Node;AmplifyShaderEditor.VertexColorNode;14;515.7672,-41.53622;Inherit;False;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;15;858.7672,96.46378;Inherit;False;2;2;0;COLOR;0,0,0,0;False;1;FLOAT4;0,0,0,0;False;1;COLOR;0
Node;AmplifyShaderEditor.TemplateMultiPassMasterNode;0;1064.739,70.52806;Float;False;True;-1;2;ASEMaterialInspector;100;5;BLK/Hue;0770190933193b94aaa3065e307002fa;True;Unlit;0;0;Unlit;2;True;True;2;5;False;;10;False;;0;1;False;;0;False;;True;0;False;;0;False;;False;False;False;False;False;False;False;False;False;True;0;False;;False;True;0;False;;False;True;True;True;True;True;0;False;;False;False;False;False;False;False;False;True;False;0;False;;255;False;;255;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;True;True;2;False;;True;3;False;;True;True;0;False;;0;False;;True;2;RenderType=Transparent=RenderType;Queue=Transparent=Queue=0;True;2;False;0;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;0;;0;0;Standard;1;Vertex Position,InvertActionOnDeselection;1;0;0;1;True;False;;False;0
WireConnection;1;0;3;0
WireConnection;4;0;1;1
WireConnection;4;1;5;0
WireConnection;11;0;1;3
WireConnection;11;1;10;0
WireConnection;12;0;1;2
WireConnection;12;1;13;0
WireConnection;9;0;3;4
WireConnection;6;0;4;0
WireConnection;6;1;12;0
WireConnection;6;2;11;0
WireConnection;7;0;6;0
WireConnection;7;3;9;0
WireConnection;15;0;14;0
WireConnection;15;1;7;0
WireConnection;0;0;15;0
ASEEND*/
//CHKSM=145B3A63A2B3D44135596F1A09C5E497FDF101F8

4. UV流动

  • 效果:

  • 代码:
点此展开
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Shader "Shiki/UVFlow"
{
Properties
{
[hideInInspector]_MainTex ("Texture", 2D) = "white" {}
_XSpeed ("XSpeed", Float) = 1
_YSpeed ("YSpeed", Float) = 0
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent"}
Blend SrcAlpha OneMinusSrcAlpha

Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag

#include "UnityCG.cginc"

struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};

struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};

sampler2D _MainTex;
float4 _MainTex_ST;
fixed _XSpeed;
fixed _YSpeed;

v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
v.uv += fixed2(_XSpeed * _Time.y, _YSpeed * _Time.y);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}

fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
return col;
}
ENDCG
}
}
}

5. 序列帧图片播放

  • 参数:

  • 代码:
点此展开
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
Shader "Shiki/Frame"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Color ("Color", Color) = (1,1,1,1)
_HorizontalAmount("Horizontal Amount", Float) = 4
_VerticalAmount("Vertical Amount", Float) = 4
_Speed ("Speed", Range(1, 50)) = 15
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" "IgnoreProjector"="True"}

ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Cull Off

Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag

#include "UnityCG.cginc"

struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float4 color : COLOR;
};

struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
float4 color : TEXCOORD1;
};

sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _Color;
float _HorizontalAmount;
float _VerticalAmount;
float _Speed;

v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.color = v.color;
return o;
}

fixed4 frag (v2f i) : SV_Target
{
float time = floor(_Time.y * _Speed);
float row = floor(time / _HorizontalAmount);
float column = time - row * _HorizontalAmount;

half2 uv = i.uv + half2(column, -row);
uv.x /= _HorizontalAmount;
uv.y /= _VerticalAmount;

fixed4 col = tex2D(_MainTex, uv);
col.rgb *= _Color;
return col * i.color;
}
ENDCG
}
}
}

6. 扫描光效果

  • 效果:

  • 贴图资源:

  • 参数:

  • 代码:
点此展开

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// Made with Amplify Shader Editor v1.9.3.2
// Available at the Unity Asset Store - http://u3d.as/y3X
Shader "Shiki/UIFlowing"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)

_StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0
_StencilOp ("Stencil Operation", Float) = 0
_StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255

_ColorMask ("Color Mask", Float) = 15

[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0

_Shading("Shading", 2D) = "black" {}
_NoiseIntensity("NoiseIntensity", Float) = 0.05
_ShadingSpeed("ShadingSpeed", Vector) = (0,0.4,0,0)
_NoiseSpeed("NoiseSpeed", Vector) = (0,0,0,0)
_NoiseTexture("NoiseTexture", 2D) = "white" {}
_AddColor("AddColor", Color) = (1,1,1,1)
[HideInInspector] _texcoord( "", 2D ) = "white" {}

}

SubShader
{
LOD 0

Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" }

Stencil
{
Ref [_Stencil]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
Comp [_StencilComp]
Pass [_StencilOp]
}


Cull Off
Lighting Off
ZWrite Off
ZTest [unity_GUIZTestMode]
Blend One OneMinusSrcAlpha
ColorMask [_ColorMask]


Pass
{
Name "Default"
CGPROGRAM

#pragma vertex vert
#pragma fragment frag
#pragma target 3.0

#include "UnityCG.cginc"
#include "UnityUI.cginc"

#pragma multi_compile_local _ UNITY_UI_CLIP_RECT
#pragma multi_compile_local _ UNITY_UI_ALPHACLIP

#include "UnityShaderVariables.cginc"
#define ASE_NEEDS_FRAG_COLOR


struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID

};

struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
float4 worldPosition : TEXCOORD1;
float4 mask : TEXCOORD2;
UNITY_VERTEX_OUTPUT_STEREO

};

sampler2D _MainTex;
fixed4 _Color;
fixed4 _TextureSampleAdd;
float4 _ClipRect;
float4 _MainTex_ST;
float _UIMaskSoftnessX;
float _UIMaskSoftnessY;

uniform sampler2D _Shading;
uniform float2 _ShadingSpeed;
uniform float4 _Shading_ST;
uniform sampler2D _NoiseTexture;
uniform float2 _NoiseSpeed;
uniform float4 _NoiseTexture_ST;
uniform float _NoiseIntensity;
uniform float4 _AddColor;


v2f vert(appdata_t v )
{
v2f OUT;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);



v.vertex.xyz += float3( 0, 0, 0 ) ;

float4 vPosition = UnityObjectToClipPos(v.vertex);
OUT.worldPosition = v.vertex;
OUT.vertex = vPosition;

float2 pixelSize = vPosition.w;
pixelSize /= float2(1, 1) * abs(mul((float2x2)UNITY_MATRIX_P, _ScreenParams.xy));

float4 clampedRect = clamp(_ClipRect, -2e10, 2e10);
float2 maskUV = (v.vertex.xy - clampedRect.xy) / (clampedRect.zw - clampedRect.xy);
OUT.texcoord = v.texcoord;
OUT.mask = float4(v.vertex.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * half2(_UIMaskSoftnessX, _UIMaskSoftnessY) + abs(pixelSize.xy)));

OUT.color = v.color * _Color;
return OUT;
}

fixed4 frag(v2f IN ) : SV_Target
{
//Round up the alpha color coming from the interpolator (to 1.0/256.0 steps)
//The incoming alpha could have numerical instability, which makes it very sensible to
//HDR color transparency blend, when it blends with the world's texture.
const half alphaPrecision = half(0xff);
const half invAlphaPrecision = half(1.0/alphaPrecision);
IN.color.a = round(IN.color.a * alphaPrecision)*invAlphaPrecision;

float2 uv_MainTex = IN.texcoord.xy * _MainTex_ST.xy + _MainTex_ST.zw;
float4 tex2DNode2 = tex2D( _MainTex, uv_MainTex );
float2 uv_Shading = IN.texcoord.xy * _Shading_ST.xy + _Shading_ST.zw;
float2 panner6 = ( 1.0 * _Time.y * _ShadingSpeed + uv_Shading);
float2 uv_NoiseTexture = IN.texcoord.xy * _NoiseTexture_ST.xy + _NoiseTexture_ST.zw;
float2 panner12 = ( 1.0 * _Time.y * _NoiseSpeed + uv_NoiseTexture);
float2 temp_cast_0 = (tex2D( _NoiseTexture, panner12 ).r).xx;
float2 lerpResult8 = lerp( panner6 , temp_cast_0 , _NoiseIntensity);


half4 color = ( ( tex2DNode2 + ( tex2DNode2.a * tex2D( _Shading, lerpResult8 ) * _AddColor ) ) * IN.color );

#ifdef UNITY_UI_CLIP_RECT
half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(IN.mask.xy)) * IN.mask.zw);
color.a *= m.x * m.y;
#endif

#ifdef UNITY_UI_ALPHACLIP
clip (color.a - 0.001);
#endif

color.rgb *= color.a;

return color;
}
ENDCG
}
}
CustomEditor "ASEMaterialInspector"

Fallback Off
}
/*ASEBEGIN
Version=19302
Node;AmplifyShaderEditor.TextureCoordinatesNode;11;-1390.019,330.9562;Inherit;False;0;10;2;3;2;SAMPLER2D;;False;0;FLOAT2;1,1;False;1;FLOAT2;0,0;False;5;FLOAT2;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.Vector2Node;13;-1345.274,484.4648;Inherit;False;Property;_NoiseSpeed;NoiseSpeed;3;0;Create;True;0;0;0;False;0;False;0,0;0,0;0;3;FLOAT2;0;FLOAT;1;FLOAT;2
Node;AmplifyShaderEditor.TextureCoordinatesNode;5;-1076.803,-12.40173;Inherit;False;0;4;2;3;2;SAMPLER2D;;False;0;FLOAT2;1,1;False;1;FLOAT2;0,0;False;5;FLOAT2;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.Vector2Node;7;-1075.481,168.8995;Inherit;False;Property;_ShadingSpeed;ShadingSpeed;2;0;Create;True;0;0;0;False;0;False;0,0.4;0,0;0;3;FLOAT2;0;FLOAT;1;FLOAT;2
Node;AmplifyShaderEditor.PannerNode;12;-1109.019,356.9562;Inherit;False;3;0;FLOAT2;0,0;False;2;FLOAT2;0,0;False;1;FLOAT;1;False;1;FLOAT2;0
Node;AmplifyShaderEditor.PannerNode;6;-825.2067,-8.06372;Inherit;False;3;0;FLOAT2;0,0;False;2;FLOAT2;0,0;False;1;FLOAT;1;False;1;FLOAT2;0
Node;AmplifyShaderEditor.RangedFloatNode;9;-576.4412,422.2407;Inherit;False;Property;_NoiseIntensity;NoiseIntensity;1;0;Create;True;0;0;0;False;0;False;0.05;0;0;0;0;1;FLOAT;0
Node;AmplifyShaderEditor.SamplerNode;10;-865.2081,300.8365;Inherit;True;Property;_NoiseTexture;NoiseTexture;4;0;Create;True;0;0;0;False;0;False;-1;c660f805ba7589c48990705a226d17af;c660f805ba7589c48990705a226d17af;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.TemplateShaderPropertyNode;1;-448.5,-169;Inherit;False;0;0;_MainTex;Shader;False;0;5;SAMPLER2D;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.LerpOp;8;-364.1982,221.579;Inherit;False;3;0;FLOAT2;0,0;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.SamplerNode;2;-165.5,-113;Inherit;True;Property;_TextureSample0;Texture Sample 0;0;0;Create;True;0;0;0;False;0;False;-1;None;None;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.SamplerNode;4;-161.5972,185.3049;Inherit;True;Property;_Shading;Shading;0;0;Create;True;0;0;0;False;0;False;-1;86d08dcc6de11b54c95c02ecb85e1c1d;86d08dcc6de11b54c95c02ecb85e1c1d;True;0;False;black;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.ColorNode;15;-33.11536,459.3895;Inherit;False;Property;_AddColor;AddColor;5;0;Create;True;0;0;0;False;0;False;1,1,1,1;1,1,1,1;True;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;14;349.8846,304.3895;Inherit;False;3;3;0;FLOAT;0;False;1;COLOR;0,0,0,0;False;2;COLOR;0,0,0,0;False;1;COLOR;0
Node;AmplifyShaderEditor.SimpleAddOpNode;3;501.9733,89.53397;Inherit;False;2;2;0;COLOR;0,0,0,0;False;1;COLOR;0,0,0,0;False;1;COLOR;0
Node;AmplifyShaderEditor.VertexColorNode;17;563.8846,267.3895;Inherit;False;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;16;778.8846,99.38953;Inherit;True;2;2;0;COLOR;0,0,0,0;False;1;COLOR;0,0,0,0;False;1;COLOR;0
Node;AmplifyShaderEditor.TemplateMultiPassMasterNode;0;988,86;Float;False;True;-1;2;ASEMaterialInspector;0;3;UIFlowing;5056123faa0c79b47ab6ad7e8bf059a4;True;Default;0;0;Default;2;False;True;3;1;False;;10;False;;0;1;False;;0;False;;False;False;False;False;False;False;False;False;False;False;False;False;True;2;False;;False;True;True;True;True;True;0;True;_ColorMask;False;False;False;False;False;False;False;True;True;0;True;_Stencil;255;True;_StencilReadMask;255;True;_StencilWriteMask;0;True;_StencilComp;0;True;_StencilOp;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;False;True;2;False;;True;0;True;unity_GUIZTestMode;False;True;5;Queue=Transparent=Queue=0;IgnoreProjector=True;RenderType=Transparent=RenderType;PreviewType=Plane;CanUseSpriteAtlas=True;False;False;0;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;True;2;False;0;;0;0;Standard;0;0;1;True;False;;False;0
WireConnection;12;0;11;0
WireConnection;12;2;13;0
WireConnection;6;0;5;0
WireConnection;6;2;7;0
WireConnection;10;1;12;0
WireConnection;8;0;6;0
WireConnection;8;1;10;1
WireConnection;8;2;9;0
WireConnection;2;0;1;0
WireConnection;4;1;8;0
WireConnection;14;0;2;4
WireConnection;14;1;4;0
WireConnection;14;2;15;0
WireConnection;3;0;2;0
WireConnection;3;1;14;0
WireConnection;16;0;3;0
WireConnection;16;1;17;0
WireConnection;0;0;16;0
ASEEND*/
//CHKSM=7B43AC024608F17057A69F37671FF10FA2C14CB3

7. 过场黑幕

  • 效果:

  • 代码:
点此展开
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
Shader "Shiki/BlackCurtainSDFShader"
{
Properties
{
[hideInInspector] _MainTex ("Texture", 2D) = "white" {}
[hideInInspector] _CircleScaleOffset ("CircleScaleOffset", Float) = 1 // Width / Height
[hideInInspector]_Radius ("Radius", Float) = 15
[hideInInspector]_RadiusThickness ("RadiusThickness", Float) = 10
_Lerp ("Lerp", Range(0, 1)) = 1
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent"}
Blend SrcAlpha OneMinusSrcAlpha

Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag

#include "UnityCG.cginc"

struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};

struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};

sampler2D _MainTex;
float4 _MainTex_ST;
float _CircleScaleOffset;
float _Radius;
float _RadiusThickness;
float _Lerp;

v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}

float sdCircle(float2 p, float r)
{
return length(p) - r;
}
float opAnnular(float sdf, float r)
{
return abs(sdf) - r;
}

fixed4 frag (v2f i) : SV_Target
{
fixed4 shape = tex2D(_MainTex, i.uv);
// 全象限
i.uv.y = 1.0 - i.uv.y;
i.uv = i.uv * 2 - 1;
// 消除屏幕拉伸影响
float w = _ScreenParams.x;
float h = _ScreenParams.y;
half co = w/h; // * _CircleScaleOffset;
i.uv = float2(i.uv.x * co, i.uv.y);

float step = 1.0 / w;
float Radius = 13 - _Lerp * 3;
fixed4 circle = smoothstep(step, -step, opAnnular(sdCircle(i.uv, Radius) , _RadiusThickness));
fixed4 col = fixed4(circle.rgb, shape.a);
col.a *= col.r;
col.rgb = fixed3(0,0,0);

return col;
}
ENDCG
}
}
}

  • 效果:

  • 代码:
点此展开
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
Shader "Shiki/BlackCurtainSDFShader_star5"
{
Properties
{
[hideInInspector] _MainTex ("Texture", 2D) = "white" {}
[hideInInspector] _CircleScaleOffset ("CircleScaleOffset", Float) = 1 // Width / Height
[hideInInspector] _Radius ("Radius", Float) = 0.03
_Lerp ("Lerp", Range(0, 1)) = 1
_Shape ("Shape", Range(0.1, 10)) = 2.5
}
SubShader
{
Tags {"RenderType"="Transparent" "Queue"="Transparent"}
Blend SrcAlpha OneMinusSrcAlpha

Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag

#include "UnityCG.cginc"

struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};

struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};

sampler2D _MainTex;
float4 _MainTex_ST;
float _CircleScaleOffset;
float _Radius;
float _Lerp;
float _Shape;

v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}

float sdStar5(in float2 p, in float r, in float rf)
{
const float2 k1 = float2(0.809016994375, -0.587785252292);
const float2 k2 = float2(-k1.x,k1.y);
p.x = abs(p.x);
p -= 2.0*max(dot(k1,p),0.0)*k1;
p -= 2.0*max(dot(k2,p),0.0)*k2;
p.x = abs(p.x);
p.y -= r;
float2 ba = rf*float2(-k1.y,k1.x) - float2(0,1);
float hh = clamp( dot(p,ba)/dot(ba,ba), 0.0, r );
float h = _ScreenParams.y;
return length(p-ba*h) * sign(p.y*ba.x-p.x*ba.y);
}

float opAnnular(float sdf, float r)
{
return abs(sdf) - r;
}

fixed4 frag (v2f i) : SV_Target
{
// 全象限
i.uv.y = 1.0 - i.uv.y;
i.uv = i.uv * 2 - 1;
// 消除屏幕拉伸影响
float w = _ScreenParams.x;
float h = _ScreenParams.y;
half co = w/h; // * _CircleScaleOffset;
i.uv = float2(i.uv.x * co, i.uv.y);

float step = 1.0 / w;
float Radius = 2.2 - 2.2 * _Lerp;
fixed4 star5 = smoothstep(step, -step, sdStar5(i.uv, Radius,_Shape));
star5.a = 1 - star5.a;
return star5;
}
ENDCG
}
}
}
  • 效果:

  • 代码:
点此展开

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Made with Amplify Shader Editor v1.9.3.2
// Available at the Unity Asset Store - http://u3d.as/y3X
Shader "Shiki/BlackCurtainShader"
{
Properties
{
_Lerp("Lerp", Range( 0 , 1)) = 0.6623793
_Tilling("Tilling", Vector) = (16,9,0,0)
_MainTex("MainTex", 2D) = "white" {}
[HideInInspector] _texcoord( "", 2D ) = "white" {}

}

SubShader
{


Tags { "RenderType"="Transparent" "Queue"="Transparent" }
LOD 100

CGINCLUDE
#pragma target 3.0
ENDCG
Blend SrcAlpha OneMinusSrcAlpha, SrcAlpha OneMinusSrcAlpha
AlphaToMask Off
Cull Back
ColorMask RGBA
ZWrite Off
ZTest LEqual
Offset 0 , 0



Pass
{
Name "Unlit"

CGPROGRAM



#ifndef UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX
//only defining to not throw compilation error over Unity 5.5
#define UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input)
#endif
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_instancing
#include "UnityCG.cginc"


struct appdata
{
float4 vertex : POSITION;
float4 color : COLOR;
float4 ase_texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};

struct v2f
{
float4 vertex : SV_POSITION;
#ifdef ASE_NEEDS_FRAG_WORLD_POSITION
float3 worldPos : TEXCOORD0;
#endif
float4 ase_texcoord1 : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};

uniform sampler2D _MainTex;
uniform float4 _MainTex_ST;
uniform float _Lerp;
uniform float2 _Tilling;


v2f vert ( appdata v )
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
UNITY_TRANSFER_INSTANCE_ID(v, o);

o.ase_texcoord1.xy = v.ase_texcoord.xy;

//setting value to unused interpolator channels and avoid initialization warnings
o.ase_texcoord1.zw = 0;
float3 vertexValue = float3(0, 0, 0);
#if ASE_ABSOLUTE_VERTEX_POS
vertexValue = v.vertex.xyz;
#endif
vertexValue = vertexValue;
#if ASE_ABSOLUTE_VERTEX_POS
v.vertex.xyz = vertexValue;
#else
v.vertex.xyz += vertexValue;
#endif
o.vertex = UnityObjectToClipPos(v.vertex);

#ifdef ASE_NEEDS_FRAG_WORLD_POSITION
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
#endif
return o;
}

fixed4 frag (v2f i ) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(i);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
fixed4 finalColor;
#ifdef ASE_NEEDS_FRAG_WORLD_POSITION
float3 WorldPosition = i.worldPos;
#endif
float2 uv_MainTex = i.ase_texcoord1.xy * _MainTex_ST.xy + _MainTex_ST.zw;
float2 texCoord3 = i.ase_texcoord1.xy * _Tilling + float2( 0,0 );
float2 texCoord23 = i.ase_texcoord1.xy * float2( 1,1 ) + float2( 0,0 );


finalColor = ( tex2D( _MainTex, uv_MainTex ) * ( 1.0 - step( (-0.1 + (_Lerp - 0.0) * (2.0 - -0.1) / (1.0 - 0.0)) , ( distance( frac( texCoord3 ) , float2( 0.5,0.5 ) ) + texCoord23.x ) ) ) );
return finalColor;
}
ENDCG
}
}
CustomEditor "ASEMaterialInspector"

Fallback Off
}
/*ASEBEGIN
Version=19302
Node;AmplifyShaderEditor.Vector2Node;7;-892.8181,27.85309;Inherit;False;Property;_Tilling;Tilling;1;0;Create;True;0;0;0;False;0;False;16,9;16,9;0;3;FLOAT2;0;FLOAT;1;FLOAT;2
Node;AmplifyShaderEditor.TextureCoordinatesNode;3;-664.7827,30.79254;Inherit;True;0;-1;2;3;2;SAMPLER2D;;False;0;FLOAT2;1,1;False;1;FLOAT2;0,0;False;5;FLOAT2;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.Vector2Node;2;-564.7827,332.7925;Inherit;False;Constant;_Vector0;Vector 0;0;0;Create;True;0;0;0;False;0;False;0.5,0.5;0,0;0;3;FLOAT2;0;FLOAT;1;FLOAT;2
Node;AmplifyShaderEditor.FractNode;8;-425.2271,4.836273;Inherit;False;1;0;FLOAT2;0,0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.DistanceOpNode;1;-284.5,133;Inherit;True;2;0;FLOAT2;0,0;False;1;FLOAT2;0,0;False;1;FLOAT;0
Node;AmplifyShaderEditor.TextureCoordinatesNode;23;-288.7357,405.5515;Inherit;True;0;-1;2;3;2;SAMPLER2D;;False;0;FLOAT2;1,1;False;1;FLOAT2;0,0;False;5;FLOAT2;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.RangedFloatNode;5;-658.142,-257.6541;Inherit;False;Property;_Lerp;Lerp;0;0;Create;True;0;0;0;False;0;False;0.6623793;0.934;0;1;0;1;FLOAT;0
Node;AmplifyShaderEditor.TFHCRemapNode;17;-314.2464,-232.8476;Inherit;False;5;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;1;False;3;FLOAT;-0.1;False;4;FLOAT;2;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleAddOpNode;10;-36.84021,268.4261;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.StepOpNode;4;112.4658,-32.47552;Inherit;True;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SamplerNode;24;161.2841,-314.2552;Inherit;True;Property;_MainTex;MainTex;2;0;Create;True;0;0;0;False;0;False;-1;None;d4d6919451fe3e24388816386a6d15a4;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.OneMinusNode;26;337.0888,-93.09485;Inherit;False;1;0;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;25;486.285,-214.155;Inherit;True;2;2;0;COLOR;0,0,0,0;False;1;FLOAT;0;False;1;COLOR;0
Node;AmplifyShaderEditor.TemplateMultiPassMasterNode;0;747.9399,-142.1815;Float;False;True;-1;2;ASEMaterialInspector;100;5;BlackCurtainShader;0770190933193b94aaa3065e307002fa;True;Unlit;0;0;Unlit;2;True;True;2;5;False;;10;False;;2;5;False;;10;False;;True;0;False;;0;False;;False;False;False;False;False;False;False;False;False;True;0;False;;True;True;0;False;;False;True;True;True;True;True;0;False;;False;False;False;False;False;False;False;True;False;0;False;;255;False;;255;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;True;True;2;False;;True;3;False;;True;True;0;False;;0;False;;True;2;RenderType=Transparent=RenderType;Queue=Transparent=Queue=0;True;2;False;0;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;0;;0;0;Standard;1;Vertex Position,InvertActionOnDeselection;1;0;0;1;True;False;;False;0
WireConnection;3;0;7;0
WireConnection;8;0;3;0
WireConnection;1;0;8;0
WireConnection;1;1;2;0
WireConnection;17;0;5;0
WireConnection;10;0;1;0
WireConnection;10;1;23;1
WireConnection;4;0;17;0
WireConnection;4;1;10;0
WireConnection;26;0;4;0
WireConnection;25;0;24;0
WireConnection;25;1;26;0
WireConnection;0;0;25;0
ASEEND*/
//CHKSM=E111E8EC234E9132281E3E85AA670F2BF86D2673

8. 梦境效果

  • 效果:

  • 代码:
点此展开
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
Shader "Shiki/Dream"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Radius ("Radius", Range(0, 1.2)) = 0.21
_w ("w", Range(0, 1)) = 0.578
_h ("h", Range(0, 1)) = 0.541
_fadeWidth ("fadeWidth", Range(0.001, 4)) = 0.08
_outterWidth ("outterWidth", Range(0, 5)) = 1.84
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent"}
Blend SrcAlpha OneMinusSrcAlpha

Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag

#include "UnityCG.cginc"

struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float4 color : COLOR;
};

struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 color : COLOR;
};

sampler2D _MainTex;
float4 _MainTex_ST;
float _Radius;
float _w;
float _h;
float _fadeWidth;
float _outterWidth;

float sdRect(float2 p, float2 b)
{
float2 d = abs(p) - b;
return min(max(d.x, d.y), 0.0) + length(max(d, 0.0));
}

float opRound(float sdf, float r)
{
return sdf - r;
}

v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.color = v.color;
return o;
}

fixed4 frag (v2f i) : SV_Target
{
i.uv = i.uv * 2 + (-1);
float w = _ScreenParams.x;
float step = 1 / w;
float sdfDis = opRound(sdRect(i.uv, float2(_w, _h)), _Radius);
float sdfDisOut = opRound(sdRect(i.uv, float2(_w+_outterWidth, _h+_outterWidth)), _Radius);
float rect = smoothstep(step, -step,sdfDis);
fixed4 col = fixed4(1, 1, 1, rect);
col.a *= smoothstep( -_fadeWidth, -step, sdfDis);
col += smoothstep(step, -step,sdfDisOut) - fixed4(1, 1, 1, rect);
return col * i.color;
}
ENDCG
}
}
}

  • 拓展:
    • 可调参数:圆角度、宽、高、内扩外扩程度
    • 一般用于模拟回忆、故事滤镜

9. 按轴向显示效果

  • 效果:

  • 代码:
点此展开
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Shader "Shiki/ScanVertical"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Lerp ("Lerp", Range(0,1)) = 1
_Direction ("Direction", Range(0, 1)) = 0
_Alpha ("Alpha", Range(0,1)) = 1
_Range ("Range", Range(0,1)) = 0.2
_OneMinus ("OneMinus", Range(0, 1)) = 0
_AlphaTotal ("AlphaTotal", Range(0, 1)) = 1
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
Blend SrcAlpha OneMinusSrcAlpha

Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag

#include "UnityCG.cginc"

struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float4 color : COLOR;
};

struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 color : COLOR;
};

sampler2D _MainTex;
float4 _MainTex_ST;
float _Lerp;
float _Alpha;
float _Range;
float _Direction;
float _OneMinus;
float _AlphaTotal;

v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.color = v.color;
return o;
}

fixed4 frag (v2f i) : SV_Target
{
fixed4 shape = tex2D(_MainTex, i.uv);
fixed4 col = sign(i.uv.y - (_Direction * _Lerp + (1 - _Direction) * (1 - _Lerp)));
col.a = saturate(col.a * shape.a) * _Alpha;
col.a = col.a + smoothstep(_Range, 0, i.uv.y) * shape.a * (1 - _Direction) + smoothstep(_Range, 1, i.uv.y) * shape.a * _Direction;
col.a += sign(col.r) * col.a;
col.a = saturate(col.a);
shape.a = abs(sign(_OneMinus) - col.a) * shape.a * _AlphaTotal;//col.a;
return shape * i.color;
}
ENDCG
}
}
}

  • 效果:

  • 代码:
点此展开
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Shader "Shiki/ScanHorizontal"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Lerp ("Lerp", Range(0,1)) = 1
_Direction ("Direction", Range(0, 1)) = 0
_Range ("Range", Range(0,1)) = 0.2
_OneMinus ("OneMinus", Range(0, 1)) = 0
_AlphaTotal ("AlphaTotal", Range(0, 1)) = 1
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
Blend SrcAlpha OneMinusSrcAlpha

Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag

#include "UnityCG.cginc"

struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
fixed4 color : COLOR;
};

struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
};

sampler2D _MainTex;
float4 _MainTex_ST;
float _Lerp;
float _Range;
float _Direction;
float _OneMinus;
float _AlphaTotal;

v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.color = v.color;
return o;
}

fixed4 frag (v2f i) : SV_Target
{
fixed4 shape = tex2D(_MainTex, i.uv);
fixed4 col = sign(i.uv.x - (_Direction * _Lerp + (1 - _Direction) * (1 - _Lerp)));
col.a = col.a + smoothstep(_Range, 0, i.uv.x) * shape.a * (1 - _Direction) + smoothstep(_Range, 1, i.uv.x) * shape.a * _Direction;
col.a += sign(col.r) * col.a;
col.a = saturate(col.a);
shape.a = abs(sign(_OneMinus) - col.a) * shape.a * _AlphaTotal;//col.a;
return shape * i.color;
}
ENDCG
}
}
}

10. 屏幕特效

  • 效果:

  • 参数:

  • 代码:
点此展开

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
// Made with Amplify Shader Editor v1.9.3.2
// Available at the Unity Asset Store - http://u3d.as/y3X
Shader "Shiki/Screen_TX"
{
Properties
{
[Enum(Off,0,On,1)]_toggleUV("主贴图UV是否极坐标", Float) = 1
_MainTex("MainTex", 2D) = "white" {}
_Mask("Mask", 2D) = "white" {}
_Color("Color", Color) = (1,1,1,1)
_Alpha("Alpha", Float) = 1
_RGBA_Mask("RGBA_Mask", Vector) = (1,0,0,0)
_TillingOffset("TillingOffset", Vector) = (1,1,0,0)
_MaskTillingOffset("MaskTillingOffset", Vector) = (1,1,0,0)
_Scale("Scale", Float) = 1
_MaskScale("MaskScale", Float) = 1
_Speed("Speed", Vector) = (1,1,0,0)
_TimeScaleOffset("TimeScaleOffset", Vector) = (1,1,0,0)

}

SubShader
{


Tags { "RenderType"="Opaque" "Queue"="Transparent" }
LOD 100

CGINCLUDE
#pragma target 3.0
ENDCG
Blend SrcAlpha OneMinusSrcAlpha
AlphaToMask Off
Cull Off
ColorMask RGBA
ZWrite Off
ZTest LEqual
Offset 0 , 0



Pass
{
Name "Unlit"

CGPROGRAM



#ifndef UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX
//only defining to not throw compilation error over Unity 5.5
#define UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input)
#endif
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_instancing
#include "UnityCG.cginc"
#include "UnityShaderVariables.cginc"


struct appdata
{
float4 vertex : POSITION;
float4 color : COLOR;

UNITY_VERTEX_INPUT_INSTANCE_ID
};

struct v2f
{
float4 vertex : SV_POSITION;
#ifdef ASE_NEEDS_FRAG_WORLD_POSITION
float3 worldPos : TEXCOORD0;
#endif
float4 ase_texcoord1 : TEXCOORD1;
float4 ase_color : COLOR;
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};

uniform sampler2D _MainTex;
uniform float2 _TimeScaleOffset;
uniform float2 _Speed;
uniform float _toggleUV;
uniform float4 _TillingOffset;
uniform float4 _Color;
uniform float _Scale;
uniform float _Alpha;
uniform float4 _RGBA_Mask;
uniform sampler2D _Mask;
uniform float4 _MaskTillingOffset;
uniform float _MaskScale;


v2f vert ( appdata v )
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
UNITY_TRANSFER_INSTANCE_ID(v, o);

float4 ase_clipPos = UnityObjectToClipPos(v.vertex);
float4 screenPos = ComputeScreenPos(ase_clipPos);
o.ase_texcoord1 = screenPos;

o.ase_color = v.color;
float3 vertexValue = float3(0, 0, 0);
#if ASE_ABSOLUTE_VERTEX_POS
vertexValue = v.vertex.xyz;
#endif
vertexValue = vertexValue;
#if ASE_ABSOLUTE_VERTEX_POS
v.vertex.xyz = vertexValue;
#else
v.vertex.xyz += vertexValue;
#endif
o.vertex = UnityObjectToClipPos(v.vertex);

#ifdef ASE_NEEDS_FRAG_WORLD_POSITION
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
#endif
return o;
}

float4 frag (v2f i ) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(i);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
float4 finalColor;
#ifdef ASE_NEEDS_FRAG_WORLD_POSITION
float3 WorldPosition = i.worldPos;
#endif
float mulTime18 = _Time.y * _TimeScaleOffset.x;
float2 appendResult16 = (float2(_Speed.x , _Speed.y));
float4 screenPos = i.ase_texcoord1;
float4 ase_screenPosNorm = screenPos / screenPos.w;
ase_screenPosNorm.z = ( UNITY_NEAR_CLIP_VALUE >= 0 ) ? ase_screenPosNorm.z : ase_screenPosNorm.z * 0.5 + 0.5;
float2 appendResult9 = (float2(ase_screenPosNorm.x , ase_screenPosNorm.y));
float2 appendResult35 = (float2(ase_screenPosNorm.x , ase_screenPosNorm.y));
float2 temp_output_36_0 = (appendResult35*2.0 + -1.0);
float2 break43 = temp_output_36_0;
float2 appendResult46 = (float2(length( temp_output_36_0 ) , (0.0 + (atan2( break43.y , break43.x ) - 0.0) * (1.0 - 0.0) / (UNITY_PI - 0.0))));
float2 lerpResult48 = lerp( appendResult9 , appendResult46 , _toggleUV);
float2 appendResult13 = (float2(_TillingOffset.x , _TillingOffset.y));
float2 appendResult14 = (float2(_TillingOffset.z , _TillingOffset.w));
float2 panner10 = ( ( mulTime18 + _TimeScaleOffset.y ) * appendResult16 + (lerpResult48*appendResult13 + appendResult14));
float4 tex2DNode1 = tex2D( _MainTex, panner10 );
float2 appendResult33 = (float2(_MaskTillingOffset.x , _MaskTillingOffset.y));
float2 appendResult32 = (float2(_MaskTillingOffset.z , _MaskTillingOffset.w));
float4 appendResult5 = (float4(( tex2DNode1 * _Color * _Scale * i.ase_color ).rgb , ( _Alpha * ( ( tex2DNode1.r * _RGBA_Mask.x ) + ( tex2DNode1.g * _RGBA_Mask.y ) + ( tex2DNode1.b * _RGBA_Mask.z ) + ( tex2DNode1.a * _RGBA_Mask.w ) ) * ( tex2D( _Mask, (appendResult9*appendResult33 + appendResult32) ) * _MaskScale ) ).r));


finalColor = appendResult5;
return finalColor;
}
ENDCG
}
}
CustomEditor "ASEMaterialInspector"

Fallback Off
}
/*ASEBEGIN
Version=19302
Node;AmplifyShaderEditor.ScreenPosInputsNode;8;-3424.466,-503.7861;Float;False;0;False;0;5;FLOAT4;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.DynamicAppendNode;35;-3189.624,-261.7405;Inherit;True;FLOAT2;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.ScaleAndOffsetNode;36;-2867.845,-257.2079;Inherit;True;3;0;FLOAT2;0,0;False;1;FLOAT;2;False;2;FLOAT;-1;False;1;FLOAT2;0
Node;AmplifyShaderEditor.BreakToComponentsNode;43;-2595.251,77.86584;Inherit;False;FLOAT2;1;0;FLOAT2;0,0;False;16;FLOAT;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4;FLOAT;5;FLOAT;6;FLOAT;7;FLOAT;8;FLOAT;9;FLOAT;10;FLOAT;11;FLOAT;12;FLOAT;13;FLOAT;14;FLOAT;15
Node;AmplifyShaderEditor.PiNode;55;-2457.88,369.1848;Inherit;False;1;0;FLOAT;1;False;1;FLOAT;0
Node;AmplifyShaderEditor.ATan2OpNode;44;-2421.251,83.86584;Inherit;True;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.LengthOpNode;37;-2464.544,-243.7079;Inherit;True;1;0;FLOAT2;0,0;False;1;FLOAT;0
Node;AmplifyShaderEditor.TFHCRemapNode;45;-2168.252,115.8658;Inherit;False;5;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;3.141593;False;3;FLOAT;0;False;4;FLOAT;1;False;1;FLOAT;0
Node;AmplifyShaderEditor.Vector4Node;12;-1617.439,-203.2669;Inherit;False;Property;_TillingOffset;TillingOffset;6;0;Create;True;0;0;0;False;0;False;1,1,0,0;1,1,0,0;0;5;FLOAT4;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.Vector2Node;51;-1485.661,136.278;Inherit;False;Property;_TimeScaleOffset;TimeScaleOffset;11;0;Create;True;0;0;0;False;0;False;1,1;1,0;0;3;FLOAT2;0;FLOAT;1;FLOAT;2
Node;AmplifyShaderEditor.DynamicAppendNode;9;-1480.383,-443.9041;Inherit;False;FLOAT2;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.RangedFloatNode;49;-1707.343,-335.0562;Inherit;False;Property;_toggleUV;主贴图UV是否极坐标;0;1;[Enum];Create;False;0;2;Off;0;On;1;0;False;0;False;1;1;0;0;0;1;FLOAT;0
Node;AmplifyShaderEditor.DynamicAppendNode;46;-1975.829,-150.7183;Inherit;True;FLOAT2;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.DynamicAppendNode;14;-1396.439,-113.2668;Inherit;False;FLOAT2;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.DynamicAppendNode;13;-1397.439,-206.2669;Inherit;False;FLOAT2;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.Vector2Node;50;-1441.661,10.27795;Inherit;False;Property;_Speed;Speed;10;0;Create;True;0;0;0;False;0;False;1,1;1,1;0;3;FLOAT2;0;FLOAT;1;FLOAT;2
Node;AmplifyShaderEditor.SimpleTimeNode;18;-1134.07,126.9291;Inherit;False;1;0;FLOAT;1;False;1;FLOAT;0
Node;AmplifyShaderEditor.LerpOp;48;-1222.343,-422.0562;Inherit;False;3;0;FLOAT2;0,0;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.DynamicAppendNode;16;-1125.502,2.695892;Inherit;False;FLOAT2;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.Vector4Node;31;-1095.063,854.8722;Inherit;False;Property;_MaskTillingOffset;MaskTillingOffset;7;0;Create;True;0;0;0;False;0;False;1,1,0,0;1,1,0,0;0;5;FLOAT4;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.SimpleAddOpNode;19;-939.0702,162.9291;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.ScaleAndOffsetNode;11;-1133.439,-234.267;Inherit;False;3;0;FLOAT2;0,0;False;1;FLOAT2;1,0;False;2;FLOAT2;0,0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.DynamicAppendNode;32;-874.064,944.8725;Inherit;False;FLOAT2;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.DynamicAppendNode;33;-875.064,851.8722;Inherit;False;FLOAT2;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.PannerNode;10;-816.4438,-101.9479;Inherit;False;3;0;FLOAT2;0,0;False;2;FLOAT2;0,0;False;1;FLOAT;1;False;1;FLOAT2;0
Node;AmplifyShaderEditor.SamplerNode;1;-610.2937,-137.6392;Inherit;True;Property;_MainTex;MainTex;1;0;Create;True;0;0;0;False;0;False;-1;None;4ad524818053b0949b65ba4d061ccac5;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.Vector4Node;26;-651.1687,470.1977;Inherit;False;Property;_RGBA_Mask;RGBA_Mask;5;0;Create;True;0;0;0;False;0;False;1,0,0,0;1,1,1,0;0;5;FLOAT4;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.ScaleAndOffsetNode;34;-611.064,823.8719;Inherit;False;3;0;FLOAT2;0,0;False;1;FLOAT2;1,0;False;2;FLOAT2;0,0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;22;-266.1687,350.1977;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;23;-263.1687,464.1977;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;24;-261.1687,571.1977;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;25;-261.1687,671.1977;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SamplerNode;28;-305.9966,849.3268;Inherit;True;Property;_Mask;Mask;2;0;Create;True;0;0;0;False;0;False;-1;None;c87093dfaecbca442a86bc15accd31d0;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.RangedFloatNode;29;-221.4968,1111.927;Inherit;False;Property;_MaskScale;MaskScale;9;0;Create;True;0;0;0;False;0;False;1;1;0;0;0;1;FLOAT;0
Node;AmplifyShaderEditor.ColorNode;7;-601.2937,71.36084;Inherit;False;Property;_Color;Color;3;0;Create;True;0;0;0;False;0;False;1,1,1,1;1,1,1,1;True;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.RangedFloatNode;4;-556.2937,280.3608;Inherit;False;Property;_Scale;Scale;8;0;Create;True;0;0;0;False;0;False;1;0.85;0;0;0;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleAddOpNode;27;-53.98921,494.2824;Inherit;False;4;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.RangedFloatNode;6;-53.30715,292.8151;Inherit;False;Property;_Alpha;Alpha;4;0;Create;True;0;0;0;False;0;False;1;0.5;0;0;0;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;30;67.10324,988.4271;Inherit;False;2;2;0;COLOR;0,0,0,0;False;1;FLOAT;0;False;1;COLOR;0
Node;AmplifyShaderEditor.VertexColorNode;52;-596.7842,-359.4721;Inherit;False;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;3;-297.2937,77.36084;Inherit;False;4;4;0;COLOR;0,0,0,0;False;1;COLOR;0,0,0,0;False;2;FLOAT;0;False;3;COLOR;0,0,0,0;False;1;COLOR;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;21;178.6203,372.3519;Inherit;False;3;3;0;FLOAT;0;False;1;FLOAT;0;False;2;COLOR;0,0,0,0;False;1;COLOR;0
Node;AmplifyShaderEditor.DynamicAppendNode;5;417.8781,79.6699;Inherit;False;FLOAT4;4;0;FLOAT3;0,0,0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT4;0
Node;AmplifyShaderEditor.TemplateMultiPassMasterNode;0;643.1719,-16.69092;Float;False;True;-1;2;ASEMaterialInspector;100;5;BLK/Screen_TX;0770190933193b94aaa3065e307002fa;True;Unlit;0;0;Unlit;2;True;True;2;5;False;;10;False;;0;1;False;;0;False;;True;0;False;;0;False;;False;False;False;False;False;False;False;False;False;True;0;False;;True;True;2;False;;False;True;True;True;True;True;0;False;;False;False;False;False;False;False;False;True;False;0;False;;255;False;;255;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;True;True;2;False;;True;3;False;;True;True;0;False;;0;False;;True;2;RenderType=Opaque=RenderType;Queue=Transparent=Queue=0;True;2;False;0;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;0;;0;0;Standard;1;Vertex Position,InvertActionOnDeselection;1;0;0;1;True;False;;False;0
WireConnection;35;0;8;1
WireConnection;35;1;8;2
WireConnection;36;0;35;0
WireConnection;43;0;36;0
WireConnection;44;0;43;1
WireConnection;44;1;43;0
WireConnection;37;0;36;0
WireConnection;45;0;44;0
WireConnection;45;2;55;0
WireConnection;9;0;8;1
WireConnection;9;1;8;2
WireConnection;46;0;37;0
WireConnection;46;1;45;0
WireConnection;14;0;12;3
WireConnection;14;1;12;4
WireConnection;13;0;12;1
WireConnection;13;1;12;2
WireConnection;18;0;51;1
WireConnection;48;0;9;0
WireConnection;48;1;46;0
WireConnection;48;2;49;0
WireConnection;16;0;50;1
WireConnection;16;1;50;2
WireConnection;19;0;18;0
WireConnection;19;1;51;2
WireConnection;11;0;48;0
WireConnection;11;1;13;0
WireConnection;11;2;14;0
WireConnection;32;0;31;3
WireConnection;32;1;31;4
WireConnection;33;0;31;1
WireConnection;33;1;31;2
WireConnection;10;0;11;0
WireConnection;10;2;16;0
WireConnection;10;1;19;0
WireConnection;1;1;10;0
WireConnection;34;0;9;0
WireConnection;34;1;33;0
WireConnection;34;2;32;0
WireConnection;22;0;1;1
WireConnection;22;1;26;1
WireConnection;23;0;1;2
WireConnection;23;1;26;2
WireConnection;24;0;1;3
WireConnection;24;1;26;3
WireConnection;25;0;1;4
WireConnection;25;1;26;4
WireConnection;28;1;34;0
WireConnection;27;0;22;0
WireConnection;27;1;23;0
WireConnection;27;2;24;0
WireConnection;27;3;25;0
WireConnection;30;0;28;0
WireConnection;30;1;29;0
WireConnection;3;0;1;0
WireConnection;3;1;7;0
WireConnection;3;2;4;0
WireConnection;3;3;52;0
WireConnection;21;0;6;0
WireConnection;21;1;27;0
WireConnection;21;2;30;0
WireConnection;5;0;3;0
WireConnection;5;3;21;0
WireConnection;0;0;5;0
ASEEND*/
//CHKSM=8361E30B4D3F1B6506DE49E77982A3146C215563
  • 拓展:
    • 需要放在粒子系统上使用,需要该粒子被摄像机看到,即修改MinPerticleSize

11. 两种贴图切换

  • 参数:

  • 代码:
点此展开
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Shader "Shiki/TrueOrFalse"
{
Properties
{
_MainTex ("TextureTrue", 2D) = "white" {}
_MainTex_False ("TextureFalse", 2D) = "white" {}
[Toggle] _True ("True", Float) = 0
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
Blend SrcAlpha OneMinusSrcAlpha

Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"

struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float4 color : COLOR;
};

struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 color : COLOR;
};

sampler2D _MainTex;
sampler2D _MainTex_False;
float4 _MainTex_ST;
float4 _MainTex_False_ST;
float _True;

v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.color = v.color;
return o;
}

fixed4 frag (v2f i) : SV_Target
{
fixed4 col;
col = _True ? tex2D(_MainTex, i.uv) : tex2D(_MainTex_False, i.uv);
return col * i.color;
}
ENDCG
}
}
}

12. 两个正多边形进行布尔运算或混合

  • 效果:


  • 参数:

  • 代码:
点此展开
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
Shader "Shiki/SDFImage"
{
Properties
{
[hideInInspector] _MainTex("Sprite Texture", 2D) = "white" {}
_TillingOffset ("TillingOffset", Vector) = (1, 1, 0, 0)
[Header(__________________________________Shape__________________________________)][Space(10)]
[Enum(Circle, 0, Rect, 1, RegularPolygon, 2)] _Shape ("Shape", Float) = 0
[IntRange] _N ("N", Range(0, 30)) = 3
[Header(_________________________________Attribute_________________________________)][Space(10)]
_Center ("Center", Vector) = (0.5, 0.5, 0.5, 0.5)
_Radius ("Radius", Vector) = (1, 1, 1, 1)
_StartAngle ("StartAngle", Float) = 0
_Softness("Softness", Range(0, 1)) = 0
_Color ("Color", Color) = (1, 1, 1, 1)
[Header(_________________________________Operation_________________________________)][Space(10)]
[Enum(Union, 0, Intersection, 1, Subtraction, 2, ShapeBlending, 3)] _Operation ("Operation", Float) = 0
_BlendRadius("BlendRadius", Range(0.0001, 3.0)) = 0.0001
_BlendFactor ("BlendFactor", Range(0, 1)) = 0
[Toggle] _BlendFactorUseImageR ("BlendFactorUseImageR", Float) = 0
[hideInInspector][IntRange] _SDFDataLength ("SDFDataLength", Range(0, 10)) = 2
[Header(_________________________________Edge_________________________________)][Space(10)]
[Toggle] _UseEdge ("UseEdge", Float) = 0
[Toggle] _UseLerp ("UseLerp", Float) = 0
_EdgeColor ("EdgeColor", Color) = (.6, .6, .6, 1)
_EdgeSize ("EdgeSize", Range(0.0001, 1)) = 0.001
}

SubShader
{
Tags {"Queue" = "Transparent" "RenderType" = "Transparent" "CanUseSpriteAtlas" = "True"}

Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
Cull Off

Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"

#define SDFOperation_Union 0
#define SDFOperation_Intersection 1
#define SDFOperation_Subtraction 2
#define SDFOperation_ShapeBlending 3

#define Shape_Circle 0
#define Shape_Rect 1
#define Shape_RegularPolygon 2

struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float4 color: COLOR;
};

struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
fixed4 color: COLOR;
};

sampler2D _MainTex;
float4 _MainTex_ST;
float4 _SDFDataBuffer[16];
int _SDFDataLength;
float _BlendRadius;
float _Softness;
float4 _Center;
float4 _Radius;
float _N;
float _StartAngle;
float _Shape;
float _Operation;
float _BlendFactor;
float4 _TillingOffset;
float _BlendFactorUseImageR;
float _EdgeSize;
float _UseEdge;
float _UseLerp;
float4 _Color;
float4 _EdgeColor;

#define PI 3.141592653589793238

float smin(float a, float b, float k) {
float h = max(k - abs(a - b), 0.0f) / k;
return min(a, b) - h * h * k * 0.25f;
}

float smax(float a, float b, float k) {
float h = max(k - abs(a - b), 0.0f) / k;
return max(a, b) + h * h * k * 0.25f;
}

float distanceToLine(float2 pt, float2 p0, float2 p1)
{
float2 v = p1 - p0;
float2 w = pt - p0;
float c1 = dot(w, v);
float c2 = dot(v, v);
return length(w - v * (c1 / c2));
}

v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
v.uv = v.uv * _TillingOffset.xy;
v.uv -= _TillingOffset.zw;
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.color = v.color;
return o;
}

float sdfCircle(float2 pt, inout uint index)
{
float2 center = index == 0 ? _Center.xy : _Center.zw;

float2 radius = (index == 0 ? _Radius.xy : _Radius.zw)* 0.5f;

float dx = center.x - pt.x;
float dy = center.y - pt.y;
dx = dx / radius.x;
dy = dy / radius.y;
float normalizedDistance = sqrt(dx * dx + dy * dy);
return 1 - normalizedDistance;
}

float sdfRect(float2 pt, inout uint index)
{
float2 center = index == 0 ? _Center.xy : _Center.zw;

float2 sizeHalf = (index == 0 ? _Radius.xy : _Radius.zw)* 0.5f;

float dx = center.x - pt.x;
float dy = center.y - pt.y;
dx = dx / sizeHalf.x;
dy = dy / sizeHalf.y;

float2 normalizedDistance = float2(abs(dx) - 0.5, abs(dy) - 0.5);

float dist = max(max(normalizedDistance.x, normalizedDistance.y), 0);
return 0.5 - dist;
}

float sdfRegularPolygon(float2 pt, inout uint index)
{
float2 center = index == 0 ? _Center.xy : _Center.zw;

float2 sizeHalf = (index == 0 ? _Radius.xy : _Radius.zw)* 0.5f;
int n = (int)_N;
float startAngle = radians(_StartAngle);

float dx = pt.x - center.x;
float dy = pt.y - center.y;
dx = dx / sizeHalf.x;
dy = dy / sizeHalf.y;

float2 pointLocal = float2(dx, dy);

float angle = 2 * PI / n;
float halfAngle = angle / 2;
float cosHalfAngle = cos(halfAngle);
float sinHalfAngle = sin(halfAngle);

float radius = cosHalfAngle / (1.0f + cosHalfAngle);

float pointAngle = atan2(pointLocal.y, pointLocal.x) - startAngle;
if (pointAngle < 0)
{
pointAngle += 2 * PI;
}

int closestEdgeIndex = (int)floor(pointAngle / angle);

float angleEdge = closestEdgeIndex * angle + startAngle;
float2 pointEdge = float2(radius * cos(angleEdge), radius * sin(angleEdge));
float angleNextEdge = (closestEdgeIndex + 1) * angle + startAngle;
float2 pointNextEdge = float2(radius * cos(angleNextEdge), radius * sin(angleNextEdge));

float distToSegment = distanceToLine(pointLocal,pointEdge,pointNextEdge );

return radius - distToSegment;
}

fixed4 frag(v2f i) : SV_Target
{
float sdf = 0;
float sdfTemp = 0;
int operation = SDFOperation_Union;
int shape = Shape_Circle;

for (int j = 0; j < (int)_SDFDataLength;j++)
{
bool first = j == 0;

shape = _Shape;

switch (shape)
{
case Shape_Circle:
sdfTemp = sdfCircle(i.uv, j);
break;
case Shape_Rect:
sdfTemp = sdfRect(i.uv, j);
break;
case Shape_RegularPolygon:
sdfTemp = sdfRegularPolygon(i.uv, j);
break;
}
sdfTemp-=_BlendRadius;

operation = _Operation;

if (first)
{

sdf = sdfTemp;
}
else
{
switch (operation)
{
case SDFOperation_Union:
sdf = smax(sdf, sdfTemp, _BlendRadius);
break;
case SDFOperation_Intersection:
sdf = smin(sdf, sdfTemp, _BlendRadius);
break;
case SDFOperation_Subtraction:
sdf = smin(sdf, -sdfTemp, _BlendRadius);
break;
case SDFOperation_ShapeBlending:
float factor = _BlendFactorUseImageR ? i.color.r : _BlendFactor;
sdf = (1 - factor) * sdf + factor * sdfTemp;
break;
}
}
}
float4 col = sdf;

float halfSoft = _Softness * 0.5f;
col = smoothstep(-halfSoft, halfSoft, sdf);

col *= _Color;

if (sdf < _EdgeSize && sdf >= 0)
{
col = _UseEdge ? _UseLerp ? lerp(_EdgeColor, col, sdf * 1.0 / _EdgeSize) : _EdgeColor : col;
}

col.a *= i.color.a;

return col;
}

ENDCG
}
}
}