add testing module; integrate holographic effects into vial_fill shader with noise texture, sum-of-sines water surface, top-down lighting, foam line, and font outlines for readability
This commit is contained in:
parent
308cf26a77
commit
7cfbf72ca5
10 changed files with 250 additions and 28 deletions
|
|
@ -1,17 +1,57 @@
|
|||
shader_type canvas_item;
|
||||
|
||||
// --- Fill control ---
|
||||
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 corner_radius : hint_range(0.0, 0.5) = 0.05;
|
||||
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;
|
||||
|
||||
// --- Liquid base color (modulated by effects below) ---
|
||||
uniform vec4 liquid_color : source_color = vec4(0.2, 0.5, 0.8, 1.0);
|
||||
|
||||
// --- Animation controls ---
|
||||
uniform float time_factor : hint_range(0.0, 5.0) = 1.0;
|
||||
uniform float wave_strength : hint_range(0.0, 0.5) = 0.05;
|
||||
uniform float ripple_speed : hint_range(0.0, 5.0) = 1.0;
|
||||
|
||||
// --- Glow / edge ---
|
||||
uniform vec4 edge_color : source_color = vec4(0.3, 0.6, 1.0, 1.0);
|
||||
uniform float glow_intensity : hint_range(0.0, 5.0) = 1.5;
|
||||
uniform float edge_pulse : hint_range(0.0, 2.0) = 1.0;
|
||||
|
||||
// --- Distortion ---
|
||||
uniform sampler2D noise_tex : repeat_enable;
|
||||
uniform float noise_scale : hint_range(0.0, 5.0) = 1.0;
|
||||
uniform float swirl_strength : hint_range(-2.0, 2.0) = 0.5;
|
||||
uniform float hue_shift_speed : hint_range(0.0, 5.0) = 0.0;
|
||||
|
||||
|
||||
// ---------- helpers ----------
|
||||
|
||||
vec3 rgb2hsv(vec3 c) {
|
||||
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
||||
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
|
||||
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
|
||||
float d = q.x - min(q.w, q.y);
|
||||
float e = 1e-10;
|
||||
return vec3(abs((q.w - q.y) / (6.0 * d + e) + q.z), d / (q.x + e), q.x);
|
||||
}
|
||||
|
||||
vec3 hsv2rgb(vec3 c) {
|
||||
vec3 p = abs(fract(c.xxx + vec3(0.0, 1.0 / 3.0, 2.0 / 3.0)) * 6.0 - 3.0);
|
||||
return c.z * mix(vec3(1.0), clamp(p - 1.0, 0.0, 1.0), c.y);
|
||||
}
|
||||
|
||||
vec2 get_swirl_uv(vec2 uv, float strength) {
|
||||
vec2 center = vec2(0.5);
|
||||
vec2 diff = uv - center;
|
||||
float dist = length(diff);
|
||||
float angle = atan(diff.y, diff.x) + strength * (0.5 - dist) * sin(TIME * 0.5);
|
||||
return center + vec2(cos(angle), sin(angle)) * dist;
|
||||
}
|
||||
|
||||
float rr_sdf(vec2 p, vec2 half_size, float r) {
|
||||
vec2 d = abs(p) - half_size + r;
|
||||
|
|
@ -19,42 +59,86 @@ float rr_sdf(vec2 p, vec2 half_size, float r) {
|
|||
}
|
||||
|
||||
|
||||
// ---------- main ----------
|
||||
|
||||
void fragment() {
|
||||
vec2 half_size = vec2(0.5, 0.5);
|
||||
vec2 uv_centered = UV - half_size;
|
||||
float t = TIME * time_factor;
|
||||
|
||||
// --- rounded-rect mask ---
|
||||
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.
|
||||
// UV.y = 0 is top, UV.y = 1 is bottom. fill = 0 → empty, fill = 1 → full.
|
||||
float wave = sin(UV.x * wave_freq * 6.283 + TIME * 1.5) * wave_amp;
|
||||
float fill_line = 1.0 - fill + wave;
|
||||
// --- liquid fill line (sum-of-sines + edge damping) ---
|
||||
float wf = wave_freq * 6.283;
|
||||
float w1 = sin(UV.x * wf + TIME * 5.0);
|
||||
float w2 = sin(UV.x * wf * 1.7 + TIME * 7.0 + 1.3) * 0.5;
|
||||
float w3 = sin(UV.x * wf * 0.6 + TIME * 2.5 + 2.9) * 0.3;
|
||||
float wave_sum = (w1 + w2 + w3) / 1.8;
|
||||
|
||||
// damp wave near left/right walls for meniscus effect
|
||||
float edge_damp = smoothstep(0.0, 0.08, UV.x) * smoothstep(0.0, 0.08, 1.0 - UV.x);
|
||||
wave_sum *= edge_damp;
|
||||
|
||||
float fill_line = 1.0 - fill + wave_sum * wave_amp;
|
||||
float liquid = smoothstep(fill_line - 0.001, fill_line + 0.001, UV.y);
|
||||
liquid *= inner;
|
||||
|
||||
// Base background
|
||||
// --- build effect colour for the liquid region ---
|
||||
vec2 uv = UV;
|
||||
float noise_val = texture(noise_tex, uv * noise_scale + t * 0.05).r;
|
||||
|
||||
// wave distortion
|
||||
uv.y += sin(uv.x * 10.0 + t) * wave_strength * noise_val;
|
||||
uv.x += cos(uv.y * 10.0 + t * 0.5) * wave_strength * noise_val;
|
||||
|
||||
// ripple rings
|
||||
float dist_center = distance(uv, vec2(0.5));
|
||||
uv += sin(dist_center * 20.0 - t * ripple_speed) * (wave_strength * 0.5 * noise_val);
|
||||
|
||||
// swirl
|
||||
uv = get_swirl_uv(uv, swirl_strength);
|
||||
|
||||
// sample the ColorRect texture (water image if assigned, else 1x1 white)
|
||||
vec4 tex = texture(TEXTURE, uv);
|
||||
|
||||
// hue-shift the base liquid colour, modulated by the texture
|
||||
vec3 base_rgb = tex.rgb * liquid_color.rgb;
|
||||
vec3 hsv = rgb2hsv(base_rgb);
|
||||
hsv.x = fract(hsv.x + t * 0.1 * hue_shift_speed);
|
||||
hsv.y = clamp(hsv.y + 0.2 * noise_val, 0.0, 1.0);
|
||||
vec3 effect_rgb = hsv2rgb(hsv);
|
||||
|
||||
// top-down lighting — subtle brightening at the very top
|
||||
float top_light = smoothstep(0.0, 0.3, 1.0 - UV.y);
|
||||
effect_rgb *= 1.0 + top_light * 0.2;
|
||||
|
||||
// overall pulse
|
||||
float pulse = 0.8 + 0.2 * sin(t);
|
||||
effect_rgb *= (glow_intensity * pulse);
|
||||
|
||||
// tiny sparkle
|
||||
effect_rgb += 0.03 * vec3(sin(t * 3.0), cos(t * 2.0), noise_val * 0.1);
|
||||
|
||||
// --- composite ---
|
||||
vec3 col = bg_color.rgb;
|
||||
col = mix(col, effect_rgb, liquid);
|
||||
|
||||
// Liquid with subtle depth gradient
|
||||
vec3 liq = mix(liquid_color.rgb, liquid_color.rgb * 1.35, 1.0 - UV.y);
|
||||
col = mix(col, liq, liquid);
|
||||
// surface foam line (wider glow + bright core)
|
||||
float foam_glow = smoothstep(fill_line - 0.02, fill_line, UV.y) - smoothstep(fill_line, fill_line + 0.004, UV.y);
|
||||
col += foam_glow * vec3(0.5, 0.65, 0.9) * 0.6 * liquid;
|
||||
float foam_core = smoothstep(fill_line - 0.006, fill_line, UV.y) - smoothstep(fill_line, fill_line + 0.001, UV.y);
|
||||
col += foam_core * vec3(0.7, 0.85, 1.0) * liquid;
|
||||
|
||||
// Surface highlight line at the top of the liquid column
|
||||
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
|
||||
// border
|
||||
col = mix(col, border_color.rgb, outer - inner);
|
||||
|
||||
COLOR = vec4(col, outer);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue