shader step 2: hex grid with gradient colors and wave animation

This commit is contained in:
Damocles 2026-04-13 10:43:44 +02:00
parent 6c33db2a0e
commit 42f861676e
2 changed files with 83 additions and 3 deletions

View file

@ -25,9 +25,31 @@ PanelWindow {
color: M.Theme.base01 color: M.Theme.base01
} }
// Step 1: minimal shader test should show solid red
ShaderEffect { ShaderEffect {
id: fx
anchors.fill: parent anchors.fill: parent
fragmentShader: Quickshell.shellPath("modules/hex_wave.frag.qsb") fragmentShader: Quickshell.shellPath("modules/hex_wave.frag.qsb")
property real uSize: 50.0
property real uWavePhase: -200
property vector4d uResolution: Qt.vector4d(width, height, 0, 0)
property color uC0: M.Theme.base0C
property color uC1: M.Theme.base0E
property color uC2: M.Theme.base09
// Wave animation: 6s sweep + 8s pause
SequentialAnimation on uWavePhase {
loops: Animation.Infinite
running: true
NumberAnimation {
from: -200
to: fx.width + 200
duration: 6000
easing.type: Easing.InOutSine
}
PauseAnimation {
duration: 8000
}
}
} }
} }

View file

@ -6,8 +6,66 @@ layout(location = 0) out vec4 fragColor;
layout(std140, binding = 0) uniform buf { layout(std140, binding = 0) uniform buf {
mat4 qt_Matrix; mat4 qt_Matrix;
float qt_Opacity; float qt_Opacity;
float uSize;
float uWavePhase;
vec4 uResolution;
vec4 uC0;
vec4 uC1;
vec4 uC2;
}; };
void main() { float sdHexFlat(vec2 p, float r) {
fragColor = vec4(1.0, 0.0, 0.0, 0.5) * qt_Opacity; const vec3 k = vec3(0.5, 0.8660254, 0.5773503);
p = abs(p);
p -= 2.0 * min(dot(k.yx, p), 0.0) * k.yx;
p -= vec2(clamp(p.x, -k.z * r, k.z * r), r);
return length(p) * sign(p.y);
}
void main() {
vec2 res = uResolution.xy;
vec2 frag = qt_TexCoord0 * res;
float dx = uSize * 1.5;
float dy = uSize * 1.7320508;
float col = round(frag.x / dx);
float yoff = mod(col, 2.0) != 0.0 ? dy * 0.5 : 0.0;
float row = round((frag.y - yoff) / dy);
vec2 center = vec2(col * dx, row * dy + yoff);
// Wave factor
float dist = center.x - uWavePhase;
float wf = exp(-dist * dist / 9000.0);
float baseR = uSize * 0.48;
float inradius = baseR * (1.0 + 0.35 * wf);
vec2 p = frag - center;
float d = sdHexFlat(p, inradius);
if (d > 0.0) {
fragColor = vec4(0.0);
return;
}
// Gradient color
float fx = clamp(center.x / res.x, 0.0, 1.0);
vec3 rgb = fx < 0.5
? mix(uC0.rgb, uC1.rgb, fx * 2.0)
: mix(uC1.rgb, uC2.rgb, (fx - 0.5) * 2.0);
// Alpha from distance to center
float fy = clamp(center.y / res.y, 0.0, 1.0);
float dc = length(vec2(fx - 0.5, fy - 0.5));
float a = 0.03 + dc * 0.06;
// Wave brighten
rgb = min(rgb + vec3(0.3 * wf), vec3(1.0));
a += 0.12 * wf;
// Anti-alias
float aa = 1.0 - smoothstep(-1.0, 0.0, d);
a *= aa;
fragColor = vec4(rgb * a, a) * qt_Opacity;
} }