Table 3: Spring Force Calculate Compute Shader

Input SSBO Pos, Vel, Spring
output SSBO Force
1 BEGINID = gl_GlobalInvocationlD.xNode1 = Spring [ID] index1Node2 = Spring[ID].index2Dstlndex1 = Node2 * Maxlnput1 + Node1Dstlndex2 = Node1 * Maxlnput1 + Node2
2 len = sqrt(PDir.x^2 + PDir.y^2 + PDir.z^2)
3 Stiffness = Ks * (len - RestLength)Damping = Dot(VDir, Pdir) / len * Kd
4 SpringForce = Stiffness + DampingSpringForce *= PDir / len
5 Force[DstIndex1] = SpringForce[DstIndex2] = -SpringForceEND