Imported Upstream version 2.81
[platform/upstream/libbullet.git] / src / BulletMultiThreaded / GpuSoftBodySolvers / DX11 / HLSL / SolvePositions.hlsl
1 MSTRINGIFY(\r
2 \r
3 cbuffer SolvePositionsFromLinksKernelCB : register( b0 )\r
4 {\r
5         int startLink;\r
6         int numLinks;\r
7         float kst;\r
8         float ti;\r
9 };\r
10 \r
11 // Node indices for each link\r
12 StructuredBuffer<int2> g_linksVertexIndices : register( t0 );\r
13 \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
17 \r
18 RWStructuredBuffer<float4> g_vertexPositions : register( u0 );\r
19 \r
20 [numthreads(128, 1, 1)]\r
21 void \r
22 SolvePositionsFromLinksKernel( uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint GI : SV_GroupIndex )\r
23 {\r
24         int linkID = DTid.x + startLink;\r
25         if( DTid.x < numLinks )\r
26         {       \r
27                 float massLSC = g_linksMassLSC[linkID];\r
28                 float restLengthSquared = g_linksRestLengthSquared[linkID];\r
29                 \r
30                 if( massLSC > 0.0f )\r
31                 {               \r
32                         int2 nodeIndices = g_linksVertexIndices[linkID];\r
33                         int node0 = nodeIndices.x;\r
34                         int node1 = nodeIndices.y;\r
35                         \r
36                         float3 position0 = g_vertexPositions[node0].xyz;\r
37                         float3 position1 = g_vertexPositions[node1].xyz;\r
38 \r
39                         float inverseMass0 = g_verticesInverseMass[node0];\r
40                         float inverseMass1 = g_verticesInverseMass[node1]; \r
41 \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
47 \r
48                         g_vertexPositions[node0] = float4(position0, 0.f);\r
49                         g_vertexPositions[node1] = float4(position1, 0.f);\r
50 \r
51                 }\r
52         }\r
53 }\r
54 \r
55 );