Imported Upstream version 2.81
[platform/upstream/libbullet.git] / src / BulletMultiThreaded / GpuSoftBodySolvers / DX11 / HLSL / VSolveLinks.hlsl
1 MSTRINGIFY(\r
2 \r
3 cbuffer VSolveLinksCB : register( b0 )\r
4 {\r
5         int startLink;\r
6         int numLinks;\r
7         float kst;\r
8         int padding;\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_linksLengthRatio : register( t1 );\r
15 StructuredBuffer<float4> g_linksCurrentLength : register( t2 );\r
16 StructuredBuffer<float> g_vertexInverseMass : register( t3 );\r
17 \r
18 RWStructuredBuffer<float4> g_vertexVelocity : register( u0 );\r
19 \r
20 [numthreads(128, 1, 1)]\r
21 void \r
22 VSolveLinksKernel( 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                 int2 nodeIndices = g_linksVertexIndices[linkID];\r
28                 int node0 = nodeIndices.x;\r
29                 int node1 = nodeIndices.y;\r
30                 \r
31                 float linkLengthRatio = g_linksLengthRatio[linkID];\r
32                 float3 linkCurrentLength = g_linksCurrentLength[linkID].xyz;\r
33                 \r
34                 float3 vertexVelocity0 = g_vertexVelocity[node0].xyz;\r
35                 float3 vertexVelocity1 = g_vertexVelocity[node1].xyz;\r
36 \r
37                 float vertexInverseMass0 = g_vertexInverseMass[node0];\r
38                 float vertexInverseMass1 = g_vertexInverseMass[node1]; \r
39 \r
40                 float3 nodeDifference = vertexVelocity0 - vertexVelocity1;\r
41                 float dotResult = dot(linkCurrentLength, nodeDifference);\r
42                 float j = -dotResult*linkLengthRatio*kst;\r
43                 \r
44                 float3 velocityChange0 = linkCurrentLength*(j*vertexInverseMass0);\r
45                 float3 velocityChange1 = linkCurrentLength*(j*vertexInverseMass1);\r
46                 \r
47                 vertexVelocity0 += velocityChange0;\r
48                 vertexVelocity1 -= velocityChange1;\r
49 \r
50                 g_vertexVelocity[node0] = float4(vertexVelocity0, 0.f);\r
51                 g_vertexVelocity[node1] = float4(vertexVelocity1, 0.f);\r
52         }\r
53 }\r
54 \r
55 );