3 cbuffer SolvePositionsFromLinksKernelCB : register( b0 )
\r
11 // Node indices for each link
\r
12 StructuredBuffer<int2> g_linksVertexIndices : register( t0 );
\r
14 StructuredBuffer<float> g_linksMassLSC : register( t1 );
\r
15 StructuredBuffer<float> g_linksRestLengthSquared : register( t2 );
\r
16 StructuredBuffer<float> g_verticesInverseMass : register( t3 );
\r
18 RWStructuredBuffer<float4> g_vertexPositions : register( u0 );
\r
20 [numthreads(128, 1, 1)]
\r
22 SolvePositionsFromLinksKernel( uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint GI : SV_GroupIndex )
\r
24 int linkID = DTid.x + startLink;
\r
25 if( DTid.x < numLinks )
\r
27 float massLSC = g_linksMassLSC[linkID];
\r
28 float restLengthSquared = g_linksRestLengthSquared[linkID];
\r
30 if( massLSC > 0.0f )
\r
32 int2 nodeIndices = g_linksVertexIndices[linkID];
\r
33 int node0 = nodeIndices.x;
\r
34 int node1 = nodeIndices.y;
\r
36 float3 position0 = g_vertexPositions[node0].xyz;
\r
37 float3 position1 = g_vertexPositions[node1].xyz;
\r
39 float inverseMass0 = g_verticesInverseMass[node0];
\r
40 float inverseMass1 = g_verticesInverseMass[node1];
\r
42 float3 del = position1 - position0;
\r
43 float len = dot(del, del);
\r
44 float k = ((restLengthSquared - len)/(massLSC*(restLengthSquared+len)))*kst;
\r
45 position0 = position0 - del*(k*inverseMass0);
\r
46 position1 = position1 + del*(k*inverseMass1);
\r
48 g_vertexPositions[node0] = float4(position0, 0.f);
\r
49 g_vertexPositions[node1] = float4(position1, 0.f);
\r