/** * Copyright (c) 2026 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose */ export declare const common_animation = "\nuniform float uWiggleSpeed;\nuniform float uWiggleAmplitude;\nuniform float uWiggleFrequency;\nuniform int uWiggleMode;\nuniform float uTumbleSpeed;\nuniform float uTumbleAmplitude;\nuniform float uTumbleFrequency;\n\n#ifdef dWiggle\n uniform vec2 uWiggleTexDim;\n uniform sampler2D tWiggle;\n uniform float uWiggleStrength;\n#endif\n\nvec3 applyWiggle(vec3 pos, float groupId, float instanceId) {\n if (!uEnableAnimation) return pos;\n float amplitude = uWiggleAmplitude;\n #ifdef dWiggle\n #if defined(dWiggleType_instance)\n amplitude += readFromTexture(tWiggle, instanceId, uWiggleTexDim).a * uWiggleStrength;\n #elif defined(dWiggleType_groupInstance)\n amplitude += readFromTexture(tWiggle, groupInstanceIndex(instanceId, groupId), uWiggleTexDim).a * uWiggleStrength;\n #endif\n #endif\n if (amplitude > 0.0 && uWiggleSpeed > 0.0 && uWiggleFrequency > 0.0) {\n float t = uTime * uWiggleSpeed;\n vec3 s;\n if (uWiggleMode == 0) {\n // Position mode: spatial position correlates nearby atoms\n s = pos;\n } else {\n // Group mode: per-group independent noise\n // Hash groupId into a well-distributed 3D seed to avoid repetition\n s = vec3(\n fract(sin(groupId * 127.1) * 43758.5453) * 1000.0,\n fract(sin(groupId * 269.5) * 21639.7182) * 1000.0,\n fract(sin(groupId * 419.2) * 32517.3926) * 1000.0\n );\n }\n s *= uWiggleFrequency;\n pos.x += (fbm(vec3(s.x, s.y + t, s.z)) / 0.4375 - 1.0) * amplitude;\n pos.y += (fbm(vec3(s.x + 37.0, s.y, s.z + t)) / 0.4375 - 1.0) * amplitude;\n pos.z += (fbm(vec3(s.x + t, s.y + 73.0, s.z)) / 0.4375 - 1.0) * amplitude;\n }\n return pos;\n}\n\nmat4 applyTumble(mat4 transform, float instanceIndex, float objectId) {\n if (!uEnableAnimation) return transform;\n if (uTumbleAmplitude > 0.0 && uTumbleSpeed > 0.0 && uTumbleFrequency > 0.0) {\n // Scale amplitude inversely with bounding-sphere radius (Stokes-Einstein: D ~ 1/r)\n float amplitude = uTumbleAmplitude / max(InvariantBoundingSphere.w, 1.0);\n float t = uTime * uTumbleSpeed;\n float seed = (instanceIndex * 127.1 + objectId * 311.7) * uTumbleFrequency;\n\n // Per-instance rotation angles from layered noise (Brownian-like)\n float angleX = (fbm(vec3(seed, t, 0.0)) / 0.4375 - 1.0) * amplitude;\n float angleY = (fbm(vec3(seed, 0.0, t)) / 0.4375 - 1.0) * amplitude;\n float angleZ = (fbm(vec3(0.0, seed, t)) / 0.4375 - 1.0) * amplitude;\n\n float cx = cos(angleX); float sx = sin(angleX);\n float cy = cos(angleY); float sy = sin(angleY);\n float cz = cos(angleZ); float sz = sin(angleZ);\n\n // Combined rotation matrix (Rz * Ry * Rx)\n mat3 rot = mat3(\n cy * cz, cx * sz + sx * sy * cz, sx * sz - cx * sy * cz,\n -cy * sz, cx * cz - sx * sy * sz, sx * cz + cx * sy * sz,\n sy, -sx * cy, cx * cy\n );\n\n // Per-instance translation offset from layered noise (Brownian-like)\n vec3 offset = vec3(\n (fbm(vec3(seed + 31.7, t, 0.0)) / 0.4375 - 1.0),\n (fbm(vec3(seed + 31.7, 0.0, t)) / 0.4375 - 1.0),\n (fbm(vec3(0.0, seed + 31.7, t)) / 0.4375 - 1.0)\n ) * amplitude;\n\n // Bounding-sphere center transformed by the linear part only (no translation)\n vec3 localCenter = mat3(transform) * InvariantBoundingSphere.xyz;\n\n // Rotate basis vectors\n mat4 result = transform;\n result[0].xyz = rot * transform[0].xyz;\n result[1].xyz = rot * transform[1].xyz;\n result[2].xyz = rot * transform[2].xyz;\n\n // Adjust translation so rotation pivots around the transformed center\n result[3].xyz = transform[3].xyz + localCenter - rot * localCenter + offset;\n\n return result;\n }\n return transform;\n}\n";