#version 440 // Hold-to-confirm fill (HoldFill.qml): accent liquid rises inside a rounded // shape while a button is held, with a wavy surface, a paler back wave and a // lit meniscus. The glyph texture is inked in the accent text colour where the // liquid covers it. Output is premultiplied. // Rebuild holdfill.frag.qsb with scripts/build-shaders after editing. layout(location = 0) in vec2 qt_TexCoord0; layout(location = 0) out vec4 fragColor; layout(std140, binding = 0) uniform buf { mat4 qt_Matrix; float qt_Opacity; vec2 size; // item size, px float radius; // corner radius, px float level; // 0 empty .. 1 full float time; // seconds, drives the waves float slosh; // wave amplitude, px vec4 fill; // premultiplied liquid colour vec4 ink; // premultiplied glyph colour under the liquid }; layout(binding = 1) uniform sampler2D glyph; float sdBox(vec2 p, vec2 h, float r) { r = min(r, min(h.x, h.y)); vec2 q = abs(p) - h + r; return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - r; } void main() { vec2 p = qt_TexCoord0 * size; float shape = clamp(0.5 - sdBox(p - size * 0.5, size * 0.5, radius), 0.0, 1.0); if (shape <= 0.0 || level <= 0.0) { fragColor = vec4(0.0); return; } // Waves calm down at the very bottom and top so it starts and ends flat. float amp = slosh * smoothstep(0.0, 0.18, level) * (1.0 - smoothstep(0.82, 1.0, level)); float x = p.x / max(size.x, 1.0) * 6.2831853; float base = mix(size.y + amp * 2.0, -amp * 2.0, level); float front = base + amp * (sin(x * 1.3 + time * 4.2) * 0.65 + sin(x * 2.1 - time * 2.9) * 0.35); float back = base - amp * 0.6 + amp * sin(x * 1.1 - time * 3.4 + 1.7); float aFront = clamp(p.y - front + 0.5, 0.0, 1.0); float aBack = clamp(p.y - back + 0.5, 0.0, 1.0) * 0.42; // Deeper liquid is a touch darker; a bright band sits under the surface. float depth = clamp((p.y - front) / max(size.y, 1.0), 0.0, 1.0); vec3 col = fill.rgb * (1.0 - 0.16 * depth); float meniscus = exp(-max(p.y - front, 0.0) / 1.6) * aFront; col = mix(col, vec3(fill.a), 0.28 * meniscus); vec4 c = vec4(fill.rgb, fill.a) * aBack; c = c * (1.0 - aFront) + vec4(col, fill.a) * aFront; float g = texture(glyph, qt_TexCoord0).a * aFront; c = c * (1.0 - g * ink.a) + ink * g; fragColor = c * shape * qt_Opacity; }