change lcpp Lua preprocessor, to keep #defines and comments, remove empty lines

remove duplicate data in b3Contact4 (now in btContact4Data shared between CPU/C++ and OpenCL)
OpenCL kernels use #include "Bullet3Collision/NarrowPhaseCollision/shared/b3Contact4Data.h"
Increase number of batches back to 250 (from 50), need to fix this hard coded number (see https://github.com/erwincoumans/bullet3/issues/12)
Work towards GJK/EPA, in addition to SAT/clipping (early on)
This commit is contained in:
erwincoumans
2013-08-08 12:24:09 -07:00
parent 46a08e3282
commit 3bf003ace1
50 changed files with 920 additions and 2731 deletions

View File

@@ -1,67 +1,62 @@
//this file is autogenerated using stringify.bat (premake --stringify) in the build folder of this project
static const char* primitiveContactsKernelsCL= \
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"#ifndef B3_CONTACT4DATA_H\n"
"#define B3_CONTACT4DATA_H\n"
"#ifndef B3_FLOAT4_H\n"
"#define B3_FLOAT4_H\n"
"#ifndef B3_PLATFORM_DEFINITIONS_H\n"
"#define B3_PLATFORM_DEFINITIONS_H\n"
"struct MyTest\n"
"{\n"
" int bla;\n"
"};\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"#endif\n"
"#ifdef __cplusplus\n"
"#else//bla\n"
" typedef float4 b3Float4;\n"
"\n"
"\n"
"\n"
"\n"
"typedef struct\n"
"#endif \n"
"#endif //B3_FLOAT4_H\n"
"typedef struct b3Contact4Data b3Contact4Data_t;\n"
"struct b3Contact4Data\n"
"{\n"
" b3Float4 m_worldPos[4];\n"
"// b3Float4 m_localPosB[4];\n"
" b3Float4 m_worldNormal; // w: m_nPoints\n"
" unsigned int m_coeffs;\n"
" unsigned int m_batchIdx;\n"
"\n"
" unsigned short m_restituitionCoeffCmp;\n"
" unsigned short m_frictionCoeffCmp;\n"
" int m_batchIdx;\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"
"} b3Contact4Data;\n"
"\n"
"\n"
"\n"
" b3Float4 m_localPosA;\n"
"};\n"
"inline int b3Contact4Data_getNumPoints(const struct b3Contact4Data* contact)\n"
"{\n"
" return (int)contact->m_worldNormal.w;\n"
"};\n"
"inline void b3Contact4Data_setNumPoints(struct b3Contact4Data* contact, int numPoints)\n"
"{\n"
" contact->m_worldNormal.w = (float)numPoints;\n"
"};\n"
"#endif //B3_CONTACT4DATA_H\n"
"#define SHAPE_CONVEX_HULL 3\n"
"#define SHAPE_PLANE 4\n"
"#define SHAPE_CONCAVE_TRIMESH 5\n"
"#define SHAPE_COMPOUND_OF_CONVEX_HULLS 6\n"
"#define SHAPE_SPHERE 7\n"
"\n"
"\n"
"#pragma OPENCL EXTENSION cl_amd_printf : enable\n"
"#pragma OPENCL EXTENSION cl_khr_local_int32_base_atomics : enable\n"
"#pragma OPENCL EXTENSION cl_khr_global_int32_base_atomics : enable\n"
"#pragma OPENCL EXTENSION cl_khr_local_int32_extended_atomics : enable\n"
"#pragma OPENCL EXTENSION cl_khr_global_int32_extended_atomics : enable\n"
"\n"
"#ifdef cl_ext_atomic_counters_32\n"
"#pragma OPENCL EXTENSION cl_ext_atomic_counters_32 : enable\n"
"#else\n"
"#define counter32_t volatile __global int*\n"
"#endif\n"
"\n"
"#define GET_GROUP_IDX get_group_id(0)\n"
"#define GET_LOCAL_IDX get_local_id(0)\n"
"#define GET_GLOBAL_IDX get_global_id(0)\n"
@@ -75,15 +70,9 @@ static const char* primitiveContactsKernelsCL= \
"#define AtomAdd(x, value) atom_add(&(x), value)\n"
"#define AtomCmpxhg(x, cmp, value) atom_cmpxchg( &(x), cmp, value )\n"
"#define AtomXhg(x, value) atom_xchg ( &(x), value )\n"
"\n"
"#define max2 max\n"
"#define min2 min\n"
"\n"
"typedef unsigned int u32;\n"
"\n"
"\n"
"\n"
"\n"
"typedef struct \n"
"{\n"
" union\n"
@@ -99,7 +88,6 @@ static const char* primitiveContactsKernelsCL= \
" int m_maxIndices[4];\n"
" };\n"
"} btAabbCL;\n"
"\n"
"///keep this in sync with btCollidable.h\n"
"typedef struct\n"
"{\n"
@@ -109,7 +97,6 @@ static const char* primitiveContactsKernelsCL= \
" int m_shapeIndex;\n"
" \n"
"} btCollidableGpu;\n"
"\n"
"typedef struct\n"
"{\n"
" float4 m_childPosition;\n"
@@ -119,23 +106,18 @@ static const char* primitiveContactsKernelsCL= \
" int m_unused1;\n"
" int m_unused2;\n"
"} btGpuChildShape;\n"
"\n"
"#define GET_NPOINTS(x) (x).m_worldNormal.w\n"
"\n"
"typedef struct\n"
"{\n"
" float4 m_pos;\n"
" float4 m_quat;\n"
" float4 m_linVel;\n"
" float4 m_angVel;\n"
"\n"
" u32 m_collidableIdx; \n"
" float m_invMass;\n"
" float m_restituitionCoeff;\n"
" float m_frictionCoeff;\n"
"} BodyData;\n"
"\n"
"\n"
"typedef struct \n"
"{\n"
" float4 m_localCenter;\n"
@@ -152,48 +134,37 @@ static const char* primitiveContactsKernelsCL= \
" int m_uniqueEdgesOffset;\n"
" int m_numUniqueEdges;\n"
" int m_unused;\n"
"\n"
"} ConvexPolyhedronCL;\n"
"\n"
"typedef struct\n"
"{\n"
" float4 m_plane;\n"
" int m_indexOffset;\n"
" int m_numIndices;\n"
"} btGpuFace;\n"
"\n"
"#define SELECT_UINT4( b, a, condition ) select( b,a,condition )\n"
"\n"
"#define make_float4 (float4)\n"
"#define make_float2 (float2)\n"
"#define make_uint4 (uint4)\n"
"#define make_int4 (int4)\n"
"#define make_uint2 (uint2)\n"
"#define make_int2 (int2)\n"
"\n"
"\n"
"__inline\n"
"float fastDiv(float numerator, float denominator)\n"
"{\n"
" return native_divide(numerator, denominator); \n"
"// return numerator/denominator; \n"
"}\n"
"\n"
"__inline\n"
"float4 fastDiv4(float4 numerator, float4 denominator)\n"
"{\n"
" return native_divide(numerator, denominator); \n"
"}\n"
"\n"
"\n"
"__inline\n"
"float4 cross3(float4 a, float4 b)\n"
"{\n"
" return cross(a,b);\n"
"}\n"
"\n"
"//#define dot3F4 dot\n"
"\n"
"__inline\n"
"float dot3F4(float4 a, float4 b)\n"
"{\n"
@@ -201,35 +172,23 @@ static const char* primitiveContactsKernelsCL= \
" float4 b1 = make_float4(b.xyz,0.f);\n"
" return dot(a1, b1);\n"
"}\n"
"\n"
"__inline\n"
"float4 fastNormalize4(float4 v)\n"
"{\n"
" return fast_normalize(v);\n"
"}\n"
"\n"
"\n"
"///////////////////////////////////////\n"
"// Quaternion\n"
"///////////////////////////////////////\n"
"\n"
"typedef float4 Quaternion;\n"
"\n"
"__inline\n"
"Quaternion qtMul(Quaternion a, Quaternion b);\n"
"\n"
"__inline\n"
"Quaternion qtNormalize(Quaternion in);\n"
"\n"
"__inline\n"
"float4 qtRotate(Quaternion q, float4 vec);\n"
"\n"
"__inline\n"
"Quaternion qtInvert(Quaternion q);\n"
"\n"
"\n"
"\n"
"\n"
"__inline\n"
"Quaternion qtMul(Quaternion a, Quaternion b)\n"
"{\n"
@@ -240,7 +199,6 @@ static const char* primitiveContactsKernelsCL= \
" ans.w = a.w*b.w - dot3F4(a, b);\n"
" return ans;\n"
"}\n"
"\n"
"__inline\n"
"Quaternion qtNormalize(Quaternion in)\n"
"{\n"
@@ -257,32 +215,27 @@ static const char* primitiveContactsKernelsCL= \
" float4 out = qtMul(qtMul(q,vcpy),qInv);\n"
" return out;\n"
"}\n"
"\n"
"__inline\n"
"Quaternion qtInvert(Quaternion q)\n"
"{\n"
" return (Quaternion)(-q.xyz, q.w);\n"
"}\n"
"\n"
"__inline\n"
"float4 qtInvRotate(const Quaternion q, float4 vec)\n"
"{\n"
" return qtRotate( qtInvert( q ), vec );\n"
"}\n"
"\n"
"__inline\n"
"float4 transform(const float4* p, const float4* translation, const Quaternion* orientation)\n"
"{\n"
" return qtRotate( *orientation, *p ) + (*translation);\n"
"}\n"
"\n"
"void trInverse(float4 translationIn, Quaternion orientationIn,\n"
" float4* translationOut, Quaternion* orientationOut)\n"
"{\n"
" *orientationOut = qtInvert(orientationIn);\n"
" *translationOut = qtRotate(*orientationOut, -translationIn);\n"
"}\n"
"\n"
"void trMul(float4 translationA, Quaternion orientationA,\n"
" float4 translationB, Quaternion orientationB,\n"
" float4* translationOut, Quaternion* orientationOut)\n"
@@ -290,17 +243,12 @@ static const char* primitiveContactsKernelsCL= \
" *orientationOut = qtMul(orientationA,orientationB);\n"
" *translationOut = transform(&translationB,&translationA,&orientationA);\n"
"}\n"
"\n"
"\n"
"\n"
"__inline\n"
"float4 normalize3(const float4 a)\n"
"{\n"
" float4 n = make_float4(a.x, a.y, a.z, 0.f);\n"
" return fastNormalize4( n );\n"
"}\n"
"\n"
"\n"
"__inline float4 lerp3(const float4 a,const float4 b, float t)\n"
"{\n"
" return make_float4( a.x + (b.x - a.x) * t,\n"
@@ -308,8 +256,6 @@ static const char* primitiveContactsKernelsCL= \
" a.z + (b.z - a.z) * t,\n"
" 0.f);\n"
"}\n"
"\n"
"\n"
"float signedDistanceFromPointToPlane(float4 point, float4 planeEqn, float4* closestPointOnFace)\n"
"{\n"
" float4 n = (float4)(planeEqn.x, planeEqn.y, planeEqn.z, 0);\n"
@@ -317,9 +263,6 @@ static const char* primitiveContactsKernelsCL= \
" *closestPointOnFace = point - dist * n;\n"
" return dist;\n"
"}\n"
"\n"
"\n"
"\n"
"inline bool IsPointInPolygon(float4 p, \n"
" const btGpuFace* face,\n"
" __global const float4* baseVertex,\n"
@@ -331,17 +274,14 @@ static const char* primitiveContactsKernelsCL= \
" float4 ab;\n"
" float4 ap;\n"
" float4 v;\n"
"\n"
" float4 plane = make_float4(face->m_plane.x,face->m_plane.y,face->m_plane.z,0.f);\n"
" \n"
" if (face->m_numIndices<2)\n"
" return false;\n"
"\n"
" \n"
" float4 v0 = baseVertex[convexIndices[face->m_indexOffset + face->m_numIndices-1]];\n"
" \n"
" b = v0;\n"
"\n"
" for(unsigned i=0; i != face->m_numIndices; ++i)\n"
" {\n"
" a = b;\n"
@@ -350,7 +290,6 @@ static const char* primitiveContactsKernelsCL= \
" ab = b-a;\n"
" ap = p-a;\n"
" v = cross3(ab,plane);\n"
"\n"
" if (dot(ap, v) > 0.f)\n"
" {\n"
" float ab_m2 = dot(ab, ab);\n"
@@ -375,10 +314,6 @@ static const char* primitiveContactsKernelsCL= \
" }\n"
" return true;\n"
"}\n"
"\n"
"\n"
"\n"
"\n"
"void computeContactSphereConvex(int pairIndex,\n"
" int bodyIndexA, int bodyIndexB, \n"
" int collidableIndexA, int collidableIndexB, \n"
@@ -388,7 +323,7 @@ static const char* primitiveContactsKernelsCL= \
" __global const float4* convexVertices,\n"
" __global const int* convexIndices,\n"
" __global const btGpuFace* faces,\n"
" __global b3Contact4Data* restrict globalContactsOut,\n"
" __global struct b3Contact4Data* restrict globalContactsOut,\n"
" counter32_t nGlobalContactsOut,\n"
" int maxContactCapacity,\n"
" float4 spherePos2,\n"
@@ -397,25 +332,19 @@ static const char* primitiveContactsKernelsCL= \
" float4 quat\n"
" )\n"
"{\n"
"\n"
" float4 invPos;\n"
" float4 invOrn;\n"
"\n"
" trInverse(pos,quat, &invPos,&invOrn);\n"
"\n"
" float4 spherePos = transform(&spherePos2,&invPos,&invOrn);\n"
"\n"
" int shapeIndex = collidables[collidableIndexB].m_shapeIndex;\n"
" int numFaces = convexShapes[shapeIndex].m_numFaces;\n"
" 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"
"\n"
" for ( int f = 0; f < numFaces; f++ )\n"
" {\n"
" btGpuFace face = faces[convexShapes[shapeIndex].m_faceOffset+f];\n"
"\n"
" // set up a plane equation \n"
" float4 planeEqn;\n"
" float4 n1 = face.m_plane;\n"
@@ -427,21 +356,17 @@ static const char* primitiveContactsKernelsCL= \
" // compute a signed distance from the vertex in cloth to the face of rigidbody.\n"
" float4 pntReturn;\n"
" float dist = signedDistanceFromPointToPlane(spherePos, planeEqn, &pntReturn);\n"
"\n"
" // If the distance is positive, the plane is a separating plane. \n"
" if ( dist > radius )\n"
" {\n"
" bCollide = false;\n"
" break;\n"
" }\n"
"\n"
"\n"
" if (dist>0)\n"
" {\n"
" //might hit an edge or vertex\n"
" float4 out;\n"
" float4 zeroPos = make_float4(0,0,0,0);\n"
"\n"
" bool isInPoly = IsPointInPolygon(spherePos,\n"
" &face,\n"
" &convexVertices[convexShapes[shapeIndex].m_vertexOffset],\n"
@@ -488,9 +413,7 @@ static const char* primitiveContactsKernelsCL= \
" }\n"
" \n"
" }\n"
"\n"
" \n"
"\n"
" if (bCollide && minDist > -10000)\n"
" {\n"
" float4 normalOnSurfaceB1 = qtRotate(quat,-hitNormalWorld);\n"
@@ -500,35 +423,28 @@ static const char* primitiveContactsKernelsCL= \
" if (actualDepth<=0.f)\n"
" {\n"
" \n"
"\n"
" pOnB1.w = actualDepth;\n"
"\n"
" int dstIdx;\n"
" AppendInc( nGlobalContactsOut, dstIdx );\n"
" \n"
" \n"
" if (1)//dstIdx < maxContactCapacity)\n"
" {\n"
" __global b3Contact4Data* c = &globalContactsOut[dstIdx];\n"
" __global struct b3Contact4Data* c = &globalContactsOut[dstIdx];\n"
" c->m_worldNormal = normalOnSurfaceB1;\n"
" c->m_coeffs = (u32)(0.f*0xffff) | ((u32)(0.7f*0xffff)<<16);\n"
" c->m_restituitionCoeffCmp = (0.f*0xffff);c->m_frictionCoeffCmp = (0.7f*0xffff);\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"
" c->m_childIndexA = -1;\n"
" c->m_childIndexB = -1;\n"
"\n"
" GET_NPOINTS(*c) = 1;\n"
" } \n"
"\n"
" }\n"
" }//if (hasCollision)\n"
"\n"
"}\n"
" \n"
"\n"
"\n"
"int extractManifoldSequential(const float4* p, int nPoints, float4 nearNormal, int4* contactIdx)\n"
"{\n"
" if( nPoints == 0 )\n"
@@ -621,9 +537,7 @@ static const char* primitiveContactsKernelsCL= \
" return 4;\n"
" \n"
"}\n"
"\n"
"#define MAX_PLANE_CONVEX_POINTS 64\n"
"\n"
"int computeContactPlaneConvex(int pairIndex,\n"
" int bodyIndexA, int bodyIndexB, \n"
" int collidableIndexA, int collidableIndexB, \n"
@@ -633,7 +547,7 @@ static const char* primitiveContactsKernelsCL= \
" __global const float4* convexVertices,\n"
" __global const int* convexIndices,\n"
" __global const btGpuFace* faces,\n"
" __global b3Contact4Data* restrict globalContactsOut,\n"
" __global struct b3Contact4Data* restrict globalContactsOut,\n"
" counter32_t nGlobalContactsOut,\n"
" int maxContactCapacity,\n"
" float4 posB,\n"
@@ -641,7 +555,6 @@ static const char* primitiveContactsKernelsCL= \
" )\n"
"{\n"
" int resultIndex=-1;\n"
"\n"
" int shapeIndex = collidables[collidableIndexB].m_shapeIndex;\n"
" __global const ConvexPolyhedronCL* hullB = &convexShapes[shapeIndex];\n"
" \n"
@@ -649,10 +562,8 @@ static const char* primitiveContactsKernelsCL= \
" posA = rigidBodies[bodyIndexA].m_pos;\n"
" Quaternion ornA;\n"
" ornA = rigidBodies[bodyIndexA].m_quat;\n"
"\n"
" int numContactsOut = 0;\n"
" int numWorldVertsB1= 0;\n"
"\n"
" float4 planeEq;\n"
" planeEq = faces[collidables[collidableIndexA].m_shapeIndex].m_plane;\n"
" float4 planeNormal = make_float4(planeEq.x,planeEq.y,planeEq.z,0.f);\n"
@@ -674,18 +585,13 @@ static const char* primitiveContactsKernelsCL= \
" trInverse(posB,ornB,&invPosB,&invOrnB);\n"
" trMul(invPosB,invOrnB,posA,ornA,&planeInConvexPos1,&planeInConvexOrn1); \n"
" }\n"
"\n"
" \n"
" float4 planeNormalInConvex = qtRotate(planeInConvexOrn1,-planeNormal);\n"
" float maxDot = -1e30;\n"
" int hitVertex=-1;\n"
" float4 hitVtx;\n"
"\n"
"\n"
"\n"
" float4 contactPoints[MAX_PLANE_CONVEX_POINTS];\n"
" int numPoints = 0;\n"
"\n"
" int4 contactIdx;\n"
" contactIdx=make_int4(0,1,2,3);\n"
" \n"
@@ -694,8 +600,6 @@ static const char* primitiveContactsKernelsCL= \
" {\n"
" float4 vtx = convexVertices[hullB->m_vertexOffset+i];\n"
" float curDot = dot(vtx,planeNormalInConvex);\n"
"\n"
"\n"
" if (curDot>maxDot)\n"
" {\n"
" hitVertex=i;\n"
@@ -705,7 +609,6 @@ static const char* primitiveContactsKernelsCL= \
" if (numPoints==MAX_PLANE_CONVEX_POINTS)\n"
" numPoints--;\n"
" }\n"
"\n"
" if (numPoints<MAX_PLANE_CONVEX_POINTS)\n"
" {\n"
" float4 vtxWorld = transform(&vtx, &posB, &ornB);\n"
@@ -718,34 +621,29 @@ static const char* primitiveContactsKernelsCL= \
" numPoints++;\n"
" }\n"
" }\n"
"\n"
" }\n"
"\n"
" int numReducedPoints = numPoints;\n"
" if (numPoints>4)\n"
" {\n"
" numReducedPoints = extractManifoldSequential( contactPoints, numPoints, planeNormalInConvex, &contactIdx);\n"
" }\n"
"\n"
" if (numReducedPoints>0)\n"
" {\n"
" int dstIdx;\n"
" AppendInc( nGlobalContactsOut, dstIdx );\n"
"\n"
" if (dstIdx < maxContactCapacity)\n"
" {\n"
" resultIndex = dstIdx;\n"
" __global b3Contact4Data* c = &globalContactsOut[dstIdx];\n"
" __global struct b3Contact4Data* c = &globalContactsOut[dstIdx];\n"
" c->m_worldNormal = planeNormalWorld;\n"
" //c->setFrictionCoeff(0.7);\n"
" //c->setRestituitionCoeff(0.f);\n"
" c->m_coeffs = (u32)(0.f*0xffff) | ((u32)(0.7f*0xffff)<<16);\n"
" c->m_restituitionCoeffCmp = (0.f*0xffff);c->m_frictionCoeffCmp = (0.7f*0xffff);\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_childIndexA = -1;\n"
" c->m_childIndexB = -1;\n"
"\n"
" switch (numReducedPoints)\n"
" {\n"
" case 4:\n"
@@ -764,18 +662,15 @@ static const char* primitiveContactsKernelsCL= \
" GET_NPOINTS(*c) = numReducedPoints;\n"
" }//if (dstIdx < numPairs)\n"
" } \n"
"\n"
" return resultIndex;\n"
"}\n"
"\n"
"\n"
"void computeContactPlaneSphere(int pairIndex,\n"
" int bodyIndexA, int bodyIndexB, \n"
" int collidableIndexA, int collidableIndexB, \n"
" __global const BodyData* rigidBodies, \n"
" __global const btCollidableGpu* collidables,\n"
" __global const btGpuFace* faces,\n"
" __global b3Contact4Data* restrict globalContactsOut,\n"
" __global struct b3Contact4Data* restrict globalContactsOut,\n"
" counter32_t nGlobalContactsOut,\n"
" int maxContactCapacity)\n"
"{\n"
@@ -812,15 +707,14 @@ static const char* primitiveContactsKernelsCL= \
" float4 normalOnSurfaceB1 = qtRotate(ornA1,planeNormal1);\n"
" float4 pOnB1 = vtxInPlaneWorld1+normalOnSurfaceB1*distance;\n"
" pOnB1.w = distance;\n"
"\n"
" int dstIdx;\n"
" AppendInc( nGlobalContactsOut, dstIdx );\n"
" \n"
" if (dstIdx < maxContactCapacity)\n"
" {\n"
" __global b3Contact4Data* c = &globalContactsOut[dstIdx];\n"
" __global struct b3Contact4Data* c = &globalContactsOut[dstIdx];\n"
" c->m_worldNormal = normalOnSurfaceB1;\n"
" c->m_coeffs = (u32)(0.f*0xffff) | ((u32)(0.7f*0xffff)<<16);\n"
" c->m_restituitionCoeffCmp = (0.f*0xffff);c->m_frictionCoeffCmp = (0.7f*0xffff);\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"
@@ -831,8 +725,6 @@ static const char* primitiveContactsKernelsCL= \
" }//if (dstIdx < numPairs)\n"
" }//if (hasCollision)\n"
"}\n"
"\n"
"\n"
"__kernel void primitiveContactsKernel( __global int4* pairs, \n"
" __global const BodyData* rigidBodies, \n"
" __global const btCollidableGpu* collidables,\n"
@@ -841,27 +733,23 @@ static const char* primitiveContactsKernelsCL= \
" __global const float4* uniqueEdges,\n"
" __global const btGpuFace* faces,\n"
" __global const int* indices,\n"
" __global b3Contact4Data* restrict globalContactsOut,\n"
" __global struct b3Contact4Data* restrict globalContactsOut,\n"
" counter32_t nGlobalContactsOut,\n"
" int numPairs, int maxContactCapacity)\n"
"{\n"
"\n"
" int i = get_global_id(0);\n"
" int pairIndex = i;\n"
" \n"
" float4 worldVertsB1[64];\n"
" float4 worldVertsB2[64];\n"
" int capacityWorldVerts = 64; \n"
"\n"
" float4 localContactsOut[64];\n"
" int localContactCapacity=64;\n"
" \n"
" float minDist = -1e30f;\n"
" float maxDist = 0.02f;\n"
"\n"
" if (i<numPairs)\n"
" {\n"
"\n"
" int bodyIndexA = pairs[i].x;\n"
" int bodyIndexB = pairs[i].y;\n"
" \n"
@@ -871,7 +759,6 @@ static const char* primitiveContactsKernelsCL= \
" if (collidables[collidableIndexA].m_shapeType == SHAPE_PLANE &&\n"
" collidables[collidableIndexB].m_shapeType == SHAPE_CONVEX_HULL)\n"
" {\n"
"\n"
" float4 posB;\n"
" posB = rigidBodies[bodyIndexB].m_pos;\n"
" Quaternion ornB;\n"
@@ -881,31 +768,22 @@ static const char* primitiveContactsKernelsCL= \
" faces, globalContactsOut, nGlobalContactsOut,maxContactCapacity, posB,ornB);\n"
" if (contactIndex>=0)\n"
" pairs[pairIndex].z = contactIndex;\n"
"\n"
" return;\n"
" }\n"
"\n"
"\n"
" if (collidables[collidableIndexA].m_shapeType == SHAPE_CONVEX_HULL &&\n"
" collidables[collidableIndexB].m_shapeType == SHAPE_PLANE)\n"
" {\n"
"\n"
" float4 posA;\n"
" posA = rigidBodies[bodyIndexA].m_pos;\n"
" Quaternion ornA;\n"
" ornA = rigidBodies[bodyIndexA].m_quat;\n"
"\n"
"\n"
" int contactIndex = computeContactPlaneConvex( pairIndex, bodyIndexB,bodyIndexA, collidableIndexB,collidableIndexA, \n"
" rigidBodies,collidables,convexShapes,vertices,indices,\n"
" faces, globalContactsOut, nGlobalContactsOut,maxContactCapacity,posA,ornA);\n"
"\n"
" if (contactIndex>=0)\n"
" pairs[pairIndex].z = contactIndex;\n"
"\n"
" return;\n"
" }\n"
"\n"
" if (collidables[collidableIndexA].m_shapeType == SHAPE_PLANE &&\n"
" collidables[collidableIndexB].m_shapeType == SHAPE_SPHERE)\n"
" {\n"
@@ -913,22 +791,15 @@ static const char* primitiveContactsKernelsCL= \
" rigidBodies,collidables,faces, globalContactsOut, nGlobalContactsOut,maxContactCapacity);\n"
" return;\n"
" }\n"
"\n"
"\n"
" if (collidables[collidableIndexA].m_shapeType == SHAPE_SPHERE &&\n"
" collidables[collidableIndexB].m_shapeType == SHAPE_PLANE)\n"
" {\n"
"\n"
"\n"
" computeContactPlaneSphere( pairIndex, bodyIndexB,bodyIndexA, collidableIndexB,collidableIndexA, \n"
" rigidBodies,collidables,\n"
" faces, globalContactsOut, nGlobalContactsOut,maxContactCapacity);\n"
"\n"
" return;\n"
" }\n"
"\n"
" \n"
"\n"
" \n"
" if (collidables[collidableIndexA].m_shapeType == SHAPE_SPHERE &&\n"
" collidables[collidableIndexB].m_shapeType == SHAPE_CONVEX_HULL)\n"
@@ -938,14 +809,11 @@ static const char* primitiveContactsKernelsCL= \
" float sphereRadius = collidables[collidableIndexA].m_radius;\n"
" float4 convexPos = rigidBodies[bodyIndexB].m_pos;\n"
" float4 convexOrn = rigidBodies[bodyIndexB].m_quat;\n"
"\n"
" computeContactSphereConvex(pairIndex, bodyIndexA, bodyIndexB, collidableIndexA, collidableIndexB, \n"
" rigidBodies,collidables,convexShapes,vertices,indices,faces, globalContactsOut, nGlobalContactsOut,maxContactCapacity,\n"
" spherePos,sphereRadius,convexPos,convexOrn);\n"
"\n"
" return;\n"
" }\n"
"\n"
" if (collidables[collidableIndexA].m_shapeType == SHAPE_CONVEX_HULL &&\n"
" collidables[collidableIndexB].m_shapeType == SHAPE_SPHERE)\n"
" {\n"
@@ -954,7 +822,6 @@ static const char* primitiveContactsKernelsCL= \
" float sphereRadius = collidables[collidableIndexB].m_radius;\n"
" float4 convexPos = rigidBodies[bodyIndexA].m_pos;\n"
" float4 convexOrn = rigidBodies[bodyIndexA].m_quat;\n"
"\n"
" computeContactSphereConvex(pairIndex, bodyIndexB, bodyIndexA, collidableIndexB, collidableIndexA, \n"
" rigidBodies,collidables,convexShapes,vertices,indices,faces, globalContactsOut, nGlobalContactsOut,maxContactCapacity,\n"
" spherePos,sphereRadius,convexPos,convexOrn);\n"
@@ -974,7 +841,6 @@ static const char* primitiveContactsKernelsCL= \
" float radiusB = collidables[collidableIndexB].m_radius;\n"
" float4 posA = rigidBodies[bodyIndexA].m_pos;\n"
" float4 posB = rigidBodies[bodyIndexB].m_pos;\n"
"\n"
" float4 diff = posA-posB;\n"
" float len = length(diff);\n"
" \n"
@@ -996,9 +862,9 @@ static const char* primitiveContactsKernelsCL= \
" \n"
" if (dstIdx < maxContactCapacity)\n"
" {\n"
" __global b3Contact4Data* c = &globalContactsOut[dstIdx];\n"
" __global struct b3Contact4Data* c = &globalContactsOut[dstIdx];\n"
" c->m_worldNormal = -normalOnSurfaceB;\n"
" c->m_coeffs = (u32)(0.f*0xffff) | ((u32)(0.7f*0xffff)<<16);\n"
" c->m_restituitionCoeffCmp = (0.f*0xffff);c->m_frictionCoeffCmp = (0.7f*0xffff);\n"
" c->m_batchIdx = pairIndex;\n"
" int bodyA = pairs[pairIndex].x;\n"
" int bodyB = pairs[pairIndex].y;\n"
@@ -1010,15 +876,10 @@ static const char* primitiveContactsKernelsCL= \
" GET_NPOINTS(*c) = 1;\n"
" }//if (dstIdx < numPairs)\n"
" }//if ( len <= (radiusA+radiusB))\n"
"\n"
" return;\n"
" }//SHAPE_SPHERE SHAPE_SPHERE\n"
"\n"
" }// if (i<numPairs)\n"
"\n"
"}\n"
"\n"
"\n"
"// work-in-progress\n"
"__kernel void processCompoundPairsPrimitivesKernel( __global const int4* gpuCompoundPairs,\n"
" __global const BodyData* rigidBodies, \n"
@@ -1030,18 +891,16 @@ static const char* primitiveContactsKernelsCL= \
" __global const int* indices,\n"
" __global btAabbCL* aabbs,\n"
" __global const btGpuChildShape* gpuChildShapes,\n"
" __global b3Contact4Data* restrict globalContactsOut,\n"
" __global struct b3Contact4Data* restrict globalContactsOut,\n"
" counter32_t nGlobalContactsOut,\n"
" int numCompoundPairs, int maxContactCapacity\n"
" )\n"
"{\n"
"\n"
" int i = get_global_id(0);\n"
" if (i<numCompoundPairs)\n"
" {\n"
" int bodyIndexA = gpuCompoundPairs[i].x;\n"
" int bodyIndexB = gpuCompoundPairs[i].y;\n"
"\n"
" int childShapeIndexA = gpuCompoundPairs[i].z;\n"
" int childShapeIndexB = gpuCompoundPairs[i].w;\n"
" \n"
@@ -1087,26 +946,21 @@ static const char* primitiveContactsKernelsCL= \
" \n"
" int shapeTypeA = collidables[collidableIndexA].m_shapeType;\n"
" int shapeTypeB = collidables[collidableIndexB].m_shapeType;\n"
"\n"
" int pairIndex = i;\n"
" if ((shapeTypeA == SHAPE_PLANE) && (shapeTypeB==SHAPE_CONVEX_HULL))\n"
" {\n"
"\n"
" computeContactPlaneConvex( pairIndex, bodyIndexA,bodyIndexB, collidableIndexA,collidableIndexB, \n"
" rigidBodies,collidables,convexShapes,vertices,indices,\n"
" faces, globalContactsOut, nGlobalContactsOut,maxContactCapacity,posB,ornB);\n"
" return;\n"
" }\n"
"\n"
" if ((shapeTypeA == SHAPE_CONVEX_HULL) && (shapeTypeB==SHAPE_PLANE))\n"
" {\n"
"\n"
" computeContactPlaneConvex( pairIndex, bodyIndexB,bodyIndexA, collidableIndexB,collidableIndexA, \n"
" rigidBodies,collidables,convexShapes,vertices,indices,\n"
" faces, globalContactsOut, nGlobalContactsOut,maxContactCapacity,posA,ornA);\n"
" return;\n"
" }\n"
"\n"
" if ((shapeTypeA == SHAPE_CONVEX_HULL) && (shapeTypeB == SHAPE_SPHERE))\n"
" {\n"
" float4 spherePos = rigidBodies[bodyIndexB].m_pos;\n"
@@ -1120,15 +974,12 @@ static const char* primitiveContactsKernelsCL= \
" \n"
" return;\n"
" }\n"
"\n"
" if ((shapeTypeA == SHAPE_SPHERE) && (shapeTypeB == SHAPE_CONVEX_HULL))\n"
" {\n"
"\n"
" float4 spherePos = rigidBodies[bodyIndexA].m_pos;\n"
" float sphereRadius = collidables[collidableIndexA].m_radius;\n"
" float4 convexPos = posB;\n"
" float4 convexOrn = ornB;\n"
"\n"
" \n"
" computeContactSphereConvex(pairIndex, bodyIndexA, bodyIndexB, collidableIndexA, collidableIndexB, \n"
" rigidBodies,collidables,convexShapes,vertices,indices,faces, globalContactsOut, nGlobalContactsOut,maxContactCapacity,\n"
@@ -1138,28 +989,21 @@ static const char* primitiveContactsKernelsCL= \
" }\n"
" }// if (i<numCompoundPairs)\n"
"}\n"
"\n"
"\n"
"bool pointInTriangle(const float4* vertices, const float4* normal, float4 *p )\n"
"{\n"
"\n"
" const float4* p1 = &vertices[0];\n"
" const float4* p2 = &vertices[1];\n"
" const float4* p3 = &vertices[2];\n"
"\n"
" float4 edge1; edge1 = (*p2 - *p1);\n"
" float4 edge2; edge2 = ( *p3 - *p2 );\n"
" float4 edge3; edge3 = ( *p1 - *p3 );\n"
"\n"
" \n"
" float4 p1_to_p; p1_to_p = ( *p - *p1 );\n"
" float4 p2_to_p; p2_to_p = ( *p - *p2 );\n"
" float4 p3_to_p; p3_to_p = ( *p - *p3 );\n"
"\n"
" float4 edge1_normal; edge1_normal = ( cross(edge1,*normal));\n"
" float4 edge2_normal; edge2_normal = ( cross(edge2,*normal));\n"
" float4 edge3_normal; edge3_normal = ( cross(edge3,*normal));\n"
"\n"
" \n"
" \n"
" float r1, r2, r3;\n"
@@ -1172,10 +1016,7 @@ static const char* primitiveContactsKernelsCL= \
" if ( r1 <= 0 && r2 <= 0 && r3 <= 0 ) \n"
" return true;\n"
" return false;\n"
"\n"
"}\n"
"\n"
"\n"
"float segmentSqrDistance(float4 from, float4 to,float4 p, float4* nearest) \n"
"{\n"
" float4 diff = p - from;\n"
@@ -1201,15 +1042,13 @@ static const char* primitiveContactsKernelsCL= \
" *nearest = from + t*v;\n"
" return dot(diff,diff); \n"
"}\n"
"\n"
"\n"
"void computeContactSphereTriangle(int pairIndex,\n"
" int bodyIndexA, int bodyIndexB,\n"
" int collidableIndexA, int collidableIndexB, \n"
" __global const BodyData* rigidBodies, \n"
" __global const btCollidableGpu* collidables,\n"
" const float4* triangleVertices,\n"
" __global b3Contact4Data* restrict globalContactsOut,\n"
" __global struct b3Contact4Data* restrict globalContactsOut,\n"
" counter32_t nGlobalContactsOut,\n"
" int maxContactCapacity,\n"
" float4 spherePos2,\n"
@@ -1219,10 +1058,8 @@ static const char* primitiveContactsKernelsCL= \
" int faceIndex\n"
" )\n"
"{\n"
"\n"
" float4 invPos;\n"
" float4 invOrn;\n"
"\n"
" trInverse(pos,quat, &invPos,&invOrn);\n"
" float4 spherePos = transform(&spherePos2,&invPos,&invOrn);\n"
" int numFaces = 3;\n"
@@ -1230,13 +1067,10 @@ static const char* primitiveContactsKernelsCL= \
" float4 hitNormalWorld = (float4)(0, 0, 0, 0);\n"
" float minDist = -1000000.f;\n"
" bool bCollide = false;\n"
"\n"
" \n"
" //////////////////////////////////////\n"
"\n"
" float4 sphereCenter;\n"
" sphereCenter = spherePos;\n"
"\n"
" const float4* vertices = triangleVertices;\n"
" float contactBreakingThreshold = 0.f;//todo?\n"
" float radiusWithThreshold = radius + contactBreakingThreshold;\n"
@@ -1252,7 +1086,6 @@ static const char* primitiveContactsKernelsCL= \
" p1ToCenter = sphereCenter - vertices[0];\n"
" \n"
" float distanceFromPlane = dot(p1ToCenter,normal);\n"
"\n"
" if (distanceFromPlane < 0.f)\n"
" {\n"
" //triangle facing the other way\n"
@@ -1260,7 +1093,6 @@ static const char* primitiveContactsKernelsCL= \
" normal *= -1.f;\n"
" }\n"
" hitNormalWorld = normal;\n"
"\n"
" bool isInsideContactPlane = distanceFromPlane < radiusWithThreshold;\n"
" \n"
" // Check for contact / intersection\n"
@@ -1284,7 +1116,6 @@ static const char* primitiveContactsKernelsCL= \
" {\n"
" float4 pa =vertices[i];\n"
" float4 pb = vertices[(i+1)%3];\n"
"\n"
" float distanceSqr = segmentSqrDistance(pa,pb,sphereCenter, &nearestOnEdge);\n"
" if (distanceSqr < contactCapsuleRadiusSqr) \n"
" {\n"
@@ -1297,10 +1128,8 @@ static const char* primitiveContactsKernelsCL= \
" }\n"
" }\n"
" }\n"
"\n"
" if (hasContact) \n"
" {\n"
"\n"
" closestPnt = contactPoint;\n"
" float4 contactToCenter = sphereCenter - contactPoint;\n"
" minDist = length(contactToCenter);\n"
@@ -1311,23 +1140,18 @@ static const char* primitiveContactsKernelsCL= \
" }\n"
" \n"
" }\n"
"\n"
"\n"
" /////////////////////////////////////\n"
"\n"
" if (bCollide && minDist > -10000)\n"
" {\n"
" \n"
" float4 normalOnSurfaceB1 = qtRotate(quat,-hitNormalWorld);\n"
" float4 pOnB1 = transform(&closestPnt,&pos,&quat);\n"
" float actualDepth = minDist-radius;\n"
"\n"
" \n"
" if (actualDepth<=0.f)\n"
" {\n"
" pOnB1.w = actualDepth;\n"
" int dstIdx;\n"
"\n"
" \n"
" float lenSqr = dot3F4(normalOnSurfaceB1,normalOnSurfaceB1);\n"
" if (lenSqr>FLT_EPSILON)\n"
@@ -1336,28 +1160,21 @@ static const char* primitiveContactsKernelsCL= \
" \n"
" if (dstIdx < maxContactCapacity)\n"
" {\n"
" __global b3Contact4Data* c = &globalContactsOut[dstIdx];\n"
" __global struct b3Contact4Data* c = &globalContactsOut[dstIdx];\n"
" c->m_worldNormal = normalOnSurfaceB1;\n"
" c->m_coeffs = (u32)(0.f*0xffff) | ((u32)(0.7f*0xffff)<<16);\n"
" c->m_restituitionCoeffCmp = (0.f*0xffff);c->m_frictionCoeffCmp = (0.7f*0xffff);\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"
"\n"
"}\n"
"\n"
"\n"
"\n"
"// work-in-progress\n"
"__kernel void findConcaveSphereContactsKernel( __global int4* concavePairs,\n"
" __global const BodyData* rigidBodies,\n"
@@ -1368,26 +1185,21 @@ static const char* primitiveContactsKernelsCL= \
" __global const btGpuFace* faces,\n"
" __global const int* indices,\n"
" __global btAabbCL* aabbs,\n"
" __global b3Contact4Data* restrict globalContactsOut,\n"
" __global struct b3Contact4Data* restrict globalContactsOut,\n"
" counter32_t nGlobalContactsOut,\n"
" int numConcavePairs, int maxContactCapacity\n"
" )\n"
"{\n"
"\n"
" int i = get_global_id(0);\n"
" if (i>=numConcavePairs)\n"
" return;\n"
" int pairIdx = i;\n"
"\n"
" int bodyIndexA = concavePairs[i].x;\n"
" int bodyIndexB = concavePairs[i].y;\n"
"\n"
" int collidableIndexA = rigidBodies[bodyIndexA].m_collidableIdx;\n"
" int collidableIndexB = rigidBodies[bodyIndexB].m_collidableIdx;\n"
"\n"
" int shapeIndexA = collidables[collidableIndexA].m_shapeIndex;\n"
" int shapeIndexB = collidables[collidableIndexB].m_shapeIndex;\n"
"\n"
" if (collidables[collidableIndexB].m_shapeType==SHAPE_SPHERE)\n"
" {\n"
" int f = concavePairs[i].z;\n"
@@ -1400,18 +1212,15 @@ static const char* primitiveContactsKernelsCL= \
" float4 vert = vertices[convexShapes[shapeIndexA].m_vertexOffset+index];\n"
" verticesA[i] = vert;\n"
" }\n"
"\n"
" float4 spherePos = rigidBodies[bodyIndexB].m_pos;\n"
" float sphereRadius = collidables[collidableIndexB].m_radius;\n"
" float4 convexPos = rigidBodies[bodyIndexA].m_pos;\n"
" float4 convexOrn = rigidBodies[bodyIndexA].m_quat;\n"
"\n"
" computeContactSphereTriangle(i, bodyIndexB, bodyIndexA, collidableIndexB, collidableIndexA, \n"
" rigidBodies,collidables,\n"
" verticesA,\n"
" globalContactsOut, nGlobalContactsOut,maxContactCapacity,\n"
" spherePos,sphereRadius,convexPos,convexOrn, f);\n"
"\n"
" return;\n"
" }\n"
"}\n"