export const VERTEX_SHADER = /* glsl */ ` uniform float uTime, uMix, uPx, uVel, uDim, uHA, uHB, uBrain, uGal, uZoomA, uSpinB; uniform vec2 uMouse; uniform vec3 uHintA, uHintB, uOffA, uOffB; uniform mat3 uRot; attribute vec3 aFrom, aTo; attribute vec4 aRand; attribute float aAmb; attribute vec2 aShade; varying vec3 vColor; varying float vAlpha; varying float vRot; vec3 spinY(vec3 p, float a) { float c = cos(a), s = sin(a); return vec3(p.x * c + p.z * s, p.y, -p.x * s + p.z * c); } void main() { float m = uMix, body = 1.0 - aAmb; vec3 p = aFrom; if (aAmb < 0.5) { // shapes are built around their own centre: rotate in place, then move to the section's spot vec3 local = mix(aFrom * uZoomA, spinY(aTo, uSpinB), m); p = uRot * local + mix(uOffA, uOffB, m); } // between sections the particles burst out toward the viewer, swirl, then settle into the next shape float burst = pow(sin(m * 3.14159), 1.25) * body; vec3 dir = normalize(vec3(aRand.x - 0.5, aRand.y - 0.5, aRand.z - 0.5) + 0.0001); float sw = burst * (aRand.y - 0.5) * 2.4, cs = cos(sw), sn = sin(sw); vec2 fl = vec2(dir.x * cs - dir.y * sn, dir.x * sn + dir.y * cs); p += vec3(fl * (1.7 + aRand.w * 4.2), 0.55 + aRand.w * 3.6) * burst; float t = uTime * (0.25 + aRand.y * 0.5); p += vec3(sin(t + aRand.z * 20.0), cos(t * 1.3 + aRand.x * 20.0), sin(t * 0.7 + aRand.w * 20.0)) * (0.018 + aAmb * 0.4 + uVel * 0.18); vec4 wp = modelMatrix * vec4(p, 1.0); vec2 d = wp.xy - uMouse; float L = length(d); if (L < 1.4) wp.xy += normalize(d + 0.0001) * pow(1.0 - L / 1.4, 2.0) * (1.0 - aAmb * 0.6); vec4 mv = viewMatrix * wp; gl_Position = projectionMatrix * mv; float sz = (0.55 + aRand.w * 0.95) * uPx * (12.0 / -mv.z) * (1.0 + burst * 0.3); sz *= mix(1.0, 0.78, uBrain * body) * mix(1.0, 0.55 + aShade.y * 0.6, uGal * body); gl_PointSize = min(sz, uPx * 3.6); // blue-to-white blend: deep blue, brand blue, ice, white float g = clamp(0.48 + p.y * 0.09 + p.z * 0.06 + (aRand.y - 0.5) * 0.85, 0.0, 1.0); g = mix(g, clamp(0.02 + aShade.x * 0.86 + p.y * 0.04 + (aRand.y - 0.5) * 0.22, 0.0, 1.0), uBrain * body); g = mix(g, clamp(0.04 + aShade.y * 0.96 + (aRand.y - 0.5) * 0.14, 0.0, 1.0), uGal * body); vec3 deep = vec3(0.07, 0.24, 0.62), brand = vec3(0.275, 0.667, 0.914), ice = vec3(0.75, 0.89, 0.98); vec3 col = g < 0.4 ? mix(deep, brand, g / 0.4) : (g < 0.78 ? mix(brand, ice, (g - 0.4) / 0.38) : mix(ice, vec3(1.0), (g - 0.78) / 0.22)); float hint = mix(uHA, uHB, m) * step(0.72, aRand.z) * body; col = mix(col, mix(uHintA, uHintB, m), hint); if (aAmb > 0.5 && aRand.x > 0.93) col = aRand.w > 0.5 ? vec3(1.0) : vec3(0.75, 0.89, 0.98); vColor = col; float tw = 0.62 + 0.38 * sin(uTime * (0.7 + aRand.y * 2.2) + aRand.x * 40.0); vAlpha = tw * mix(0.6, 0.42, aAmb) * uDim * mix(1.0, 0.5, burst); // the far side of the brain fades so the folds facing you read clearly vAlpha *= mix(1.0, mix(1.0, 0.14, clamp((-mv.z - 11.6) / 2.4, 0.0, 1.0)), uBrain * body); vAlpha *= mix(1.0, 0.3 + aShade.y * 0.7, uGal * body); vRot = aRand.x * 6.2832 + uTime * (aRand.z - 0.5) * 1.4; }`; // Each point is drawn as a rotating outlined triangle export const FRAGMENT_SHADER = /* glsl */ ` varying vec3 vColor; varying float vAlpha; varying float vRot; float sdTri(vec2 p, float r) { const float k = 1.7320508; p.x = abs(p.x) - r; p.y = p.y + r / k; if (p.x + k * p.y > 0.0) p = vec2(p.x - k * p.y, -k * p.x - p.y) / 2.0; p.x -= clamp(p.x, -2.0 * r, 0.0); return -length(p) * sign(p.y); } void main() { vec2 p = gl_PointCoord * 2.0 - 1.0; p.y = -p.y; float c = cos(vRot), s = sin(vRot); p = mat2(c, -s, s, c) * p; float d = sdTri(p, 0.62); float a = 1.0 - smoothstep(0.05, 0.19, abs(d)); if (a < 0.02) discard; gl_FragColor = vec4(vColor, a * vAlpha); }`;