Glitch Shader in WebGL

HTML

<link href="https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap" rel="stylesheet">

<a href="#">
  <canvas></canvas>
  <span>Get in touch</span>
</a>

CSS

canvas {
  display: block;
  box-shadow: 0 10px 20px -9px #00000090;
  width: 100%;
  height: 100%;
  border-radius: 50px;
  overlay: hidden;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  border: solid 1px #ffffff15;
}

a {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 400px;
  height: 90px;
  position: relative;
  text-decoration: none;
}

span {
  position: relative;
  z-index: 10;
  color: #fff;
  font-weight: 700;
  font-size: 1.2em;
  text-shadow: 0 2px 7px #000;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #101010;
  font-family: "Inter";
}

JavaScript

const canvas = document.querySelector('canvas');
const gl = canvas.getContext('webgl2'); // Use webgl2 for GLSL ES 3.00

if (!gl) {
  alert('Unable to initialize WebGL. Your browser or machine may not support it.');
}

// Vertex shader source
const vsSource = `#version 300 es
  in vec4 a_position;
  out vec2 v_uv;

  void main() {
    gl_Position = a_position;
    // Map clip space (-1 to 1) to UV space (0 to 1)
    v_uv = (a_position.xy * 0.5) + 0.5;
  }
`;

// Fragment shader source (translated from Swift Metal)
const fsSource = `#version 300 es
  precision highp float;

  in vec2 v_uv;
  out vec4 fragColor;

  uniform float u_time;
  uniform float u_tapValue;
  uniform vec2 u_resolution;
  uniform float u_aspectRatio;
  uniform float u_verticalOffset;
  uniform float u_patternZoom; // NEW: Pattern Zoom uniform

  // Helper functions
  float hash(float n) {
    return fract(sin(n) * 753.5453123);
  }

  float noise(vec2 x) {
    vec2 p = floor(x);
    vec2 f = fract(x);
    f = f * f * (3.0 - 2.0 * f);

    float n = p.x + p.y * 157.0;
    return mix(
      mix(hash(n + 0.0), hash(n + 1.0), f.x),
      mix(hash(n + 157.0), hash(n + 158.0), f.x),
      f.y
    );
  }

  float fbm(vec2 p, vec3 a) {
    float v = 0.0;
    v += noise(p * a.x) * 0.50 ;
    v += noise(p * a.y) * 1.50 ;
    v += noise(p * a.z) * 0.125 * 0.1; // variable
    return v;
  }

  vec3 drawLines(
    vec2 uv,
    vec3 fbmOffset,
    vec3 color1,
    vec3 colorSet[4], // GLSL requires size for arrays in parameters
    float secs
  ) {
    float timeVal = secs * 0.1;
    vec3 finalColor = vec3(0.0);

    for (int i = 0; i < 4; ++i) {
      float indexAsFloat = float(i);
      float amp = 80.0 + (indexAsFloat * 0.0);
      float period = 2.0 + (indexAsFloat + 2.0);
      float thickness = mix(0.4, 0.2, noise(uv * 2.0));

      float t = abs(1.0 / (sin(uv.y + fbm(uv + timeVal * period, fbmOffset)) * amp) * thickness);

...