hex shader: rainbow shimmer on edges when wave passes

This commit is contained in:
Damocles 2026-04-13 10:52:32 +02:00
parent 207e61ca52
commit c2112bb451

View file

@ -22,6 +22,11 @@ float sdHexagon(vec2 p, float r) {
return length(p) * sign(p.y);
}
// Rainbow from angle — color picker style
vec3 hsv2rgb(float h) {
return clamp(abs(mod(h * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0);
}
void main() {
vec2 res = uResolution.xy;
vec2 frag = qt_TexCoord0 * res;
@ -43,6 +48,7 @@ void main() {
vec2 p = frag - center;
float d = sdHexagon(p.yx, inradius); // swap for flat-top
if (d > 0.0) {
fragColor = vec4(0.0);
return;
@ -63,7 +69,23 @@ void main() {
rgb = min(rgb + vec3(0.3 * wf), vec3(1.0));
a += 0.12 * wf;
// Anti-alias
// Rainbow shimmer on hex edges when wave passes
float edgeWidth = 2.0;
float edgeFactor = smoothstep(-edgeWidth, 0.0, d); // 0 at interior, 1 at edge
if (wf > 0.01 && edgeFactor > 0.0) {
// Angle around hex center → hue
float angle = atan(p.y, p.x);
float hue = (angle + 3.14159) / 6.28318;
// Shift hue by position so neighboring hexes have different phase
hue = fract(hue + center.x * 0.003 + center.y * 0.005);
vec3 rainbow = hsv2rgb(hue);
float shimmer = edgeFactor * wf;
rgb = mix(rgb, rainbow, shimmer * 0.8);
a = mix(a, 0.5, shimmer * 0.6);
}
// Anti-alias outer edge
float aa = 1.0 - smoothstep(-1.0, 0.0, d);
a *= aa;