declare const _default: "#version 300 es\n\nprecision highp float;\n\nuniform sampler2D uState;\nuniform sampler2D uFixed;\nuniform sampler2D uTreeData;\nuniform sampler2D uTreeChildren;\nuniform sampler2D uTreeGeometry;\nuniform sampler2D uAdjOffsets;\nuniform sampler2D uAdjEdges;\n\nuniform int uNodeCount;\nuniform int uTexWidth;\nuniform float uAlpha;\nuniform float uDamping;\n\nuniform float uManyBodyStrength;\nuniform float uTheta2;\nuniform float uDistanceMin2;\nuniform float uDistanceMax2;\nuniform int uTreeNodeCount;\nuniform int uTreeTexWidth;\n\nuniform int uAdjOffsetsTexWidth;\nuniform int uAdjEdgesTexWidth;\n\nuniform vec2 uCenter;\nuniform float uCenterStrength;\n\nuniform float uCollisionRadius;\nuniform float uCollisionStrength;\n\nuniform float uForceXTarget;\nuniform float uForceXStrength;\nuniform float uForceYTarget;\nuniform float uForceYStrength;\n\nuniform float uHasManyBody;\nuniform float uHasLinks;\nuniform float uHasCentering;\nuniform float uHasCollision;\nuniform float uHasPositioning;\n\nout vec4 fragColor;\n\nivec2 texCoord(int idx, int tw) {\n return ivec2(idx % tw, idx / tw);\n}\n\nvoid main() {\n ivec2 fc = ivec2(gl_FragCoord.xy);\n int nodeId = fc.y * uTexWidth + fc.x;\n\n if (nodeId >= uNodeCount) {\n fragColor = vec4(0.0);\n return;\n }\n\n vec4 fixedData = texelFetch(uFixed, fc, 0);\n if (fixedData.x > 0.5) {\n fragColor = vec4(fixedData.yz, 0.0, 0.0);\n return;\n }\n\n vec4 state = texelFetch(uState, fc, 0);\n vec2 pos = state.xy;\n vec2 vel = state.zw;\n\n if (uHasManyBody > 0.5 && uTreeNodeCount > 0) {\n int stack[128];\n int top = 0;\n stack[top++] = 0;\n\n while (top > 0) {\n int idx = stack[--top];\n vec4 data = texelFetch(uTreeData, texCoord(idx, uTreeTexWidth), 0);\n float w = data.w;\n\n if (w < -0.5) {\n int bodyIdx = int(-w - 0.5);\n if (bodyIdx != nodeId) {\n vec2 delta = data.xy - pos;\n float distSq = dot(delta, delta);\n\n if (distSq < 1e-8) {\n delta = vec2(float(nodeId) * 1e-4 - float(bodyIdx) * 1e-4 + 1e-4, 1e-4);\n distSq = dot(delta, delta);\n }\n\n if (distSq < uDistanceMax2) {\n float l = distSq;\n if (l < uDistanceMin2) l = sqrt(uDistanceMin2 * l);\n vel += delta * (data.z * uAlpha / max(l, 1e-6));\n }\n }\n } else {\n vec2 delta = data.xy - pos;\n float distSq = dot(delta, delta);\n\n if (distSq > 0.0 && w * w / distSq < uTheta2) {\n if (distSq < uDistanceMax2) {\n float l = distSq;\n if (l < uDistanceMin2) l = sqrt(uDistanceMin2 * l);\n vel += delta * (data.z * uAlpha / max(l, 1e-6));\n }\n } else {\n vec4 ch = texelFetch(uTreeChildren, texCoord(idx, uTreeTexWidth), 0);\n if (ch.w >= 0.0 && top < 64) stack[top++] = int(ch.w + 0.5);\n if (ch.z >= 0.0 && top < 64) stack[top++] = int(ch.z + 0.5);\n if (ch.y >= 0.0 && top < 64) stack[top++] = int(ch.y + 0.5);\n if (ch.x >= 0.0 && top < 64) stack[top++] = int(ch.x + 0.5);\n }\n }\n }\n }\n\n if (uHasCollision > 0.5 && uCollisionRadius > 0.0 && uTreeNodeCount > 0) {\n float collisionDiam = uCollisionRadius * 2.0;\n vec2 predictedPos = state.xy + state.zw;\n int stack[64];\n int top = 0;\n stack[top++] = 0;\n\n while (top > 0) {\n int idx = stack[--top];\n vec4 data = texelFetch(uTreeData, texCoord(idx, uTreeTexWidth), 0);\n float w = data.w;\n\n if (w < -0.5) {\n int bodyIdx = int(-w - 0.5);\n if (bodyIdx != nodeId && bodyIdx < uNodeCount) {\n vec2 delta = data.xy - predictedPos;\n float dist = length(delta);\n\n if (dist < collisionDiam && dist > 0.0) {\n float push = (collisionDiam - dist) * uCollisionStrength;\n vel -= (delta / dist) * push * 0.5;\n }\n }\n } else {\n vec4 geo = texelFetch(uTreeGeometry, texCoord(idx, uTreeTexWidth), 0);\n float cellSize = geo.z;\n vec2 nearest = clamp(predictedPos, geo.xy, geo.xy + cellSize);\n float distToCell = length(nearest - predictedPos);\n\n if (distToCell < collisionDiam) {\n vec4 ch = texelFetch(uTreeChildren, texCoord(idx, uTreeTexWidth), 0);\n if (ch.w >= 0.0 && top < 64) stack[top++] = int(ch.w + 0.5);\n if (ch.z >= 0.0 && top < 64) stack[top++] = int(ch.z + 0.5);\n if (ch.y >= 0.0 && top < 64) stack[top++] = int(ch.y + 0.5);\n if (ch.x >= 0.0 && top < 64) stack[top++] = int(ch.x + 0.5);\n }\n }\n }\n }\n\n if (uHasLinks > 0.5) {\n vec4 offData = texelFetch(uAdjOffsets, texCoord(nodeId, uAdjOffsetsTexWidth), 0);\n int start = int(offData.x + 0.5);\n int count = int(offData.y + 0.5);\n\n for (int e = 0; e < count; e++) {\n vec4 edgeData = texelFetch(uAdjEdges, texCoord(start + e, uAdjEdgesTexWidth), 0);\n int targetId = int(edgeData.x + 0.5);\n float restDist = edgeData.y;\n float strength = edgeData.z;\n float dirBias = edgeData.w;\n\n vec4 targetState = texelFetch(uState, texCoord(targetId, uTexWidth), 0);\n vec2 delta = (targetState.xy + targetState.zw) - (state.xy + state.zw);\n float d = length(delta);\n\n if (d < 1e-6) {\n delta = vec2(1e-3, 1e-3);\n d = length(delta);\n }\n\n float scale = (d - restDist) / d * uAlpha * strength;\n vel += delta * scale * dirBias;\n }\n }\n\n if (uHasCentering > 0.5) {\n vel += (uCenter - pos) * uCenterStrength * uAlpha;\n }\n\n if (uHasPositioning > 0.5) {\n vel.x += (uForceXTarget - pos.x) * uForceXStrength * uAlpha;\n vel.y += (uForceYTarget - pos.y) * uForceYStrength * uAlpha;\n }\n\n vel *= uDamping;\n pos += vel;\n\n fragColor = vec4(pos, vel);\n}\n"; export default _default;