~ubuntu-branches/ubuntu/saucy/emscripten/saucy-proposed

« back to all changes in this revision

Viewing changes to tests/bullet/src/BulletMultiThreaded/GpuSoftBodySolvers/DX11/HLSL/ApplyForces.hlsl

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
MSTRINGIFY(
 
2
 
 
3
cbuffer ApplyForcesCB : register( b0 )
 
4
{
 
5
        unsigned int numNodes;
 
6
        float solverdt;
 
7
        float epsilon;
 
8
        int padding3;
 
9
};
 
10
 
 
11
 
 
12
StructuredBuffer<int> g_vertexClothIdentifier : register( t0 );
 
13
StructuredBuffer<float4> g_vertexNormal : register( t1 );
 
14
StructuredBuffer<float> g_vertexArea : register( t2 );
 
15
StructuredBuffer<float> g_vertexInverseMass : register( t3 );
 
16
// TODO: These could be combined into a lift/drag factor array along with medium density
 
17
StructuredBuffer<float> g_clothLiftFactor : register( t4 );
 
18
StructuredBuffer<float> g_clothDragFactor : register( t5 );
 
19
StructuredBuffer<float4> g_clothWindVelocity : register( t6 );
 
20
StructuredBuffer<float4> g_clothAcceleration : register( t7 );
 
21
StructuredBuffer<float> g_clothMediumDensity : register( t8 );
 
22
 
 
23
RWStructuredBuffer<float4> g_vertexForceAccumulator : register( u0 );
 
24
RWStructuredBuffer<float4> g_vertexVelocity : register( u1 );
 
25
 
 
26
float3 projectOnAxis( float3 v, float3 a )
 
27
{
 
28
        return (a*dot(v, a));
 
29
}
 
30
 
 
31
[numthreads(128, 1, 1)]
 
32
void 
 
33
ApplyForcesKernel( uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint GI : SV_GroupIndex )
 
34
{
 
35
        unsigned int nodeID = DTid.x;
 
36
        if( nodeID < numNodes )
 
37
        {               
 
38
                int clothId = g_vertexClothIdentifier[nodeID];
 
39
                float nodeIM = g_vertexInverseMass[nodeID];
 
40
                
 
41
                if( nodeIM > 0.0f )
 
42
                {
 
43
                        float3 nodeV = g_vertexVelocity[nodeID].xyz;
 
44
                        float3 normal = g_vertexNormal[nodeID].xyz;
 
45
                        float area = g_vertexArea[nodeID];
 
46
                        float3 nodeF = g_vertexForceAccumulator[nodeID].xyz;
 
47
                        
 
48
                        // Read per-cloth values
 
49
                        float3 clothAcceleration = g_clothAcceleration[clothId].xyz;
 
50
                        float3 clothWindVelocity = g_clothWindVelocity[clothId].xyz;
 
51
                        float liftFactor = g_clothLiftFactor[clothId];
 
52
                        float dragFactor = g_clothDragFactor[clothId];
 
53
                        float mediumDensity = g_clothMediumDensity[clothId];
 
54
                
 
55
                        // Apply the acceleration to the cloth rather than do this via a force
 
56
                        nodeV += (clothAcceleration*solverdt);
 
57
 
 
58
                        g_vertexVelocity[nodeID] = float4(nodeV, 0.f);
 
59
 
 
60
                        float3 relativeWindVelocity = nodeV - clothWindVelocity;
 
61
                        float relativeSpeedSquared = dot(relativeWindVelocity, relativeWindVelocity);
 
62
                        
 
63
                        if( relativeSpeedSquared > epsilon )
 
64
                        {
 
65
                                // Correct direction of normal relative to wind direction and get dot product
 
66
                                normal = normal * (dot(normal, relativeWindVelocity) < 0 ? -1.f : 1.f);
 
67
                                float dvNormal = dot(normal, relativeWindVelocity);
 
68
                                if( dvNormal > 0 )
 
69
                                {
 
70
                                        float3 force = float3(0.f, 0.f, 0.f);
 
71
                                        float c0 = area * dvNormal * relativeSpeedSquared / 2.f;
 
72
                                        float c1 = c0 * mediumDensity;
 
73
                                        force += normal * (-c1 * liftFactor);
 
74
                                        force += normalize(relativeWindVelocity)*(-c1 * dragFactor);
 
75
                                        
 
76
                                        float dtim = solverdt * nodeIM;
 
77
                                        float3 forceDTIM = force * dtim;
 
78
                                        
 
79
                                        float3 nodeFPlusForce = nodeF + force;
 
80
                                        
 
81
                                        // m_nodesf[i] -= ProjectOnAxis(m_nodesv[i], force.normalized())/dtim;  
 
82
                                        float3 nodeFMinus = nodeF - (projectOnAxis(nodeV, normalize(force))/dtim);
 
83
                                        
 
84
                                        nodeF = nodeFPlusForce;
 
85
                                        if( dot(forceDTIM, forceDTIM) > dot(nodeV, nodeV) )
 
86
                                                nodeF = nodeFMinus;
 
87
                                                                        
 
88
                                        g_vertexForceAccumulator[nodeID] = float4(nodeF, 0.0f); 
 
89
                                }
 
90
                        }
 
91
                }
 
92
        }
 
93
}
 
94
 
 
95
);
 
 
b'\\ No newline at end of file'