Unity shader 护盾shield的简单实现
擾動(dòng)
直接對(duì)uv進(jìn)行變換就可以了,記得首先把六邊形格子地圖的Tilling調(diào)高點(diǎn) 先預(yù)先調(diào)成合適大小的六邊形,然后repeat鋪滿整個(gè)護(hù)盾
1
2
3
4
5
6
// Tiles and offsets the value of input UV by the inputs Tiling and Offset respectively.
// This is commonly used for detail maps and scrolling textures over Time.
void Unity_TilingAndOffset_float(float2 UV, float2 Tiling, float2 Offset, out float2 Out)
{
Out = UV * Tiling + Offset;
}
直接在vertex著色器中對(duì)appdata傳進(jìn)來(lái)的uv進(jìn)行變動(dòng),兩者 offset的變動(dòng)頻率不同
1
2
3
4
5
6
7
8
9
10
11
12
13
14
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
half2 uv = TRANSFORM_TEX(v.uv, _MainTex);
Unity_TilingAndOffset_float(uv, half2(1, 1), half2(0, -_Time.y), o.uv);
Unity_TilingAndOffset_float(uv, half2(1, 1), half2(0, -_Time.y * 2), o.uvGlow);
護(hù)盾邊緣光
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 normal : NORMAL;
};
vertex著色器
1
2
3
4
5
6
7
8
9
10
11
12
13
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
…
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
fragment著色器
先獲取世界坐標(biāo)系下的法線向量和世界坐標(biāo)系下攝像機(jī)到頂點(diǎn)的向量,1-點(diǎn)乘得到的值然后結(jié)合到最后的顏色輸出計(jì)算中,法線向量與攝像機(jī)到頂點(diǎn)的向量的所成夾角可視為從中心點(diǎn)向邊緣擴(kuò)散,角度越來(lái)越大,到邊緣區(qū)角度呈局部最大值
1
2
3
4
5
6
7
8
9
10
11
half4 frag (v2f i) : SV_Target
{
…
half rim = pow(1 - abs(dot(normalize(i.worldNormal), normalize(i.worldViewDir))), _RimNum);
全部代碼
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
Shader “Unlit/ShieldForceField”
{
Properties
{
_MainTex (“Texture”, 2D) = “white” {}
[NoScaleOffset] _LightTex (“LightTex”, 2D) = “white” {}
_Hologram (“Hologram”, 2D) = “white” {}
[HDR] _LightColor (“LightColor”, Color) = (1, 1, 1, 1)
// 邊緣光幅度
_RimNum(“Rim” , Range(0 , 5)) = 1
}
SubShader
{
Tags
{
“RenderType” = “Transparent”
“Queue” = “Transparent”
“IgnoreProjector” = “True”
“ForceNoShadowCasting” = “True”
}
}
最后大功告成了,后續(xù)可能會(huì)繼續(xù)改進(jìn)一下(加上相交時(shí)會(huì)留下邊緣光)
USB Microphone https://www.soft-voice.com/
Wooden Speakers https://www.zeshuiplatform.com/
亞馬遜測(cè)評(píng) www.yisuping.cn
深圳網(wǎng)站建設(shè)www.sz886.com
總結(jié)
以上是生活随笔為你收集整理的Unity shader 护盾shield的简单实现的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 几何语言点C是ab的中点,备战中考:初中
- 下一篇: 闲鱼卖货,月入1.5w的小众类目分享。