hex shader: rainbow shimmer on edges when wave passes
This commit is contained in:
parent
207e61ca52
commit
c2112bb451
1 changed files with 23 additions and 1 deletions
|
|
@ -22,6 +22,11 @@ float sdHexagon(vec2 p, float r) {
|
||||||
return length(p) * sign(p.y);
|
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() {
|
void main() {
|
||||||
vec2 res = uResolution.xy;
|
vec2 res = uResolution.xy;
|
||||||
vec2 frag = qt_TexCoord0 * res;
|
vec2 frag = qt_TexCoord0 * res;
|
||||||
|
|
@ -43,6 +48,7 @@ void main() {
|
||||||
|
|
||||||
vec2 p = frag - center;
|
vec2 p = frag - center;
|
||||||
float d = sdHexagon(p.yx, inradius); // swap for flat-top
|
float d = sdHexagon(p.yx, inradius); // swap for flat-top
|
||||||
|
|
||||||
if (d > 0.0) {
|
if (d > 0.0) {
|
||||||
fragColor = vec4(0.0);
|
fragColor = vec4(0.0);
|
||||||
return;
|
return;
|
||||||
|
|
@ -63,7 +69,23 @@ void main() {
|
||||||
rgb = min(rgb + vec3(0.3 * wf), vec3(1.0));
|
rgb = min(rgb + vec3(0.3 * wf), vec3(1.0));
|
||||||
a += 0.12 * wf;
|
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);
|
float aa = 1.0 - smoothstep(-1.0, 0.0, d);
|
||||||
a *= aa;
|
a *= aa;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue