24 #define MSTRINGIFY(A) #A
26 #include "HLSL/PrepareLinks.hlsl"
28 #include "HLSL/UpdatePositionsFromVelocities.hlsl"
29 static char* SolvePositionsHLSLString =
30 #include "HLSL/SolvePositions.hlsl"
31 static char* UpdateNodesHLSLString =
32 #include "HLSL/UpdateNodes.hlsl"
33 static char* UpdatePositionsHLSLString =
34 #include "HLSL/UpdatePositions.hlsl"
35 static char* UpdateConstantsHLSLString =
36 #include "HLSL/UpdateConstants.hlsl"
37 static char* IntegrateHLSLString =
38 #include "HLSL/Integrate.hlsl"
39 static char* ApplyForcesHLSLString =
40 #include "HLSL/ApplyForces.hlsl"
41 static char* UpdateNormalsHLSLString =
42 #include "HLSL/UpdateNormals.hlsl"
43 static char* OutputToVertexArrayHLSLString =
44 #include "HLSL/OutputToVertexArray.hlsl"
45 static char* VSolveLinksHLSLString =
46 #include "HLSL/VSolveLinks.hlsl"
47 static char* ComputeBoundsHLSLString =
48 #include "HLSL/ComputeBounds.hlsl"
49 static char* SolveCollisionsAndUpdateVelocitiesHLSLString =
50 #include "HLSL/SolveCollisionsAndUpdateVelocities.hlsl"
54 m_dx11Links( d3dDevice, d3dDeviceContext, &m_links, false ),
63 m_d3dDevice = d3dDevice;
80 int newSize = previousSize + numLinks;
143 batchValues.
resize( numLinks, 0 );
147 for(
int linkIndex = 0; linkIndex < numLinks; ++linkIndex )
151 if( vertex0 > maxVertex )
153 if( vertex1 > maxVertex )
156 int numVertices = maxVertex + 1;
162 vertexConnectedColourLists.
resize(numVertices);
169 for(
int linkIndex = 0; linkIndex < numLinks; ++linkIndex )
190 batchValues[linkIndex] = colour;
195 for(
int i = 0; i < numLinks; ++i )
197 int batch = batchValues[i];
198 if( batch >= batchCounts.
size() )
201 ++(batchCounts[batch]);
210 for(
int batchIndex = 0; batchIndex < batchCounts.
size(); ++batchIndex )
214 sum += batchCounts[batchIndex];
232 for(
int batch = 0; batch < batchCounts.
size(); ++batch )
233 batchCounts[batch] = 0;
236 for(
int linkIndex = 0; linkIndex < numLinks; ++linkIndex )
247 int batch = batchValues[linkIndex];
250 batchCounts[batch] = batchCounts[batch] + 1;
251 m_links[newLocation] = m_links_Backup[linkLocation];
253 m_linkStrength[newLocation] = m_linkStrength_Backup[linkLocation];
254 m_linksMassLSC[newLocation] = m_linksMassLSC_Backup[linkLocation];
268 m_dx11ClothIdentifier( d3dDevice, d3dDeviceContext, &m_clothIdentifier, false ),
269 m_dx11VertexPosition( d3dDevice, d3dDeviceContext, &m_vertexPosition, false ),
270 m_dx11VertexPreviousPosition( d3dDevice, d3dDeviceContext, &m_vertexPreviousPosition, false ),
271 m_dx11VertexVelocity( d3dDevice, d3dDeviceContext, &m_vertexVelocity, false ),
272 m_dx11VertexForceAccumulator( d3dDevice, d3dDeviceContext, &m_vertexForceAccumulator, false ),
273 m_dx11VertexNormal( d3dDevice, d3dDeviceContext, &m_vertexNormal, false ),
274 m_dx11VertexInverseMass( d3dDevice, d3dDeviceContext, &m_vertexInverseMass, false ),
275 m_dx11VertexArea( d3dDevice, d3dDeviceContext, &m_vertexArea, false ),
276 m_dx11VertexTriangleCount( d3dDevice, d3dDeviceContext, &m_vertexTriangleCount, false )
356 m_dx11VertexIndices( d3dDevice, d3dDeviceContext, &m_vertexIndices, false ),
357 m_dx11Area( d3dDevice, d3dDeviceContext, &m_area, false ),
358 m_dx11Normal( d3dDevice, d3dDeviceContext, &m_normal, false )
374 int newSize = previousSize + numTriangles;
430 if( numTriangles == 0 )
435 batchValues.
resize( numTriangles );
439 for(
int triangleIndex = 0; triangleIndex < numTriangles; ++triangleIndex )
445 if( vertex0 > maxVertex )
447 if( vertex1 > maxVertex )
449 if( vertex2 > maxVertex )
452 int numVertices = maxVertex + 1;
458 vertexConnectedColourLists.
resize(numVertices);
465 for(
int triangleIndex = 0; triangleIndex < numTriangles; ++triangleIndex )
498 batchValues[triangleIndex] = colour;
504 for(
int i = 0; i < numTriangles; ++i )
506 int batch = batchValues[i];
507 if( batch >= batchCounts.
size() )
510 ++(batchCounts[batch]);
519 for(
int batchIndex = 0; batchIndex < batchCounts.
size(); ++batchIndex )
523 sum += batchCounts[batchIndex];
535 for(
int batch = 0; batch < batchCounts.
size(); ++batch )
536 batchCounts[batch] = 0;
539 for(
int triangleIndex = 0; triangleIndex < numTriangles; ++triangleIndex )
550 int batch = batchValues[triangleIndex];
553 batchCounts[batch] = batchCounts[batch] + 1;
554 m_vertexIndices[newLocation] = m_vertexIndices_Backup[triangleLocation];
555 m_area[newLocation] = m_area_Backup[triangleLocation];
556 m_normal[newLocation] = m_normal_Backup[triangleLocation];
575 m_dx11Device( dx11Device ),
576 m_dx11Context( dx11Context ),
577 dxFunctions( m_dx11Device, m_dx11Context, dx11CompileFromMemory ),
578 m_linkData(m_dx11Device, m_dx11Context),
579 m_vertexData(m_dx11Device, m_dx11Context),
580 m_triangleData(m_dx11Device, m_dx11Context),
581 m_dx11PerClothAcceleration( m_dx11Device, m_dx11Context, &m_perClothAcceleration, true ),
582 m_dx11PerClothWindVelocity( m_dx11Device, m_dx11Context, &m_perClothWindVelocity, true ),
583 m_dx11PerClothDampingFactor( m_dx11Device, m_dx11Context, &m_perClothDampingFactor, true ),
584 m_dx11PerClothVelocityCorrectionCoefficient( m_dx11Device, m_dx11Context, &m_perClothVelocityCorrectionCoefficient, true ),
585 m_dx11PerClothLiftFactor( m_dx11Device, m_dx11Context, &m_perClothLiftFactor, true ),
586 m_dx11PerClothDragFactor( m_dx11Device, m_dx11Context, &m_perClothDragFactor, true ),
587 m_dx11PerClothMediumDensity( m_dx11Device, m_dx11Context, &m_perClothMediumDensity, true ),
588 m_dx11PerClothCollisionObjects( m_dx11Device, m_dx11Context, &m_perClothCollisionObjects, true ),
589 m_dx11CollisionObjectDetails( m_dx11Device, m_dx11Context, &m_collisionObjectDetails, true ),
590 m_dx11PerClothMinBounds( m_dx11Device, m_dx11Context, &m_perClothMinBounds, false ),
591 m_dx11PerClothMaxBounds( m_dx11Device, m_dx11Context, &m_perClothMaxBounds, false ),
592 m_dx11PerClothFriction( m_dx11Device, m_dx11Context, &m_perClothFriction, false ),
593 m_enableUpdateBounds(false)
652 for(
int softBodyIndex = 0; softBodyIndex <
m_softBodySet.size(); ++softBodyIndex )
661 for(
int vertex = 0; vertex < numVertices; ++vertex )
664 Point3 vertexPosition(
getVertexData().getVertexPositions()[firstVertex + vertex] );
666 softBody->
m_nodes[vertex].m_x.setX( vertexPosition.getX() );
667 softBody->
m_nodes[vertex].m_x.setY( vertexPosition.getY() );
668 softBody->
m_nodes[vertex].m_x.setZ( vertexPosition.getZ() );
670 softBody->
m_nodes[vertex].m_n.setX( vertexPosition.getX() );
671 softBody->
m_nodes[vertex].m_n.setY( vertexPosition.getY() );
672 softBody->
m_nodes[vertex].m_n.setZ( vertexPosition.getZ() );
689 for(
int softBodyIndex = 0; softBodyIndex < softBodies.
size(); ++softBodyIndex )
691 btSoftBody *softBody = softBodies[ softBodyIndex ];
715 int maxVertices = numVertices;
721 int maxTriangles = numTriangles;
725 for(
int vertex = 0; vertex < numVertices; ++vertex )
727 Point3 multPoint(softBody->
m_nodes[vertex].m_x.getX(), softBody->
m_nodes[vertex].m_x.getY(), softBody->
m_nodes[vertex].m_x.getZ());
735 float vertexInverseMass = softBody->
m_nodes[vertex].m_im;
736 desc.setInverseMass(vertexInverseMass);
742 for(
int triangle = 0; triangle < numTriangles; ++triangle )
746 int vertexIndex0 = (softBody->
m_faces[triangle].m_n[0] - &(softBody->
m_nodes[0]));
747 int vertexIndex1 = (softBody->
m_faces[triangle].m_n[1] - &(softBody->
m_nodes[0]));
748 int vertexIndex2 = (softBody->
m_faces[triangle].m_n[2] - &(softBody->
m_nodes[0]));
760 int maxLinks = numLinks;
766 for(
int link = 0; link < numLinks; ++link )
768 int vertexIndex0 = softBody->
m_links[link].m_n[0] - &(softBody->
m_nodes[0]);
769 int vertexIndex1 = softBody->
m_links[link].m_n[1] - &(softBody->
m_nodes[0]);
831 constBuffer.
epsilon = FLT_EPSILON;
834 D3D11_MAPPED_SUBRESOURCE MappedResource = {0};
847 int numBlocks = (constBuffer.
numNodes + (128-1)) / 128;
852 ID3D11UnorderedAccessView* pUAViewNULL = NULL;
853 m_dx11Context->CSSetUnorderedAccessViews( 0, 1, &pUAViewNULL, NULL );
854 m_dx11Context->CSSetUnorderedAccessViews( 1, 1, &pUAViewNULL, NULL );
856 ID3D11Buffer *pBufferNull = NULL;
868 constBuffer.
epsilon = FLT_EPSILON;
871 D3D11_MAPPED_SUBRESOURCE MappedResource = {0};
886 int numBlocks = (constBuffer.
numNodes + (128-1)) / 128;
891 ID3D11ShaderResourceView* pViewNULL = NULL;
894 ID3D11UnorderedAccessView* pUAViewNULL = NULL;
895 m_dx11Context->CSSetUnorderedAccessViews( 0, 1, &pUAViewNULL, NULL );
896 m_dx11Context->CSSetUnorderedAccessViews( 1, 1, &pUAViewNULL, NULL );
898 ID3D11Buffer *pBufferNull = NULL;
910 constBuffer.
numFaces = numTriangles;
913 D3D11_MAPPED_SUBRESOURCE MappedResource = {0};
931 int numBlocks = (numTriangles + (128-1)) / 128;
936 ID3D11ShaderResourceView* pViewNULL = NULL;
939 ID3D11UnorderedAccessView* pUAViewNULL = NULL;
940 m_dx11Context->CSSetUnorderedAccessViews( 0, 1, &pUAViewNULL, NULL );
941 m_dx11Context->CSSetUnorderedAccessViews( 1, 1, &pUAViewNULL, NULL );
943 ID3D11Buffer *pBufferNull = NULL;
950 using namespace Vectormath::Aos;
987 float dtInverseMass = solverdt*inverseMass;
992 vertexForce += force;
998 using namespace Vectormath::Aos;
1014 constBuffer.solverdt = solverdt;
1015 constBuffer.epsilon = FLT_EPSILON;
1018 D3D11_MAPPED_SUBRESOURCE MappedResource = {0};
1020 memcpy( MappedResource.pData, &constBuffer,
sizeof(
ApplyForcesCB) );
1041 int numBlocks = (constBuffer.numNodes + (128-1)) / 128;
1046 ID3D11ShaderResourceView* pViewNULL = NULL;
1057 ID3D11UnorderedAccessView* pUAViewNULL = NULL;
1058 m_dx11Context->CSSetUnorderedAccessViews( 0, 1, &pUAViewNULL, NULL );
1059 m_dx11Context->CSSetUnorderedAccessViews( 1, 1, &pUAViewNULL, NULL );
1061 ID3D11Buffer *pBufferNull = NULL;
1082 D3D11_MAPPED_SUBRESOURCE MappedResource = {0};
1084 memcpy( MappedResource.pData, &constBuffer,
sizeof(
IntegrateCB) );
1099 int numBlocks = (constBuffer.
numNodes + (128-1)) / 128;
1104 ID3D11ShaderResourceView* pViewNULL = NULL;
1107 ID3D11UnorderedAccessView* pUAViewNULL = NULL;
1108 m_dx11Context->CSSetUnorderedAccessViews( 0, 1, &pUAViewNULL, NULL );
1109 m_dx11Context->CSSetUnorderedAccessViews( 1, 1, &pUAViewNULL, NULL );
1110 m_dx11Context->CSSetUnorderedAccessViews( 2, 1, &pUAViewNULL, NULL );
1111 m_dx11Context->CSSetUnorderedAccessViews( 3, 1, &pUAViewNULL, NULL );
1113 ID3D11Buffer *pBufferNull = NULL;
1126 float area =
length( crossProduct );
1137 unsigned int mantissa : 23;
1138 unsigned int exponent : 8;
1139 unsigned int sign : 1;
1145 unsigned int uintValue;
1151 for(
int softBodyIndex = 0; softBodyIndex <
m_softBodySet.size(); ++softBodyIndex )
1169 for(
int softBodyIndex = 0; softBodyIndex <
m_softBodySet.size(); ++softBodyIndex )
1178 fai.uintValue = minBoundUInt.
x;
1179 fai.uintValue ^= (((fai.uintValue >> 31) - 1) | 0x80000000);
1180 minBound.
setX( fai.floatValue );
1181 fai.uintValue = minBoundUInt.
y;
1182 fai.uintValue ^= (((fai.uintValue >> 31) - 1) | 0x80000000);
1183 minBound.
setY( fai.floatValue );
1184 fai.uintValue = minBoundUInt.
z;
1185 fai.uintValue ^= (((fai.uintValue >> 31) - 1) | 0x80000000);
1186 minBound.
setZ( fai.floatValue );
1189 fai.uintValue = maxBoundUInt.
x;
1190 fai.uintValue ^= (((fai.uintValue >> 31) - 1) | 0x80000000);
1191 maxBound.
setX( fai.floatValue );
1192 fai.uintValue = maxBoundUInt.
y;
1193 fai.uintValue ^= (((fai.uintValue >> 31) - 1) | 0x80000000);
1194 maxBound.
setY( fai.floatValue );
1195 fai.uintValue = maxBoundUInt.
z;
1196 fai.uintValue ^= (((fai.uintValue >> 31) - 1) | 0x80000000);
1197 maxBound.
setZ( fai.floatValue );
1200 m_softBodySet[softBodyIndex]->updateBounds( minBound, maxBound );
1206 using namespace Vectormath::Aos;
1216 for(
int linkIndex = 0; linkIndex < numLinks; ++linkIndex )
1223 float massLSC = (invMass0 + invMass1)/linearStiffness;
1226 float restLengthSquared = restLength*restLength;
1264 int currentCloth = 0;
1269 if( nextCloth != currentCloth )
1275 currentCloth = nextCloth;
1276 startIndex = collisionObject;
1332 if( m_numberOfVelocityIterations > 0 )
1370 D3D11_MAPPED_SUBRESOURCE MappedResource = {0};
1372 memcpy( MappedResource.pData, &constBuffer,
sizeof(
PrepareLinksCB) );
1387 int numBlocks = (constBuffer.
numLinks + (128-1)) / 128;
1392 ID3D11ShaderResourceView* pViewNULL = NULL;
1397 ID3D11UnorderedAccessView* pUAViewNULL = NULL;
1398 m_dx11Context->CSSetUnorderedAccessViews( 0, 1, &pUAViewNULL, NULL );
1399 m_dx11Context->CSSetUnorderedAccessViews( 1, 1, &pUAViewNULL, NULL );
1401 ID3D11Buffer *pBufferNull = NULL;
1417 D3D11_MAPPED_SUBRESOURCE MappedResource = {0};
1432 int numBlocks = (constBuffer.
numNodes + (128-1)) / 128;
1437 ID3D11ShaderResourceView* pViewNULL = NULL;
1440 ID3D11UnorderedAccessView* pUAViewNULL = NULL;
1441 m_dx11Context->CSSetUnorderedAccessViews( 0, 1, &pUAViewNULL, NULL );
1442 m_dx11Context->CSSetUnorderedAccessViews( 1, 1, &pUAViewNULL, NULL );
1444 ID3D11Buffer *pBufferNull = NULL;
1459 constBuffer.
kst = kst;
1460 constBuffer.
ti = ti;
1462 D3D11_MAPPED_SUBRESOURCE MappedResource = {0};
1479 int numBlocks = (constBuffer.
numLinks + (128-1)) / 128;
1484 ID3D11ShaderResourceView* pViewNULL = NULL;
1490 ID3D11UnorderedAccessView* pUAViewNULL = NULL;
1491 m_dx11Context->CSSetUnorderedAccessViews( 0, 1, &pUAViewNULL, NULL );
1493 ID3D11Buffer *pBufferNull = NULL;
1509 constBuffer.
kst = kst;
1511 D3D11_MAPPED_SUBRESOURCE MappedResource = {0};
1513 memcpy( MappedResource.pData, &constBuffer,
sizeof(
VSolveLinksCB) );
1528 int numBlocks = (constBuffer.
numLinks + (128-1)) / 128;
1533 ID3D11ShaderResourceView* pViewNULL = NULL;
1539 ID3D11UnorderedAccessView* pUAViewNULL = NULL;
1540 m_dx11Context->CSSetUnorderedAccessViews( 0, 1, &pUAViewNULL, NULL );
1542 ID3D11Buffer *pBufferNull = NULL;
1558 D3D11_MAPPED_SUBRESOURCE MappedResource = {0};
1578 int numBlocks = (constBuffer.
numNodes + (128-1)) / 128;
1583 ID3D11ShaderResourceView* pViewNULL = NULL;
1590 ID3D11UnorderedAccessView* pUAViewNULL = NULL;
1591 m_dx11Context->CSSetUnorderedAccessViews( 0, 1, &pUAViewNULL, NULL );
1592 m_dx11Context->CSSetUnorderedAccessViews( 1, 1, &pUAViewNULL, NULL );
1594 ID3D11Buffer *pBufferNull = NULL;
1610 D3D11_MAPPED_SUBRESOURCE MappedResource = {0};
1629 int numBlocks = (constBuffer.
numNodes + (128-1)) / 128;
1634 ID3D11ShaderResourceView* pViewNULL = NULL;
1640 ID3D11UnorderedAccessView* pUAViewNULL = NULL;
1641 m_dx11Context->CSSetUnorderedAccessViews( 0, 1, &pUAViewNULL, NULL );
1642 m_dx11Context->CSSetUnorderedAccessViews( 1, 1, &pUAViewNULL, NULL );
1644 ID3D11Buffer *pBufferNull = NULL;
1661 D3D11_MAPPED_SUBRESOURCE MappedResource = {0};
1663 memcpy( MappedResource.pData, &constBuffer,
sizeof(
ComputeBoundsCB) );
1677 int numBlocks = (constBuffer.
numNodes + (128-1)) / 128;
1682 ID3D11ShaderResourceView* pViewNULL = NULL;
1686 ID3D11UnorderedAccessView* pUAViewNULL = NULL;
1687 m_dx11Context->CSSetUnorderedAccessViews( 0, 1, &pUAViewNULL, NULL );
1688 m_dx11Context->CSSetUnorderedAccessViews( 1, 1, &pUAViewNULL, NULL );
1690 ID3D11Buffer *pBufferNull = NULL;
1713 D3D11_MAPPED_SUBRESOURCE MappedResource = {0};
1734 int numBlocks = (constBuffer.
numNodes + (128-1)) / 128;
1739 ID3D11ShaderResourceView* pViewNULL = NULL;
1747 ID3D11UnorderedAccessView* pUAViewNULL = NULL;
1748 m_dx11Context->CSSetUnorderedAccessViews( 0, 1, &pUAViewNULL, NULL );
1749 m_dx11Context->CSSetUnorderedAccessViews( 1, 1, &pUAViewNULL, NULL );
1750 m_dx11Context->CSSetUnorderedAccessViews( 2, 1, &pUAViewNULL, NULL );
1752 ID3D11Buffer *pBufferNull = NULL;
1776 for(
int softBodyIndex = 0; softBodyIndex <
m_softBodySet.size(); ++softBodyIndex )
1779 if( softBodyInterface->
getSoftBody() == softBody )
1780 return softBodyInterface;
1787 for(
int softBodyIndex = 0; softBodyIndex <
m_softBodySet.size(); ++softBodyIndex )
1790 if( softBodyInterface->
getSoftBody() == softBody )
1791 return softBodyInterface;
1798 for(
int softBodyIndex = 0; softBodyIndex <
m_softBodySet.size(); ++softBodyIndex )
1801 if( softBodyInterface->
getSoftBody() == softBody )
1802 return softBodyIndex;
1821 const int lastVertex = firstVertex + currentCloth->
getNumVertices();
1830 const int lastVertex = firstVertex + currentCloth->
getNumVertices();
1838 float *vertexPointer = basePointer + vertexOffset;
1840 for(
int vertexIndex = firstVertex; vertexIndex < lastVertex; ++vertexIndex )
1843 *(vertexPointer + 0) = position.
getX();
1844 *(vertexPointer + 1) = position.
getY();
1845 *(vertexPointer + 2) = position.
getZ();
1846 vertexPointer += vertexStride;
1853 float *normalPointer = basePointer + normalOffset;
1855 for(
int vertexIndex = firstVertex; vertexIndex < lastVertex; ++vertexIndex )
1858 *(normalPointer + 0) = normal.
getX();
1859 *(normalPointer + 1) = normal.
getY();
1860 *(normalPointer + 2) = normal.
getZ();
1861 normalPointer += normalStride;
1880 SAFE_RELEASE( outputToVertexArrayWithNormalsKernel.constBuffer );
1881 SAFE_RELEASE( outputToVertexArrayWithNormalsKernel.kernel );
1882 SAFE_RELEASE( outputToVertexArrayWithoutNormalsKernel.constBuffer );
1883 SAFE_RELEASE( outputToVertexArrayWithoutNormalsKernel.kernel );
1894 bool returnVal =
true;
1901 if( !outputToVertexArrayWithNormalsKernel.constBuffer)
1904 if( !outputToVertexArrayWithoutNormalsKernel.constBuffer )
1928 const int lastVertex = firstVertex + currentCloth->
getNumVertices();
1942 ID3D11ComputeShader* outputToVertexArrayShader = outputToVertexArrayWithoutNormalsKernel.kernel;
1943 ID3D11Buffer* outputToVertexArrayConstBuffer = outputToVertexArrayWithoutNormalsKernel.constBuffer;
1953 outputToVertexArrayShader = outputToVertexArrayWithNormalsKernel.kernel;
1954 outputToVertexArrayConstBuffer = outputToVertexArrayWithNormalsKernel.constBuffer;
1958 D3D11_MAPPED_SUBRESOURCE MappedResource = {0};
1968 ID3D11UnorderedAccessView* dx11UAV = dx11VertexBuffer->
getDX11UAV();
1974 int numBlocks = (constBuffer.
numNodes + (128-1)) / 128;
1979 ID3D11ShaderResourceView* pViewNULL = NULL;
1983 ID3D11UnorderedAccessView* pUAViewNULL = NULL;
1986 ID3D11Buffer *pBufferNull = NULL;
1997 const char *cs5String =
"cs_5_0";
2000 ID3DBlob* pErrorBlob = NULL;
2001 ID3DBlob* pBlob = NULL;
2002 ID3D11ComputeShader* kernelPointer = 0;
2004 hr = m_dx11CompileFromMemory(
2006 strlen(shaderString),
2012 D3D10_SHADER_ENABLE_STRICTNESS,
2023 btAssert(
"Compilation of compute shader failed\n" );
2024 char *debugString = (
char*)pErrorBlob->GetBufferPointer();
2025 OutputDebugStringA( debugString );
2038 hr =
m_dx11Device->CreateComputeShader( pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &kernelPointer );
2047 ID3D11Buffer* constBuffer = 0;
2048 if( constBufferSize > 0 )
2051 D3D11_BUFFER_DESC constant_buffer_desc;
2052 ZeroMemory(&constant_buffer_desc,
sizeof(constant_buffer_desc));
2053 constant_buffer_desc.ByteWidth = constBufferSize;
2054 constant_buffer_desc.Usage = D3D11_USAGE_DYNAMIC;
2055 constant_buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
2056 constant_buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
2057 m_dx11Device->CreateBuffer(&constant_buffer_desc, NULL, &constBuffer);
2071 descriptor.
kernel = kernelPointer;
2083 bool returnVal =
true;
2147 return outTransform;
2153 float scalarMargin = this->getSoftBody()->getCollisionShape()->getMargin();
2154 btVector3 vectorMargin( scalarMargin, scalarMargin, scalarMargin );
2155 m_softBody->m_bounds[0] = lowerBound - vectorMargin;
2156 m_softBody->m_bounds[1] = upperBound + vectorMargin;
2169 if( softBodyIndex >= 0 )
2183 newCollisionShapeDescription.
radius = capsule->getRadius();
2184 newCollisionShapeDescription.
halfHeight = capsule->getHalfHeight();
2185 newCollisionShapeDescription.
margin = capsule->getMargin();
2186 newCollisionShapeDescription.
friction = friction;
2194 printf(
"Unsupported collision shape type\n");
2214 for(
int softBodyIndex = 0; softBodyIndex <
m_softBodySet.size(); ++softBodyIndex )
static T sum(const btAlignedObjectArray< T > &items)
virtual void setTriangleAt(const TriangleDescription &triangle, int triangleIndex)
static char m_dx11LinksLengthRatio(d3dDevice, d3dDeviceContext,&m_linksLengthRatio, false)
btScalar length(const btQuaternion &q)
Return the length of a quaternion.
btDX11Buffer< CollisionObjectIndices > m_dx11PerClothCollisionObjects
btDX11Buffer< float > m_dx11Area
void createVertices(int numVertices, int clothIdentifier, int maxVertices=0)
Create numVertices new vertices for cloth clothIdentifier maxVertices allows a buffer zone of extra v...
btDX11Buffer< Vectormath::Aos::Point3 > m_dx11VertexPreviousPosition
virtual void setLinkAt(const LinkDescription &link, int linkIndex)
Insert the link described into the correct data structures assuming space has already been allocated ...
void push_back(const T &_Val)
void generateBatches()
Generate (and later update) the batching for the entire triangle set.
virtual void integrate(float solverdt)
Integrate motion on the solver.
static char m_dx11LinksMassLSC(d3dDevice, d3dDeviceContext,&m_linksMassLSC, false)
virtual void createTriangles(int numTriangles)
Allocate enough space in all link-related arrays to fit numLinks links.
ID3D11DeviceContext * m_dx11Context
virtual void createTriangles(int numTriangles)
Vectormath::Aos::Vector3 ProjectOnAxis(const Vectormath::Aos::Vector3 &v, const Vectormath::Aos::Vector3 &a)
Vectormath::Aos::Transform3 shapeTransform
void setPosition(const Vectormath::Aos::Point3 &position)
bool moveToGPU()
Move the data to the GPU if it is not there already.
btDX11Buffer< float > m_dx11PerClothDampingFactor
virtual bool hasVertexPositions() const
virtual void setLinkAt(const LinkDescription &link, int linkIndex)
Insert the link described into the correct data structures assuming space has already been allocated ...
btDX11Buffer< Vectormath::Aos::Vector3 > m_dx11VertexVelocity
DXFunctions::KernelDesc computeBoundsKernel
ID3D11ComputeShader * kernel
btAlignedObjectArray< Vectormath::Aos::Vector3 > m_normal
DXFunctions::KernelDesc updatePositionsFromVelocitiesKernel
btAlignedObjectArray< TriangleNodeSet > m_vertexIndices
btDX11Buffer< float > m_dx11LinksMaterialLinearStiffnessCoefficient
virtual btSoftBodyTriangleData & getTriangleData()
void generateBatches()
Generate (and later update) the batching for the entire link set.
float computeTriangleArea(const Vectormath::Aos::Point3 &vertex0, const Vectormath::Aos::Point3 &vertex1, const Vectormath::Aos::Point3 &vertex2)
void setZ(btScalar _z)
Set the z value.
virtual void copySoftBodyToVertexBuffer(const btSoftBody *const softBody, btVertexBufferDescriptor *vertexBuffer)
Output current computed vertex data to the vertex buffers for all cloths in the solver.
virtual BufferTypes getBufferType() const =0
Return the type of the vertex buffer descriptor.
virtual bool onAccelerator()
Return true if data is on the accelerator.
static char m_dx11LinksRestLength(d3dDevice, d3dDeviceContext,&m_linksRestLength, false)
float & getRestLengthSquared(int linkIndex)
Return reference to rest length squared for link linkIndex as stored on the host. ...
void normalizeNormalsAndAreas(int numVertices)
btAlignedObjectArray< int > m_triangleAddresses
Link addressing information for each cloth.
void setNumTriangles(int numTriangles)
The btCapsuleShape represents a capsule around the Y axis, there is also the btCapsuleShapeX aligned ...
int & getTriangleCount(int vertexIndex)
Get access to the array of how many triangles touch each vertex.
ID3D11Buffer * constBuffer
virtual void processCollision(btSoftBody *, const btCollisionObjectWrapper *)
The btCollisionShape class provides an interface for collision shapes that can be shared among btColl...
btDX11Buffer< float > m_dx11PerClothDragFactor
virtual ~btSoftBodyLinkDataDX11()
ID3D11Device * m_d3dDevice
btAlignedObjectArray< float > m_perClothVelocityCorrectionCoefficient
Velocity correction coefficient.
static char m_dx11LinksMaterialLinearStiffnessCoefficient(d3dDevice, d3dDeviceContext,&m_linksMaterialLinearStiffnessCoefficient, false)
float & getLinearStiffnessCoefficient(int linkIndex)
Return reference to linear stiffness coefficient for link linkIndex as stored on the host...
LinkNodePair & getVertexPair(int linkIndex)
Return reference to the vertex index pair for link linkIndex as stored on the host.
virtual void updateSoftBodies()
Perform necessary per-step updates of soft bodies such as recomputing normals and bounding boxes...
btDX11Buffer< int > m_dx11VertexTriangleCount
Class describing a vertex for input into the system.
btVector3 getColumn(int i) const
Get a column of the matrix as a vector.
btAlignedObjectArray< Vectormath::Aos::Vector3 > m_linksCLength
void setMaxTriangles(int maxTriangles)
btSoftBodyVertexDataDX11(ID3D11Device *d3dDevice, ID3D11DeviceContext *d3dDeviceContext)
ID3D11Device * m_dx11Device
btAlignedObjectArray< CollisionObjectIndices > m_perClothCollisionObjects
Collision shape details: pair of index of first collision shape for the cloth and number of collision...
virtual bool moveFromAccelerator(bool bCopy=false, bool bCopyMinimum=true)
Move data to host memory from the accelerator if bCopy is false.
void updateVelocitiesFromPositionsWithVelocities(float isolverdt)
DXFunctions::KernelDesc applyForcesKernel
void updateVelocitiesFromPositionsWithoutVelocities(float isolverdt)
void resetNormalsAndAreas(int numVertices)
btDX11Buffer< Vectormath::Aos::Vector3 > m_dx11VertexForceAccumulator
void updateBounds(const btVector3 &lowerBound, const btVector3 &upperBound)
Update the bounds in the btSoftBody object.
DXFunctions::KernelDesc addVelocityKernel
btDX11Buffer< float > m_dx11LinksLengthRatio
TriangleNodeSet getVertexSet() const
virtual ~btSoftBodyVertexDataDX11()
virtual void copySoftBodyToVertexBuffer(const btSoftBody *const softBody, btVertexBufferDescriptor *vertexBuffer)
Output current computed vertex data to the vertex buffers for all cloths in the solver.
void setNumLinks(int numLinks)
virtual ~btDX11SoftBodySolver()
static float4 normalize(const float4 &a)
bool copyFromGPU()
Copy the data back from the GPU without changing its state to be CPU-side.
const btScalar & getZ() const
Return the z value.
void clear()
clear the array, deallocated memory. Generally it is better to use array.resize(0), to reduce performance overhead of run-time memory (de)allocations.
btAlignedObjectArray< UIntVector3 > m_perClothMinBounds
Minimum bounds for each cloth.
btAlignedObjectArray< float > m_linkStrength
btDX11Buffer< float > m_dx11VertexInverseMass
float & getMassLSC(int linkIndex)
Return reference to the MassLSC value for link linkIndex as stored on the host.
static Vectormath::Aos::Vector3 toVector3(const btVector3 &vec)
virtual void createLinks(int numLinks)
Allocate enough space in all link-related arrays to fit numLinks links.
btAcceleratedSoftBodyInterface * findSoftBodyInterface(const btSoftBody *const softBody)
void setX(btScalar _x)
Set the x value.
bool m_enableUpdateBounds
DXFunctions::KernelDesc solvePositionsFromLinksKernel
btDX11Buffer< float > m_dx11VertexArea
btDX11Buffer< float > m_dx11LinkStrength
btDX11Buffer< float > m_dx11PerClothVelocityCorrectionCoefficient
float lengthSqr(const Vector3 &vec)
btSoftBodyWorldInfo * getWorldInfo()
void solveLinksForPosition(int startLink, int numLinks, float kst, float ti)
btAlignedObjectArray< float > m_perClothMediumDensity
Density of the medium in which each cloth sits.
btDX11Buffer< Vectormath::Aos::Vector3 > m_dx11VertexNormal
ID3D11Device * m_d3dDevice
int size() const
return the number of elements in the array
virtual ID3D11UnorderedAccessView * getDX11UAV() const
btDX11Buffer< float > m_dx11LinksRestLength
void setFirstVertex(int firstVertex)
const btVector3 & getWindVelocity()
Return the wind velocity for interaction with the air.
virtual SolverTypes getSolverType() const =0
Return the type of the solver.
void updatePositionsFromVelocities(float solverdt)
DXFunctions::KernelDesc solveCollisionsAndUpdateVelocitiesKernel
virtual bool onAccelerator()
Return true if data is on the accelerator.
KernelDesc compileComputeShaderFromString(const char *shaderString, const char *shaderName, int constBufferSize, D3D10_SHADER_MACRO *compileMacros=0)
Compile a compute shader kernel from a string and return the appropriate KernelDesc object...
DXFunctions::KernelDesc updateSoftBodiesKernel
virtual btSoftBodyVertexData & getVertexData()
btAlignedObjectArray< LinkNodePair > m_links
btAlignedObjectArray< float > m_perClothDampingFactor
Velocity damping factor.
SoftBody class to maintain information about a soft body instance within a solver.
virtual void setTriangleAt(const btSoftBodyTriangleData::TriangleDescription &triangle, int triangleIndex)
Insert the link described into the correct data structures assuming space has already been allocated ...
btSoftBodyLinkDataDX11 m_linkData
Link data for all cloths.
btDX11Buffer< float > m_dx11PerClothLiftFactor
DXFunctions::KernelDesc prepareLinksKernel
btAlignedObjectArray< int > m_linkAddresses
Link addressing information for each cloth.
DXFunctions::KernelDesc resetNormalsAndAreasKernel
virtual bool onAccelerator()
Return true if data is on the accelerator.
Class representing a link as a set of three indices into the vertex array.
btSoftBodySolver * getSoftBodySolver()
void setNumVertices(int numVertices)
const btVector3 & getAngularVelocity() const
btDX11Buffer< Vectormath::Aos::Vector3 > m_dx11PerClothWindVelocity
const btScalar & getY() const
Return the y value.
const btTransform & getWorldTransform() const
void setY(btScalar _y)
Set the y value.
virtual bool moveToAccelerator()
Move data from host memory to the accelerator.
DXFunctions::KernelDesc normalizeNormalsAndAreasKernel
static char * UpdatePositionsFromVelocitiesHLSLString
const btScalar & getX() const
Return the x value.
virtual void changedOnCPU()
Call if data has changed on the CPU.
The btRigidBody is the main class for rigid body objects.
virtual btSoftBodyLinkData & getLinkData()
btDX11Buffer< Vectormath::Aos::Vector3 > m_dx11Normal
float & getRestLength(int linkIndex)
Return reference to the rest length of link linkIndex as stored on the host.
btAlignedObjectArray< float > m_perClothFriction
Friction coefficient for each cloth.
btAlignedObjectArray< float > m_linksRestLengthSquared
virtual void solveConstraints(float solverdt)
Solve constraints for a set of soft bodies.
btAlignedObjectArray< BatchPair > m_batchStartLengths
Start and length values for computation batches over link data.
btAlignedObjectArray< float > m_linksLengthRatio
btDX11Buffer< CollisionShapeDescription > m_dx11CollisionObjectDetails
ID3D11DeviceContext * m_dx11Context
btAlignedObjectArray< float > m_linksMaterialLinearStiffnessCoefficient
void setMaxVertices(int maxVertices)
DXFunctions::KernelDesc integrateKernel
btAlignedObjectArray< Vectormath::Aos::Vector3 > m_perClothWindVelocity
Wind velocity to be applied normal to all non-static vertices in the solver.
virtual int getVertexStride() const
Return the vertex stride in number of floats between vertices.
static Vectormath::Aos::Transform3 toTransform3(const btTransform &transform)
virtual void copyBackToSoftBodies(bool bMove=true)
Copy necessary data back to the original soft body source objects.
static char m_dx11LinksCLength(d3dDevice, d3dDeviceContext,&m_linksCLength, false)
const btCollisionShape * getCollisionShape() const
void ApplyClampedForce(float solverdt, const Vectormath::Aos::Vector3 &force, const Vectormath::Aos::Vector3 &vertexVelocity, float inverseMass, Vectormath::Aos::Vector3 &vertexForce)
btVector3 can be used to represent 3D points and vectors.
int m_numberOfVelocityIterations
virtual int getVertexOffset() const
Return the vertex offset in floats from the base pointer.
btDX11Buffer< LinkNodePair > m_dx11Links
btAlignedObjectArray< btAcceleratedSoftBodyInterface * > m_softBodySet
Cloths owned by this solver.
Vectormath::Aos::Vector3 angularVelocity
virtual void applyForces(float solverdt)
Class describing a link for input into the system.
virtual void predictMotion(float solverdt)
Predict motion of soft bodies into next timestep.
btDX11Buffer< int > m_dx11ClothIdentifier
Wrapper for vertex data information.
static char m_dx11LinkStrength(d3dDevice, d3dDeviceContext,&m_linkStrength, false)
void executeUpdateSoftBodies(int firstTriangle, int numTriangles)
virtual bool moveFromAccelerator()
Move data from host memory from the accelerator.
btDX11Buffer< float > m_dx11LinksMassLSC
Vectormath::Aos::Vector3 & getNormal(int vertexIndex)
Return a reference to the normal of vertex vertexIndex as stored on the host.
virtual bool moveToAccelerator()
Move data from host memory to the accelerator.
btAlignedObjectArray< float > m_perClothDragFactor
Drag parameter for wind effect on cloth.
void resize(int newsize, const T &fillData=T())
btDX11Buffer< float > m_dx11PerClothMediumDensity
btSoftBodyTriangleDataDX11(ID3D11Device *d3dDevice, ID3D11DeviceContext *d3dDeviceContext)
ID3D11ShaderResourceView *& getSRV()
ID3D11DeviceContext * m_d3dDeviceContext
virtual ~btSoftBodyTriangleDataDX11()
Entry in the collision shape array.
btAlignedObjectArray< float > m_linksMassLSC
float & getInverseMass(int vertexIndex)
Return a reference to the inverse mass of vertex vertexIndex as stored on the host.
int findLinearSearch(const T &key) const
virtual bool moveToAccelerator()
Move data from host memory to the accelerator.
virtual int getNormalOffset() const
Return the vertex offset in floats from the base pointer.
btDX11Buffer< UIntVector3 > m_dx11PerClothMinBounds
Vectormath::Aos::Point3 & getPosition(int vertexIndex)
Return a reference to the position of vertex vertexIndex as stored on the host.
btSoftBodyVertexDataDX11 m_vertexData
btScalar getFriction() const
virtual float * getBasePointer() const
Return the base pointer in memory to the first vertex.
ID3D11UnorderedAccessView *& getUAV()
static float4 cross(const float4 &a, const float4 &b)
btDX11Buffer< Vectormath::Aos::Vector3 > m_dx11LinksCLength
btAlignedObjectArray< float > m_area
btAlignedObjectArray< CollisionShapeDescription > m_collisionObjectDetails
Collision shapes being passed across to the cloths in this solver.
virtual bool checkInitialized()
Ensure that this solver is initialized.
float getTimeScale()
Return the timescale that the simulation is using.
btDX11Buffer< float > m_dx11LinksRestLengthSquared
btAlignedObjectArray< float > m_perClothLiftFactor
Lift parameter for wind effect on cloth.
btDX11Buffer< Vectormath::Aos::Point3 > m_dx11VertexPosition
btAlignedObjectArray< float > m_linksRestLength
void solveLinksForVelocity(int startLink, int numLinks, float kst)
DXFunctions::KernelDesc updateVelocitiesFromPositionsWithoutVelocitiesKernel
static char m_d3dDeviceContext(d3dDeviceContext)
void setFirstLink(int firstLink)
btAlignedObjectArray< BatchPair > m_batchStartLengths
Start and length values for computation batches over link data.
const btVector3 & getLinearVelocity() const
Vectormath::Aos::Vector3 linearVelocity
const TriangleNodeSet & getVertexSet(int triangleIndex)
Return the vertex index set for triangle triangleIndex as stored on the host.
btSoftBodyTriangleDataDX11 m_triangleData
float dot(const Quat &quat0, const Quat &quat1)
int getNumVertices() const
DXFunctions::KernelDesc updateVelocitiesFromPositionsWithVelocitiesKernel
void setLinkStrength(float strength)
ID3D11DeviceContext * m_d3dDeviceContext
int getFirstVertex() const
void prepareCollisionConstraints()
Sort the collision object details array and generate indexing into it for the per-cloth collision obj...
btDX11Buffer< btSoftBodyTriangleData::TriangleNodeSet > m_dx11VertexIndices
static char * PrepareLinksHLSLString
btSoftBodyLinkDataDX11(ID3D11Device *d3dDevice, ID3D11DeviceContext *d3dDeviceContext)
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
int findSoftBodyIndex(const btSoftBody *const softBody)
void solveCollisionsAndUpdateVelocities(float isolverdt)
virtual bool moveFromAccelerator()
Move data from host memory from the accelerator.
btDX11Buffer< float > m_dx11PerClothFriction
HRESULT(WINAPI * CompileFromMemoryFunc)(LPCSTR, SIZE_T, LPCSTR, const D3D10_SHADER_MACRO *, LPD3D10INCLUDE, LPCSTR, LPCSTR, UINT, UINT, ID3DX11ThreadPump *, ID3D10Blob **, ID3D10Blob **, HRESULT *)
void setVertexAt(const VertexDescription &vertex, int vertexIndex)
btDX11Buffer< UIntVector3 > m_dx11PerClothMaxBounds
btDX11SoftBodySolver(ID3D11Device *dx11Device, ID3D11DeviceContext *dx11Context, DXFunctions::CompileFromMemoryFunc dx11CompileFromMemory=&D3DX11CompileFromMemory)
bool m_updateSolverConstants
Variable to define whether we need to update solver constants on the next iteration.
virtual bool buildShaders()
void quickSort(const L &CompareFunc)
virtual bool hasNormals() const
virtual void optimize(btAlignedObjectArray< btSoftBody * > &softBodies, bool forceUpdate=false)
Optimize soft bodies in this solver.
virtual int getNormalStride() const
Return the vertex stride in number of floats between vertices.
DXFunctions::KernelDesc vSolveLinksKernel
bool m_shadersInitialized
int m_numberOfPositionIterations
const btCollisionObject * getCollisionObject() const
static char m_dx11LinksRestLengthSquared(d3dDevice, d3dDeviceContext,&m_linksRestLengthSquared, false)
btDX11Buffer< Vectormath::Aos::Vector3 > m_dx11PerClothAcceleration
void setFirstTriangle(int firstTriangle)
virtual void createLinks(int numLinks)
Allocate enough space in all link-related arrays to fit numLinks links.
virtual void updateConstants(float timeStep)
virtual void prepareLinks()
btSoftBody * getSoftBody()
bool moveFromGPU()
Move the data back from the GPU if it is on there and isn't read only.
btAlignedObjectArray< UIntVector3 > m_perClothMaxBounds
Maximum bounds for each cloth.
btAlignedObjectArray< Vectormath::Aos::Vector3 > m_perClothAcceleration
Acceleration value to be applied to all non-static vertices in the solver.