-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleHealthBar.shader
More file actions
65 lines (54 loc) · 1.59 KB
/
SimpleHealthBar.shader
File metadata and controls
65 lines (54 loc) · 1.59 KB
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
Shader "Unlit/SimpleHealthBar"
{
Properties
{
_Health ("Health", Range(0,1)) = 1
[Header(Start)]
_StartColor ("StartColor", Color) = (1,0,0,1)
_StartThreshold ("StartThreshold", Range(0, 1)) = 0.2
[Header(End)]
_EndColor ("EndColor", Color) = (0,1,0,1)
_EndThreshold ("EndThreshold", Range(0, 1)) = 0.8
}
SubShader
{
Tags { "RenderType"="Opaque" }
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;
};
fixed4 _StartColor;
fixed4 _EndColor;
float _Health;
float _StartThreshold;
float _EndThreshold;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float weight = (_Health < _StartThreshold) ? 0 : _Health;
weight = (_Health > _EndThreshold) ? 1 : weight;
fixed4 color = lerp(_StartColor, _EndColor, weight) * (i.uv.x < _Health);
return color;
}
ENDCG
}
}
}