Imported Upstream version 2.81
[platform/upstream/libbullet.git] / src / BulletMultiThreaded / GpuSoftBodySolvers / OpenCL / OpenCLC10 / UpdateConstants.cl
1 MSTRINGIFY(\r
2 \r
3 /*#define float3 float4\r
4 \r
5 float dot3(float3 a, float3 b)\r
6 {\r
7    return a.x*b.x + a.y*b.y + a.z*b.z;\r
8 }*/\r
9 \r
10 __kernel void \r
11 UpdateConstantsKernel( \r
12         const int numLinks,\r
13         __global int2 * g_linksVertexIndices,\r
14         __global float4 * g_vertexPositions,\r
15         __global float * g_vertexInverseMasses,\r
16         __global float * g_linksMaterialLSC,\r
17         __global float * g_linksMassLSC,\r
18         __global float * g_linksRestLengthSquared,\r
19         __global float * g_linksRestLengths)\r
20 {\r
21         int linkID = get_global_id(0);\r
22         if( linkID < numLinks )\r
23         {       \r
24                 int2 nodeIndices = g_linksVertexIndices[linkID];\r
25                 int node0 = nodeIndices.x;\r
26                 int node1 = nodeIndices.y;\r
27                 float linearStiffnessCoefficient = g_linksMaterialLSC[ linkID ];\r
28                 \r
29                 float3 position0   = g_vertexPositions[node0].xyz;\r
30                 float3 position1   = g_vertexPositions[node1].xyz;\r
31                 float inverseMass0 = g_vertexInverseMasses[node0];\r
32                 float inverseMass1 = g_vertexInverseMasses[node1];\r
33 \r
34                 float3 difference = position0 - position1;\r
35                 float length2 = dot(difference, difference);\r
36                 float length = sqrt(length2);\r
37         \r
38                 g_linksRestLengths[linkID] = length;\r
39                 g_linksMassLSC[linkID] = (inverseMass0 + inverseMass1)/linearStiffnessCoefficient;\r
40                 g_linksRestLengthSquared[linkID] = length*length;               \r
41         }\r
42 }\r
43 \r
44 );