3
cbuffer VSolveLinksCB : register( b0 )
11
// Node indices for each link
12
StructuredBuffer<int2> g_linksVertexIndices : register( t0 );
14
StructuredBuffer<float> g_linksLengthRatio : register( t1 );
15
StructuredBuffer<float4> g_linksCurrentLength : register( t2 );
16
StructuredBuffer<float> g_vertexInverseMass : register( t3 );
18
RWStructuredBuffer<float4> g_vertexVelocity : register( u0 );
20
[numthreads(128, 1, 1)]
22
VSolveLinksKernel( uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint GI : SV_GroupIndex )
24
int linkID = DTid.x + startLink;
25
if( DTid.x < numLinks )
27
int2 nodeIndices = g_linksVertexIndices[linkID];
28
int node0 = nodeIndices.x;
29
int node1 = nodeIndices.y;
31
float linkLengthRatio = g_linksLengthRatio[linkID];
32
float3 linkCurrentLength = g_linksCurrentLength[linkID].xyz;
34
float3 vertexVelocity0 = g_vertexVelocity[node0].xyz;
35
float3 vertexVelocity1 = g_vertexVelocity[node1].xyz;
37
float vertexInverseMass0 = g_vertexInverseMass[node0];
38
float vertexInverseMass1 = g_vertexInverseMass[node1];
40
float3 nodeDifference = vertexVelocity0 - vertexVelocity1;
41
float dotResult = dot(linkCurrentLength, nodeDifference);
42
float j = -dotResult*linkLengthRatio*kst;
44
float3 velocityChange0 = linkCurrentLength*(j*vertexInverseMass0);
45
float3 velocityChange1 = linkCurrentLength*(j*vertexInverseMass1);
47
vertexVelocity0 += velocityChange0;
48
vertexVelocity1 -= velocityChange1;
50
g_vertexVelocity[node0] = float4(vertexVelocity0, 0.f);
51
g_vertexVelocity[node1] = float4(vertexVelocity1, 0.f);
b'\\ No newline at end of file'