From 207e61ca5235cb5975270f782525f8ffbd8e0de2 Mon Sep 17 00:00:00 2001 From: Damocles Date: Mon, 13 Apr 2026 10:47:07 +0200 Subject: [PATCH] fix hex SDF: correct IQ constants, swap coords for flat-top --- modules/hex_wave.frag | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/hex_wave.frag b/modules/hex_wave.frag index bfd884d..f296fc3 100644 --- a/modules/hex_wave.frag +++ b/modules/hex_wave.frag @@ -14,10 +14,10 @@ layout(std140, binding = 0) uniform buf { vec4 uC2; }; -float sdHexFlat(vec2 p, float r) { - const vec3 k = vec3(0.5, 0.8660254, 0.5773503); +float sdHexagon(vec2 p, float r) { + const vec3 k = vec3(-0.866025404, 0.5, 0.577350269); p = abs(p); - p -= 2.0 * min(dot(k.yx, p), 0.0) * k.yx; + p -= 2.0 * min(dot(k.xy, p), 0.0) * k.xy; p -= vec2(clamp(p.x, -k.z * r, k.z * r), r); return length(p) * sign(p.y); } @@ -42,7 +42,7 @@ void main() { float inradius = baseR * (1.0 + 0.35 * wf); vec2 p = frag - center; - float d = sdHexFlat(p, inradius); + float d = sdHexagon(p.yx, inradius); // swap for flat-top if (d > 0.0) { fragColor = vec4(0.0); return;