60 lines
2 KiB
Text
60 lines
2 KiB
Text
shader_type canvas_item;
|
|
|
|
uniform float fill : hint_range(0.0, 1.0) = 0.0;
|
|
|
|
uniform vec4 liquid_color : source_color = vec4(0.2, 0.5, 0.8, 1.0);
|
|
uniform vec4 bg_color : source_color = vec4(0.08, 0.08, 0.12, 1.0);
|
|
uniform vec4 border_color : source_color = vec4(0.2, 0.2, 0.28, 1.0);
|
|
|
|
uniform float corner_radius : hint_range(0.0, 0.5) = 0.06;
|
|
uniform float border_width : hint_range(0.0, 0.1) = 0.008;
|
|
|
|
uniform float wave_amp : hint_range(0.0, 0.05) = 0.012;
|
|
uniform float wave_freq : hint_range(0.0, 15.0) = 4.0;
|
|
|
|
|
|
float rr_sdf(vec2 p, vec2 half_size, float r) {
|
|
vec2 d = abs(p) - half_size + r;
|
|
return min(max(d.x, d.y), 0.0) + length(max(d, 0.0)) - r;
|
|
}
|
|
|
|
|
|
void fragment() {
|
|
vec2 half_size = vec2(0.5, 0.5);
|
|
vec2 uv_centered = UV - half_size;
|
|
|
|
float max_r = min(corner_radius, half_size.x);
|
|
|
|
// Outer rounded rect
|
|
float outer_d = rr_sdf(uv_centered, half_size, max_r);
|
|
float outer = 1.0 - smoothstep(0.0, max(0.001, fwidth(outer_d)), max(outer_d, 0.0));
|
|
|
|
// Inner (inset by border_width)
|
|
float inner_r = max(0.0, max_r - border_width);
|
|
float inner_hw = max(0.0, half_size.x - border_width);
|
|
float inner_hh = max(0.0, half_size.y - border_width);
|
|
float inner_d = rr_sdf(uv_centered, vec2(inner_hw, inner_hh), inner_r);
|
|
float inner = 1.0 - smoothstep(0.0, max(0.001, fwidth(inner_d)), max(inner_d, 0.0));
|
|
|
|
// Liquid fill with a gentle animated wave at the surface
|
|
float wave = sin(UV.x * wave_freq * 6.283 + TIME * 1.5) * wave_amp;
|
|
float fill_line = fill + wave;
|
|
float liquid = 1.0 - smoothstep(fill_line - 0.001, fill_line + 0.001, UV.y);
|
|
liquid *= inner;
|
|
|
|
// Base background
|
|
vec3 col = bg_color.rgb;
|
|
|
|
// Liquid with subtle depth gradient (lighter near the top)
|
|
vec3 liq = mix(liquid_color.rgb, liquid_color.rgb * 1.35, 1.0 - UV.y * 0.6);
|
|
col = mix(col, liq, liquid);
|
|
|
|
// Surface highlight line
|
|
float surface = smoothstep(fill_line - 0.008, fill_line, UV.y) - smoothstep(fill_line, fill_line + 0.002, UV.y);
|
|
col += surface * vec3(0.3, 0.4, 0.5) * liquid;
|
|
|
|
// Border
|
|
col = mix(col, border_color.rgb, outer - inner);
|
|
|
|
COLOR = vec4(col, outer);
|
|
}
|