Merge pull request #1874 from John3/readmeUpdate
[Torque-3d.git] / Engine / lib / bullet / src / BulletMultiThreaded / GpuSoftBodySolvers / DX11 / HLSL / PrepareLinks.hlsl
blob75db8d1497e6e8c607083d73daa644c8a4619ba3
1 MSTRINGIFY(
3 cbuffer PrepareLinksCB : register( b0 )
5         int numLinks;
6         int padding0;
7         int padding1;
8         int padding2;
9 };
11 // Node indices for each link
12 StructuredBuffer<int2> g_linksVertexIndices : register( t0 );
13 StructuredBuffer<float> g_linksMassLSC : register( t1 );
14 StructuredBuffer<float4> g_nodesPreviousPosition : register( t2 );
16 RWStructuredBuffer<float> g_linksLengthRatio : register( u0 );
17 RWStructuredBuffer<float4> g_linksCurrentLength : register( u1 );
19 [numthreads(128, 1, 1)]
20 void 
21 PrepareLinksKernel( uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint GI : SV_GroupIndex )
23         int linkID = DTid.x;
24         if( linkID < numLinks )
25         {       
26                 int2 nodeIndices = g_linksVertexIndices[linkID];
27                 int node0 = nodeIndices.x;
28                 int node1 = nodeIndices.y;
29                 
30                 float4 nodePreviousPosition0 = g_nodesPreviousPosition[node0];
31                 float4 nodePreviousPosition1 = g_nodesPreviousPosition[node1];
33                 float massLSC = g_linksMassLSC[linkID];
34                 
35                 float4 linkCurrentLength = nodePreviousPosition1 - nodePreviousPosition0;
36                 
37                 float linkLengthRatio = dot(linkCurrentLength, linkCurrentLength)*massLSC;
38                 linkLengthRatio = 1./linkLengthRatio;
39                 
40                 g_linksCurrentLength[linkID] = linkCurrentLength;
41                 g_linksLengthRatio[linkID] = linkLengthRatio;           
42         }