OSDN Git Service

merge from MikuMikuStudio nativebullet.
[mikumikustudio/libgdx-mikumikustudio.git] / extensions / gdx-bullet / jni / src / bullet / BulletMultiThreaded / GpuSoftBodySolvers / DX11 / HLSL / UpdatePositions.hlsl
1 MSTRINGIFY(
2
3 cbuffer UpdateVelocitiesFromPositionsWithoutVelocitiesCB : register( b0 )
4 {
5         int numNodes;
6         float isolverdt;
7         int padding1;
8         int padding2;
9 };
10
11
12 StructuredBuffer<float4> g_vertexPositions : register( t0 );
13 StructuredBuffer<float4> g_vertexPreviousPositions : register( t1 );
14 StructuredBuffer<int> g_vertexClothIndices : register( t2 );
15 StructuredBuffer<float> g_clothDampingFactor : register( t3 );
16
17 RWStructuredBuffer<float4> g_vertexVelocities : register( u0 );
18 RWStructuredBuffer<float4> g_vertexForces : register( u1 );
19
20
21 [numthreads(128, 1, 1)]
22 void 
23 updateVelocitiesFromPositionsWithoutVelocitiesKernel( uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint GI : SV_GroupIndex )
24 {
25         int nodeID = DTid.x;
26         if( nodeID < numNodes )
27         {       
28                 float3 position = g_vertexPositions[nodeID].xyz;
29                 float3 previousPosition = g_vertexPreviousPositions[nodeID].xyz;
30                 float3 velocity = g_vertexVelocities[nodeID].xyz;
31                 int clothIndex = g_vertexClothIndices[nodeID];
32                 float dampingFactor = g_clothDampingFactor[clothIndex];
33                 float velocityCoefficient = (1.f - dampingFactor);
34                 
35                 float3 difference = position - previousPosition;
36                                 
37                 velocity = difference*velocityCoefficient*isolverdt;            
38                 
39                 g_vertexVelocities[nodeID] = float4(velocity, 0.f);
40                 g_vertexForces[nodeID] = float4(0.f, 0.f, 0.f, 0.f);                                                            
41         }
42 }
43
44 );