Deterministic simulation for concave and compound collision shapes: added childShapeA/B to b3Contact4 + sort on them

Use tetrahedra instead of barrel for convex demo (until performance for edge-edge is improved)
Increased #overlapping pair capacity from 12 to 16 / objec
This commit is contained in:
erwincoumans
2013-07-17 22:42:50 -07:00
parent ab125fbb6d
commit 733f9027fb
26 changed files with 358 additions and 70 deletions

View File

@@ -49,6 +49,12 @@ typedef struct
int m_bodyAPtrAndSignBit;//x:m_bodyAPtr, y:m_bodyBPtr
int m_bodyBPtrAndSignBit;
int m_childIndexA;
int m_childIndexB;
int m_unused1;
int m_unused2;
} Contact4;
typedef struct
@@ -483,6 +489,9 @@ void computeContactSphereConvex(int pairIndex,
c->m_bodyAPtrAndSignBit = rigidBodies[bodyIndexA].m_invMass==0?-bodyIndexA:bodyIndexA;
c->m_bodyBPtrAndSignBit = rigidBodies[bodyIndexB].m_invMass==0?-bodyIndexB:bodyIndexB;
c->m_worldPos[0] = pOnB1;
c->m_childIndexA = -1;
c->m_childIndexB = -1;
GET_NPOINTS(*c) = 1;
}
@@ -705,6 +714,8 @@ void computeContactPlaneConvex(int pairIndex,
c->m_batchIdx = pairIndex;
c->m_bodyAPtrAndSignBit = rigidBodies[bodyIndexA].m_invMass==0?-bodyIndexA:bodyIndexA;
c->m_bodyBPtrAndSignBit = rigidBodies[bodyIndexB].m_invMass==0?-bodyIndexB:bodyIndexB;
c->m_childIndexA = -1;
c->m_childIndexB = -1;
switch (numReducedPoints)
{
@@ -783,6 +794,8 @@ void computeContactPlaneSphere(int pairIndex,
c->m_bodyAPtrAndSignBit = rigidBodies[bodyIndexA].m_invMass==0?-bodyIndexA:bodyIndexA;
c->m_bodyBPtrAndSignBit = rigidBodies[bodyIndexB].m_invMass==0?-bodyIndexB:bodyIndexB;
c->m_worldPos[0] = pOnB1;
c->m_childIndexA = -1;
c->m_childIndexB = -1;
GET_NPOINTS(*c) = 1;
}//if (dstIdx < numPairs)
}//if (hasCollision)
@@ -955,6 +968,8 @@ __kernel void primitiveContactsKernel( __global const int2* pairs,
c->m_bodyAPtrAndSignBit = rigidBodies[bodyA].m_invMass==0?-bodyA:bodyA;
c->m_bodyBPtrAndSignBit = rigidBodies[bodyB].m_invMass==0?-bodyB:bodyB;
c->m_worldPos[0] = contactPosB;
c->m_childIndexA = -1;
c->m_childIndexB = -1;
GET_NPOINTS(*c) = 1;
}//if (dstIdx < numPairs)
}//if ( len <= (radiusA+radiusB))
@@ -1163,7 +1178,8 @@ void computeContactSphereTriangle(int pairIndex,
float4 spherePos2,
float radius,
float4 pos,
float4 quat
float4 quat,
int faceIndex
)
{
@@ -1176,7 +1192,7 @@ void computeContactSphereTriangle(int pairIndex,
float4 closestPnt = (float4)(0, 0, 0, 0);
float4 hitNormalWorld = (float4)(0, 0, 0, 0);
float minDist = -1000000.f;
bool bCollide = true;
bool bCollide = false;
//////////////////////////////////////
@@ -1251,11 +1267,12 @@ void computeContactSphereTriangle(int pairIndex,
closestPnt = contactPoint;
float4 contactToCenter = sphereCenter - contactPoint;
minDist = length(contactToCenter);
if (minDist>0.f)
if (minDist>FLT_EPSILON)
{
hitNormalWorld = normalize(contactToCenter);//*(1./minDist);
bCollide = true;
}
bCollide = true;
}
@@ -1273,19 +1290,29 @@ void computeContactSphereTriangle(int pairIndex,
{
pOnB1.w = actualDepth;
int dstIdx;
AppendInc( nGlobalContactsOut, dstIdx );
if (dstIdx < maxContactCapacity)
float lenSqr = dot3F4(normalOnSurfaceB1,normalOnSurfaceB1);
if (lenSqr>FLT_EPSILON)
{
__global Contact4* c = &globalContactsOut[dstIdx];
c->m_worldNormal = normalOnSurfaceB1;
c->m_coeffs = (u32)(0.f*0xffff) | ((u32)(0.7f*0xffff)<<16);
c->m_batchIdx = pairIndex;
c->m_bodyAPtrAndSignBit = rigidBodies[bodyIndexA].m_invMass==0?-bodyIndexA:bodyIndexA;
c->m_bodyBPtrAndSignBit = rigidBodies[bodyIndexB].m_invMass==0?-bodyIndexB:bodyIndexB;
c->m_worldPos[0] = pOnB1;
GET_NPOINTS(*c) = 1;
}
AppendInc( nGlobalContactsOut, dstIdx );
if (dstIdx < maxContactCapacity)
{
__global Contact4* c = &globalContactsOut[dstIdx];
c->m_worldNormal = normalOnSurfaceB1;
c->m_coeffs = (u32)(0.f*0xffff) | ((u32)(0.7f*0xffff)<<16);
c->m_batchIdx = pairIndex;
c->m_bodyAPtrAndSignBit = rigidBodies[bodyIndexA].m_invMass==0?-bodyIndexA:bodyIndexA;
c->m_bodyBPtrAndSignBit = rigidBodies[bodyIndexB].m_invMass==0?-bodyIndexB:bodyIndexB;
c->m_worldPos[0] = pOnB1;
c->m_childIndexA = -1;
c->m_childIndexB = faceIndex;
GET_NPOINTS(*c) = 1;
}
}
}
}//if (hasCollision)
@@ -1346,7 +1373,7 @@ __kernel void findConcaveSphereContactsKernel( __global int4* concavePairs,
rigidBodies,collidables,
verticesA,
globalContactsOut, nGlobalContactsOut,maxContactCapacity,
spherePos,sphereRadius,convexPos,convexOrn);
spherePos,sphereRadius,convexPos,convexOrn, f);
return;
}

View File

@@ -51,6 +51,12 @@ static const char* primitiveContactsKernelsCL= \
"\n"
" int m_bodyAPtrAndSignBit;//x:m_bodyAPtr, y:m_bodyBPtr\n"
" int m_bodyBPtrAndSignBit;\n"
"\n"
" int m_childIndexA;\n"
" int m_childIndexB;\n"
" int m_unused1;\n"
" int m_unused2;\n"
"\n"
"} Contact4;\n"
"\n"
"typedef struct \n"
@@ -485,6 +491,9 @@ static const char* primitiveContactsKernelsCL= \
" c->m_bodyAPtrAndSignBit = rigidBodies[bodyIndexA].m_invMass==0?-bodyIndexA:bodyIndexA;\n"
" c->m_bodyBPtrAndSignBit = rigidBodies[bodyIndexB].m_invMass==0?-bodyIndexB:bodyIndexB;\n"
" c->m_worldPos[0] = pOnB1;\n"
" c->m_childIndexA = -1;\n"
" c->m_childIndexB = -1;\n"
"\n"
" GET_NPOINTS(*c) = 1;\n"
" } \n"
"\n"
@@ -707,6 +716,8 @@ static const char* primitiveContactsKernelsCL= \
" c->m_batchIdx = pairIndex;\n"
" c->m_bodyAPtrAndSignBit = rigidBodies[bodyIndexA].m_invMass==0?-bodyIndexA:bodyIndexA;\n"
" c->m_bodyBPtrAndSignBit = rigidBodies[bodyIndexB].m_invMass==0?-bodyIndexB:bodyIndexB;\n"
" c->m_childIndexA = -1;\n"
" c->m_childIndexB = -1;\n"
"\n"
" switch (numReducedPoints)\n"
" {\n"
@@ -785,6 +796,8 @@ static const char* primitiveContactsKernelsCL= \
" c->m_bodyAPtrAndSignBit = rigidBodies[bodyIndexA].m_invMass==0?-bodyIndexA:bodyIndexA;\n"
" c->m_bodyBPtrAndSignBit = rigidBodies[bodyIndexB].m_invMass==0?-bodyIndexB:bodyIndexB;\n"
" c->m_worldPos[0] = pOnB1;\n"
" c->m_childIndexA = -1;\n"
" c->m_childIndexB = -1;\n"
" GET_NPOINTS(*c) = 1;\n"
" }//if (dstIdx < numPairs)\n"
" }//if (hasCollision)\n"
@@ -957,6 +970,8 @@ static const char* primitiveContactsKernelsCL= \
" c->m_bodyAPtrAndSignBit = rigidBodies[bodyA].m_invMass==0?-bodyA:bodyA;\n"
" c->m_bodyBPtrAndSignBit = rigidBodies[bodyB].m_invMass==0?-bodyB:bodyB;\n"
" c->m_worldPos[0] = contactPosB;\n"
" c->m_childIndexA = -1;\n"
" c->m_childIndexB = -1;\n"
" GET_NPOINTS(*c) = 1;\n"
" }//if (dstIdx < numPairs)\n"
" }//if ( len <= (radiusA+radiusB))\n"
@@ -1165,7 +1180,8 @@ static const char* primitiveContactsKernelsCL= \
" float4 spherePos2,\n"
" float radius,\n"
" float4 pos,\n"
" float4 quat\n"
" float4 quat,\n"
" int faceIndex\n"
" )\n"
"{\n"
"\n"
@@ -1178,7 +1194,7 @@ static const char* primitiveContactsKernelsCL= \
" float4 closestPnt = (float4)(0, 0, 0, 0);\n"
" float4 hitNormalWorld = (float4)(0, 0, 0, 0);\n"
" float minDist = -1000000.f;\n"
" bool bCollide = true;\n"
" bool bCollide = false;\n"
"\n"
" \n"
" //////////////////////////////////////\n"
@@ -1253,11 +1269,12 @@ static const char* primitiveContactsKernelsCL= \
" closestPnt = contactPoint;\n"
" float4 contactToCenter = sphereCenter - contactPoint;\n"
" minDist = length(contactToCenter);\n"
" if (minDist>0.f)\n"
" if (minDist>FLT_EPSILON)\n"
" {\n"
" hitNormalWorld = normalize(contactToCenter);//*(1./minDist);\n"
" bCollide = true;\n"
" }\n"
" bCollide = true;\n"
" \n"
" }\n"
"\n"
"\n"
@@ -1275,19 +1292,29 @@ static const char* primitiveContactsKernelsCL= \
" {\n"
" pOnB1.w = actualDepth;\n"
" int dstIdx;\n"
" AppendInc( nGlobalContactsOut, dstIdx );\n"
"\n"
" \n"
" if (dstIdx < maxContactCapacity)\n"
" float lenSqr = dot3F4(normalOnSurfaceB1,normalOnSurfaceB1);\n"
" if (lenSqr>FLT_EPSILON)\n"
" {\n"
" __global Contact4* c = &globalContactsOut[dstIdx];\n"
" c->m_worldNormal = normalOnSurfaceB1;\n"
" c->m_coeffs = (u32)(0.f*0xffff) | ((u32)(0.7f*0xffff)<<16);\n"
" c->m_batchIdx = pairIndex;\n"
" c->m_bodyAPtrAndSignBit = rigidBodies[bodyIndexA].m_invMass==0?-bodyIndexA:bodyIndexA;\n"
" c->m_bodyBPtrAndSignBit = rigidBodies[bodyIndexB].m_invMass==0?-bodyIndexB:bodyIndexB;\n"
" c->m_worldPos[0] = pOnB1;\n"
" GET_NPOINTS(*c) = 1;\n"
" } \n"
" AppendInc( nGlobalContactsOut, dstIdx );\n"
" \n"
" if (dstIdx < maxContactCapacity)\n"
" {\n"
" __global Contact4* c = &globalContactsOut[dstIdx];\n"
" c->m_worldNormal = normalOnSurfaceB1;\n"
" c->m_coeffs = (u32)(0.f*0xffff) | ((u32)(0.7f*0xffff)<<16);\n"
" c->m_batchIdx = pairIndex;\n"
" c->m_bodyAPtrAndSignBit = rigidBodies[bodyIndexA].m_invMass==0?-bodyIndexA:bodyIndexA;\n"
" c->m_bodyBPtrAndSignBit = rigidBodies[bodyIndexB].m_invMass==0?-bodyIndexB:bodyIndexB;\n"
" c->m_worldPos[0] = pOnB1;\n"
"\n"
" c->m_childIndexA = -1;\n"
" c->m_childIndexB = faceIndex;\n"
"\n"
" GET_NPOINTS(*c) = 1;\n"
" } \n"
" }\n"
"\n"
" }\n"
" }//if (hasCollision)\n"
@@ -1348,7 +1375,7 @@ static const char* primitiveContactsKernelsCL= \
" rigidBodies,collidables,\n"
" verticesA,\n"
" globalContactsOut, nGlobalContactsOut,maxContactCapacity,\n"
" spherePos,sphereRadius,convexPos,convexOrn);\n"
" spherePos,sphereRadius,convexPos,convexOrn, f);\n"
"\n"
" return;\n"
" }\n"

View File

@@ -50,6 +50,12 @@ typedef struct
int m_bodyAPtrAndSignBit;//x:m_bodyAPtr, y:m_bodyBPtr
int m_bodyBPtrAndSignBit;
int m_childIndexA;
int m_childIndexB;
int m_unused1;
int m_unused2;
} Contact4;
@@ -924,6 +930,8 @@ __kernel void extractManifoldAndAddContactKernel(__global const int2* pairs,
int bodyB = pairs[pairIndex].y;
c->m_bodyAPtrAndSignBit = rigidBodies[bodyA].m_invMass==0 ? -bodyA:bodyA;
c->m_bodyBPtrAndSignBit = rigidBodies[bodyB].m_invMass==0 ? -bodyB:bodyB;
c->m_childIndexA = -1;
c->m_childIndexB = -1;
for (int i=0;i<nContacts;i++)
{
c->m_worldPos[i] = localPoints[contactIdx[i]];
@@ -1034,6 +1042,8 @@ __kernel void clipHullHullKernel( __global const int2* pairs,
int bodyB = pairs[pairIndex].y;
c->m_bodyAPtrAndSignBit = rigidBodies[bodyA].m_invMass==0?-bodyA:bodyA;
c->m_bodyBPtrAndSignBit = rigidBodies[bodyB].m_invMass==0?-bodyB:bodyB;
c->m_childIndexA = -1;
c->m_childIndexB = -1;
for (int i=0;i<nReducedContacts;i++)
{
@@ -1165,7 +1175,8 @@ __kernel void clipCompoundsHullHullKernel( __global const int4* gpuCompoundPai
int bodyB = gpuCompoundPairs[pairIndex].y;
c->m_bodyAPtrAndSignBit = rigidBodies[bodyA].m_invMass==0?-bodyA:bodyA;
c->m_bodyBPtrAndSignBit = rigidBodies[bodyB].m_invMass==0?-bodyB:bodyB;
c->m_childIndexA = childShapeIndexA;
c->m_childIndexB = childShapeIndexB;
for (int i=0;i<nReducedContacts;i++)
{
c->m_worldPos[i] = pointsIn[contactIdx[i]];
@@ -1241,6 +1252,9 @@ __kernel void sphereSphereCollisionKernel( __global const int2* pairs,
c->m_bodyAPtrAndSignBit = rigidBodies[bodyA].m_invMass==0?-bodyA:bodyA;
c->m_bodyBPtrAndSignBit = rigidBodies[bodyB].m_invMass==0?-bodyB:bodyB;
c->m_worldPos[0] = contactPosB;
c->m_childIndexA = -1;
c->m_childIndexB = -1;
GET_NPOINTS(*c) = 1;
}//if (dstIdx < numPairs)
}//if ( len <= (radiusA+radiusB))
@@ -1285,6 +1299,7 @@ __kernel void clipHullHullConcaveConvexKernel( __global int4* concavePairsIn,
int bodyIndexA = concavePairsIn[i].x;
int bodyIndexB = concavePairsIn[i].y;
int f = concavePairsIn[i].z;
int childShapeIndexA = f;
int collidableIndexA = rigidBodies[bodyIndexA].m_collidableIdx;
int collidableIndexB = rigidBodies[bodyIndexB].m_collidableIdx;
@@ -1411,12 +1426,13 @@ __kernel void clipHullHullConcaveConvexKernel( __global int4* concavePairsIn,
float4 sepAxis = separatingNormals[i];
int shapeTypeB = collidables[collidableIndexB].m_shapeType;
int childShapeIndexB =-1;
if (shapeTypeB==SHAPE_COMPOUND_OF_CONVEX_HULLS)
{
///////////////////
///compound shape support
int childShapeIndexB = concavePairsIn[pairIndex].w;
childShapeIndexB = concavePairsIn[pairIndex].w;
int childColIndexB = gpuChildShapes[childShapeIndexB].m_shapeIndex;
shapeIndexB = collidables[childColIndexB].m_shapeIndex;
float4 childPosB = gpuChildShapes[childShapeIndexB].m_childPosition;
@@ -1468,7 +1484,8 @@ __kernel void clipHullHullConcaveConvexKernel( __global int4* concavePairsIn,
int bodyB = concavePairsIn[pairIndex].y;
c->m_bodyAPtrAndSignBit = rigidBodies[bodyA].m_invMass==0?-bodyA:bodyA;
c->m_bodyBPtrAndSignBit = rigidBodies[bodyB].m_invMass==0?-bodyB:bodyB;
c->m_childIndexA = childShapeIndexA;
c->m_childIndexB = childShapeIndexB;
for (int i=0;i<nReducedContacts;i++)
{
c->m_worldPos[i] = pointsIn[contactIdx[i]];
@@ -1888,7 +1905,9 @@ __kernel void newContactReductionKernel( __global const int2* pairs,
int bodyB = pairs[pairIndex].y;
c->m_bodyAPtrAndSignBit = rigidBodies[bodyA].m_invMass==0?-bodyA:bodyA;
c->m_bodyBPtrAndSignBit = rigidBodies[bodyB].m_invMass==0?-bodyB:bodyB;
c->m_childIndexA =-1;
c->m_childIndexB =-1;
switch (nReducedContacts)
{
case 4:

View File

@@ -52,6 +52,12 @@ static const char* satClipKernelsCL= \
"\n"
" int m_bodyAPtrAndSignBit;//x:m_bodyAPtr, y:m_bodyBPtr\n"
" int m_bodyBPtrAndSignBit;\n"
"\n"
" int m_childIndexA;\n"
" int m_childIndexB;\n"
" int m_unused1;\n"
" int m_unused2;\n"
"\n"
"} Contact4;\n"
"\n"
"\n"
@@ -926,6 +932,8 @@ static const char* satClipKernelsCL= \
" int bodyB = pairs[pairIndex].y;\n"
" c->m_bodyAPtrAndSignBit = rigidBodies[bodyA].m_invMass==0 ? -bodyA:bodyA;\n"
" c->m_bodyBPtrAndSignBit = rigidBodies[bodyB].m_invMass==0 ? -bodyB:bodyB;\n"
" c->m_childIndexA = -1;\n"
" c->m_childIndexB = -1;\n"
" for (int i=0;i<nContacts;i++)\n"
" {\n"
" c->m_worldPos[i] = localPoints[contactIdx[i]];\n"
@@ -1036,6 +1044,8 @@ static const char* satClipKernelsCL= \
" int bodyB = pairs[pairIndex].y;\n"
" c->m_bodyAPtrAndSignBit = rigidBodies[bodyA].m_invMass==0?-bodyA:bodyA;\n"
" c->m_bodyBPtrAndSignBit = rigidBodies[bodyB].m_invMass==0?-bodyB:bodyB;\n"
" c->m_childIndexA = -1;\n"
" c->m_childIndexB = -1;\n"
"\n"
" for (int i=0;i<nReducedContacts;i++)\n"
" {\n"
@@ -1167,7 +1177,8 @@ static const char* satClipKernelsCL= \
" int bodyB = gpuCompoundPairs[pairIndex].y;\n"
" c->m_bodyAPtrAndSignBit = rigidBodies[bodyA].m_invMass==0?-bodyA:bodyA;\n"
" c->m_bodyBPtrAndSignBit = rigidBodies[bodyB].m_invMass==0?-bodyB:bodyB;\n"
"\n"
" c->m_childIndexA = childShapeIndexA;\n"
" c->m_childIndexB = childShapeIndexB;\n"
" for (int i=0;i<nReducedContacts;i++)\n"
" {\n"
" c->m_worldPos[i] = pointsIn[contactIdx[i]];\n"
@@ -1243,6 +1254,9 @@ static const char* satClipKernelsCL= \
" c->m_bodyAPtrAndSignBit = rigidBodies[bodyA].m_invMass==0?-bodyA:bodyA;\n"
" c->m_bodyBPtrAndSignBit = rigidBodies[bodyB].m_invMass==0?-bodyB:bodyB;\n"
" c->m_worldPos[0] = contactPosB;\n"
" c->m_childIndexA = -1;\n"
" c->m_childIndexB = -1;\n"
"\n"
" GET_NPOINTS(*c) = 1;\n"
" }//if (dstIdx < numPairs)\n"
" }//if ( len <= (radiusA+radiusB))\n"
@@ -1287,6 +1301,7 @@ static const char* satClipKernelsCL= \
" int bodyIndexA = concavePairsIn[i].x;\n"
" int bodyIndexB = concavePairsIn[i].y;\n"
" int f = concavePairsIn[i].z;\n"
" int childShapeIndexA = f;\n"
" \n"
" int collidableIndexA = rigidBodies[bodyIndexA].m_collidableIdx;\n"
" int collidableIndexB = rigidBodies[bodyIndexB].m_collidableIdx;\n"
@@ -1413,12 +1428,13 @@ static const char* satClipKernelsCL= \
" float4 sepAxis = separatingNormals[i];\n"
" \n"
" int shapeTypeB = collidables[collidableIndexB].m_shapeType;\n"
" int childShapeIndexB =-1;\n"
" if (shapeTypeB==SHAPE_COMPOUND_OF_CONVEX_HULLS)\n"
" {\n"
" ///////////////////\n"
" ///compound shape support\n"
" \n"
" int childShapeIndexB = concavePairsIn[pairIndex].w;\n"
" childShapeIndexB = concavePairsIn[pairIndex].w;\n"
" int childColIndexB = gpuChildShapes[childShapeIndexB].m_shapeIndex;\n"
" shapeIndexB = collidables[childColIndexB].m_shapeIndex;\n"
" float4 childPosB = gpuChildShapes[childShapeIndexB].m_childPosition;\n"
@@ -1470,7 +1486,8 @@ static const char* satClipKernelsCL= \
" int bodyB = concavePairsIn[pairIndex].y;\n"
" c->m_bodyAPtrAndSignBit = rigidBodies[bodyA].m_invMass==0?-bodyA:bodyA;\n"
" c->m_bodyBPtrAndSignBit = rigidBodies[bodyB].m_invMass==0?-bodyB:bodyB;\n"
"\n"
" c->m_childIndexA = childShapeIndexA;\n"
" c->m_childIndexB = childShapeIndexB;\n"
" for (int i=0;i<nReducedContacts;i++)\n"
" {\n"
" c->m_worldPos[i] = pointsIn[contactIdx[i]];\n"
@@ -1890,7 +1907,9 @@ static const char* satClipKernelsCL= \
" int bodyB = pairs[pairIndex].y;\n"
" c->m_bodyAPtrAndSignBit = rigidBodies[bodyA].m_invMass==0?-bodyA:bodyA;\n"
" c->m_bodyBPtrAndSignBit = rigidBodies[bodyB].m_invMass==0?-bodyB:bodyB;\n"
" \n"
" c->m_childIndexA =-1;\n"
" c->m_childIndexB =-1;\n"
"\n"
" switch (nReducedContacts)\n"
" {\n"
" case 4:\n"