-
Notifications
You must be signed in to change notification settings - Fork 3
/
ship_building.gdshader
45 lines (37 loc) · 1.18 KB
/
ship_building.gdshader
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
//based on https://godotshaders.com/shader/progress-bar-anything/
shader_type canvas_item;
uniform vec4 fill_color: source_color = vec4(1.0);
uniform float min_val;
uniform float current_val;
uniform float max_val;
/*
linear normalization from one range to another
*/
float linear(float old_min, float old_max, float new_min, float new_max, float current) {
float old_range = (old_max - old_min);
float new_range = (new_max - new_min);
float new_val = (((current - old_min) * new_range) / old_range ) + new_min;
return new_val;
}
void fragment() {
// Called for every pixel the material is visible on.
vec4 color = COLOR;
float normalized = linear(min_val, max_val, 0.0, 1.0, current_val);
/*
If value is less than or equal to the calculated point
between min and max that current_value falls on, mix with our
fill color
*/
//we want it to grow bottom-up hence this calculation
if (1.0-UV.y >= normalized) {
//if (UV.y >= normalized) {
color.rgb = mix(color.rgb, fill_color.rgb, 0.5);
//color.a = mix(0.0, 1.0, 1.0);
//color.rgb = fill_color.rgb;
color.a = 0.0;
}
COLOR = color;
}
void light() {
// Called for every pixel for every light affecting the CanvasItem.
}