// 思维流体 GLSL —— Ashima simplex noise + 3 octave FBM + Fresnel const SIMPLEX = /* glsl */ ` vec3 mod289(vec3 x){ return x - floor(x * (1.0/289.0)) * 289.0; } vec4 mod289(vec4 x){ return x - floor(x * (1.0/289.0)) * 289.0; } vec4 permute(vec4 x){ return mod289(((x*34.0)+1.0)*x); } vec4 taylorInvSqrt(vec4 r){ return 1.79284291400159 - 0.85373472095314 * r; } float snoise(vec3 v){ const vec2 C = vec2(1.0/6.0, 1.0/3.0); const vec4 D = vec4(0.0, 0.5, 1.0, 2.0); vec3 i = floor(v + dot(v, C.yyy)); vec3 x0 = v - i + dot(i, C.xxx); vec3 g = step(x0.yzx, x0.xyz); vec3 l = 1.0 - g; vec3 i1 = min(g.xyz, l.zxy); vec3 i2 = max(g.xyz, l.zxy); vec3 x1 = x0 - i1 + C.xxx; vec3 x2 = x0 - i2 + C.yyy; vec3 x3 = x0 - D.yyy; i = mod289(i); vec4 p = permute(permute(permute( i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0)) + i.x + vec4(0.0, i1.x, i2.x, 1.0)); float n_ = 0.142857142857; vec3 ns = n_ * D.wyz - D.xzx; vec4 j = p - 49.0 * floor(p * ns.z * ns.z); vec4 x_ = floor(j * ns.z); vec4 y_ = floor(j - 7.0 * x_); vec4 x = x_ * ns.x + ns.yyyy; vec4 y = y_ * ns.x + ns.yyyy; vec4 h = 1.0 - abs(x) - abs(y); vec4 b0 = vec4(x.xy, y.xy); vec4 b1 = vec4(x.zw, y.zw); vec4 s0 = floor(b0) * 2.0 + 1.0; vec4 s1 = floor(b1) * 2.0 + 1.0; vec4 sh = -step(h, vec4(0.0)); vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy; vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww; vec3 p0 = vec3(a0.xy, h.x); vec3 p1 = vec3(a0.zw, h.y); vec3 p2 = vec3(a1.xy, h.z); vec3 p3 = vec3(a1.zw, h.w); vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2,p2), dot(p3,p3))); p0 *= norm.x; p1 *= norm.y; p2 *= norm.z; p3 *= norm.w; vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0); m = m * m; return 42.0 * dot(m*m, vec4(dot(p0,x0), dot(p1,x1), dot(p2,x2), dot(p3,x3))); } float fbm(vec3 p){ float sum = 0.0; float amp = 0.5; for (int i = 0; i < 3; i++) { sum += amp * snoise(p); p *= 2.1; amp *= 0.5; } return sum; } `; export const blobVertex = /* glsl */ ` uniform float uTime; uniform float uFreq; uniform float uAmp; uniform float uSpeed; varying float vDisp; varying vec3 vNormal; varying vec3 vViewDir; ${SIMPLEX} void main(){ float t = uTime * uSpeed; float d = fbm(normal * uFreq + vec3(t, t * 0.7, -t * 0.4)); vDisp = d; vec3 displaced = position + normal * d * uAmp; vec4 mvPosition = modelViewMatrix * vec4(displaced, 1.0); vNormal = normalize(normalMatrix * normal); vViewDir = normalize(-mvPosition.xyz); gl_Position = projectionMatrix * mvPosition; } `; export const blobFragment = /* glsl */ ` uniform vec3 uColorA; uniform vec3 uColorB; uniform float uHeat; uniform float uOpacity; varying float vDisp; varying vec3 vNormal; varying vec3 vViewDir; void main(){ float fresnel = pow(1.0 - max(dot(vNormal, vViewDir), 0.0), 2.4); vec3 base = mix(uColorA, uColorB, vDisp * 0.5 + 0.5); base = mix(base, vec3(1.0, 0.62, 0.38), uHeat * 0.4); vec3 color = base * (0.32 + fresnel * 1.6) + base * smoothstep(0.35, 0.9, vDisp) * 0.45; float alpha = (0.22 + fresnel * 0.85) * uOpacity; gl_FragColor = vec4(color, alpha); } `; export const particleVertex = /* glsl */ ` uniform float uTime; uniform float uAttract; // 1 = 吸入核心 (thinking) uniform float uBurst; // 1 = 向外喷发 (answering) uniform float uDir; // 喷发的水平方向(指向内容区) uniform float uSize; uniform vec3 uMouse; // 指针在粒子局部空间的位置 uniform float uMouseForce; uniform float uGrab; // 按压牵引强度(弹簧驱动,可为负 → 回弹散开) attribute vec3 aSeed; // 每粒子随机种子 attribute float aRadius; attribute float aSpeed; varying float vFade; void main(){ float t = uTime * aSpeed; // 进动轨道:两组相位叠加,避免规则圆轨 float theta = aSeed.x * 6.2831 + t; float phi = aSeed.y * 3.1415 + sin(t * 0.6 + aSeed.z * 6.2831) * 0.7; float r = aRadius * mix(1.0, 0.3, uAttract); r += uBurst * (0.8 + aSeed.z * 2.6); vec3 pos = vec3( cos(theta) * sin(phi) * r, cos(phi) * r * 0.85, sin(theta) * sin(phi) * r ); // 喷发时整体偏向内容区一侧 pos.x += uBurst * uDir * (0.6 + aSeed.y * 1.8); // 鼠标牵引:靠近指针的粒子被吸过去,绕指针形成小漩涡 float md = distance(pos, uMouse); float pull = smoothstep(2.8, 0.2, md) * uMouseForce * (0.35 + aSeed.z * 0.65); vec3 swirl = vec3( sin(t * 2.2 + aSeed.x * 6.2831), cos(t * 1.7 + aSeed.y * 6.2831), sin(t * 1.3 + aSeed.z * 6.2831) ) * (0.12 + aSeed.y * 0.3); pos = mix(pos, uMouse + swirl, pull); // 按住鼠标:全体粒子被牵向按压点,逐粒错相往复脉动; // uGrab 为负(松开回弹)时 mix 外推 → 粒子向外散开再被拉回 float osc = 0.55 + 0.45 * sin(uTime * (1.2 + aSeed.x * 1.6) + aSeed.y * 6.2831); float gpull = clamp(uGrab, -0.35, 1.25) * osc * (0.5 + aSeed.z * 0.5); gpull = clamp(gpull, -0.4, 0.96); vec3 gswirl = vec3( sin(t * 1.8 + aSeed.y * 6.2831), cos(t * 1.4 + aSeed.z * 6.2831), sin(t * 1.1 + aSeed.x * 6.2831) ) * (0.18 + aSeed.x * 0.5); pos = mix(pos, uMouse + gswirl, gpull); vFade = 1.0 - uBurst * aSeed.z * 0.9; vFade = min(vFade + pull * 0.5 + max(gpull, 0.0) * 0.35, 1.2); vec4 mvPosition = modelViewMatrix * vec4(pos, 1.0); gl_PointSize = uSize * (0.6 + aSeed.z) * (1.0 + pull * 0.5 + max(gpull, 0.0) * 0.3) * (3.4 / -mvPosition.z); gl_Position = projectionMatrix * mvPosition; } `; export const particleFragment = /* glsl */ ` uniform vec3 uColorA; uniform vec3 uColorB; uniform float uHeat; uniform float uOpacity; varying float vFade; void main(){ vec2 uv = gl_PointCoord - 0.5; float d = length(uv); float mask = smoothstep(0.5, 0.05, d); vec3 color = mix(uColorA, uColorB, vFade); color = mix(color, vec3(1.0, 0.62, 0.38), uHeat * 0.35); gl_FragColor = vec4(color, mask * vFade * 0.75 * uOpacity); } `;