Imported Upstream version 2.81
[platform/upstream/libbullet.git] / src / BulletMultiThreaded / GpuSoftBodySolvers / DX11 / HLSL / PrepareLinks.hlsl
1 MSTRINGIFY(\r
2 \r
3 cbuffer PrepareLinksCB : register( b0 )\r
4 {\r
5         int numLinks;\r
6         int padding0;\r
7         int padding1;\r
8         int padding2;\r
9 };\r
10 \r
11 // Node indices for each link\r
12 StructuredBuffer<int2> g_linksVertexIndices : register( t0 );\r
13 StructuredBuffer<float> g_linksMassLSC : register( t1 );\r
14 StructuredBuffer<float4> g_nodesPreviousPosition : register( t2 );\r
15 \r
16 RWStructuredBuffer<float> g_linksLengthRatio : register( u0 );\r
17 RWStructuredBuffer<float4> g_linksCurrentLength : register( u1 );\r
18 \r
19 [numthreads(128, 1, 1)]\r
20 void \r
21 PrepareLinksKernel( uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint GI : SV_GroupIndex )\r
22 {\r
23         int linkID = DTid.x;\r
24         if( linkID < numLinks )\r
25         {       \r
26                 int2 nodeIndices = g_linksVertexIndices[linkID];\r
27                 int node0 = nodeIndices.x;\r
28                 int node1 = nodeIndices.y;\r
29                 \r
30                 float4 nodePreviousPosition0 = g_nodesPreviousPosition[node0];\r
31                 float4 nodePreviousPosition1 = g_nodesPreviousPosition[node1];\r
32 \r
33                 float massLSC = g_linksMassLSC[linkID];\r
34                 \r
35                 float4 linkCurrentLength = nodePreviousPosition1 - nodePreviousPosition0;\r
36                 \r
37                 float linkLengthRatio = dot(linkCurrentLength, linkCurrentLength)*massLSC;\r
38                 linkLengthRatio = 1./linkLengthRatio;\r
39                 \r
40                 g_linksCurrentLength[linkID] = linkCurrentLength;\r
41                 g_linksLengthRatio[linkID] = linkLengthRatio;           \r
42         }\r
43 }\r
44 );