harvest/game/resources/hp_bar.gdshader
2026-10-04 12:07:36 -04:00

23 lines
917 B
Text

shader_type spatial;
// Billboarded health bar over a damaged structure: fills from the left by `fill`, green at full
// through yellow to red, on a dark backing. Drawn over the scene so the structure can't hide it.
render_mode unshaded, cull_disabled, depth_test_disabled, shadows_disabled;
uniform float fill : hint_range(0.0, 1.0) = 1.0;
void vertex() {
MODELVIEW_MATRIX = VIEW_MATRIX * mat4(INV_VIEW_MATRIX[0], INV_VIEW_MATRIX[1], INV_VIEW_MATRIX[2], MODEL_MATRIX[3]);
}
void fragment() {
vec2 p = UV;
float edge = 0.08;
bool border = p.x < edge * 0.25 || p.x > 1.0 - edge * 0.25 || p.y < edge || p.y > 1.0 - edge;
vec3 good = vec3(0.4, 0.9, 0.3);
vec3 mid = vec3(1.0, 0.8, 0.2);
vec3 bad = vec3(1.0, 0.25, 0.15);
vec3 bar = fill > 0.5 ? mix(mid, good, (fill - 0.5) * 2.0) : mix(bad, mid, fill * 2.0);
vec3 col = border ? vec3(0.02) : (p.x <= fill ? bar : vec3(0.12));
ALBEDO = col;
ALPHA = 0.95;
}