3 cbuffer VSolveLinksCB : register( b0 )
\r
11 // Node indices for each link
\r
12 StructuredBuffer<int2> g_linksVertexIndices : register( t0 );
\r
14 StructuredBuffer<float> g_linksLengthRatio : register( t1 );
\r
15 StructuredBuffer<float4> g_linksCurrentLength : register( t2 );
\r
16 StructuredBuffer<float> g_vertexInverseMass : register( t3 );
\r
18 RWStructuredBuffer<float4> g_vertexVelocity : register( u0 );
\r
20 [numthreads(128, 1, 1)]
\r
22 VSolveLinksKernel( 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 int2 nodeIndices = g_linksVertexIndices[linkID];
\r
28 int node0 = nodeIndices.x;
\r
29 int node1 = nodeIndices.y;
\r
31 float linkLengthRatio = g_linksLengthRatio[linkID];
\r
32 float3 linkCurrentLength = g_linksCurrentLength[linkID].xyz;
\r
34 float3 vertexVelocity0 = g_vertexVelocity[node0].xyz;
\r
35 float3 vertexVelocity1 = g_vertexVelocity[node1].xyz;
\r
37 float vertexInverseMass0 = g_vertexInverseMass[node0];
\r
38 float vertexInverseMass1 = g_vertexInverseMass[node1];
\r
40 float3 nodeDifference = vertexVelocity0 - vertexVelocity1;
\r
41 float dotResult = dot(linkCurrentLength, nodeDifference);
\r
42 float j = -dotResult*linkLengthRatio*kst;
\r
44 float3 velocityChange0 = linkCurrentLength*(j*vertexInverseMass0);
\r
45 float3 velocityChange1 = linkCurrentLength*(j*vertexInverseMass1);
\r
47 vertexVelocity0 += velocityChange0;
\r
48 vertexVelocity1 -= velocityChange1;
\r
50 g_vertexVelocity[node0] = float4(vertexVelocity0, 0.f);
\r
51 g_vertexVelocity[node1] = float4(vertexVelocity1, 0.f);
\r