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:
@@ -2,17 +2,11 @@
|
||||
static const char* satKernelsCL= \
|
||||
"//keep this enum in sync with the CPU version (in btCollidable.h)\n"
|
||||
"//written by Erwin Coumans\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"#define SHAPE_CONVEX_HULL 3\n"
|
||||
"#define SHAPE_CONCAVE_TRIMESH 5\n"
|
||||
"#define TRIANGLE_NUM_CONVEX_FACES 5\n"
|
||||
"#define SHAPE_COMPOUND_OF_CONVEX_HULLS 6\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"typedef unsigned int u32;\n"
|
||||
"\n"
|
||||
"///keep this in sync with btCollidable.h\n"
|
||||
"typedef struct\n"
|
||||
"{\n"
|
||||
@@ -22,7 +16,6 @@ static const char* satKernelsCL= \
|
||||
" int m_shapeIndex;\n"
|
||||
" \n"
|
||||
"} btCollidableGpu;\n"
|
||||
"\n"
|
||||
"typedef struct\n"
|
||||
"{\n"
|
||||
" float4 m_childPosition;\n"
|
||||
@@ -32,22 +25,17 @@ static const char* satKernelsCL= \
|
||||
" int m_unused1;\n"
|
||||
" int m_unused2;\n"
|
||||
"} btGpuChildShape;\n"
|
||||
"\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"
|
||||
@@ -59,13 +47,11 @@ static const char* satKernelsCL= \
|
||||
" int m_faceOffset;\n"
|
||||
" int m_numFaces;\n"
|
||||
" int m_numVertices;\n"
|
||||
"\n"
|
||||
" int m_vertexOffset;\n"
|
||||
" int m_uniqueEdgesOffset;\n"
|
||||
" int m_numUniqueEdges;\n"
|
||||
" int m_unused;\n"
|
||||
"} ConvexPolyhedronCL;\n"
|
||||
"\n"
|
||||
"typedef struct \n"
|
||||
"{\n"
|
||||
" union\n"
|
||||
@@ -81,35 +67,27 @@ static const char* satKernelsCL= \
|
||||
" int m_maxIndices[4];\n"
|
||||
" };\n"
|
||||
"} btAabbCL;\n"
|
||||
"\n"
|
||||
"typedef struct\n"
|
||||
"{\n"
|
||||
" float4 m_plane;\n"
|
||||
" int m_indexOffset;\n"
|
||||
" int m_numIndices;\n"
|
||||
"} btGpuFace;\n"
|
||||
"\n"
|
||||
"#define make_float4 (float4)\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"__inline\n"
|
||||
"float4 cross3(float4 a, float4 b)\n"
|
||||
"{\n"
|
||||
" return cross(a,b);\n"
|
||||
"\n"
|
||||
" \n"
|
||||
"// float4 a1 = make_float4(a.xyz,0.f);\n"
|
||||
"// float4 b1 = make_float4(b.xyz,0.f);\n"
|
||||
"\n"
|
||||
"// return cross(a1,b1);\n"
|
||||
"\n"
|
||||
"//float4 c = make_float4(a.y*b.z - a.z*b.y,a.z*b.x - a.x*b.z,a.x*b.y - a.y*b.x,0.f);\n"
|
||||
" \n"
|
||||
" // float4 c = make_float4(a.y*b.z - a.z*b.y,1.f,a.x*b.y - a.y*b.x,0.f);\n"
|
||||
" \n"
|
||||
" //return c;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"__inline\n"
|
||||
"float dot3F4(float4 a, float4 b)\n"
|
||||
"{\n"
|
||||
@@ -117,36 +95,24 @@ static const char* satKernelsCL= \
|
||||
" float4 b1 = make_float4(b.xyz,0.f);\n"
|
||||
" return dot(a1, b1);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"__inline\n"
|
||||
"float4 fastNormalize4(float4 v)\n"
|
||||
"{\n"
|
||||
" v = make_float4(v.xyz,0.f);\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"
|
||||
@@ -157,7 +123,6 @@ static const char* satKernelsCL= \
|
||||
" ans.w = a.w*b.w - dot3F4(a, b);\n"
|
||||
" return ans;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"__inline\n"
|
||||
"Quaternion qtNormalize(Quaternion in)\n"
|
||||
"{\n"
|
||||
@@ -174,41 +139,33 @@ static const char* satKernelsCL= \
|
||||
" 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"
|
||||
"\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"
|
||||
"inline void projectLocal(const ConvexPolyhedronCL* hull, const float4 pos, const float4 orn, \n"
|
||||
"const float4* dir, const float4* vertices, float* min, float* max)\n"
|
||||
"{\n"
|
||||
" min[0] = FLT_MAX;\n"
|
||||
" max[0] = -FLT_MAX;\n"
|
||||
" int numVerts = hull->m_numVertices;\n"
|
||||
"\n"
|
||||
" const float4 localDir = qtInvRotate(orn,*dir);\n"
|
||||
" float offset = dot(pos,*dir);\n"
|
||||
" for(int i=0;i<numVerts;i++)\n"
|
||||
@@ -228,14 +185,12 @@ static const char* satKernelsCL= \
|
||||
" min[0] += offset;\n"
|
||||
" max[0] += offset;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"inline void project(__global const ConvexPolyhedronCL* hull, const float4 pos, const float4 orn, \n"
|
||||
"const float4* dir, __global const float4* vertices, float* min, float* max)\n"
|
||||
"{\n"
|
||||
" min[0] = FLT_MAX;\n"
|
||||
" max[0] = -FLT_MAX;\n"
|
||||
" int numVerts = hull->m_numVertices;\n"
|
||||
"\n"
|
||||
" const float4 localDir = qtInvRotate(orn,*dir);\n"
|
||||
" float offset = dot(pos,*dir);\n"
|
||||
" for(int i=0;i<numVerts;i++)\n"
|
||||
@@ -255,7 +210,6 @@ static const char* satKernelsCL= \
|
||||
" min[0] += offset;\n"
|
||||
" max[0] += offset;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"inline bool TestSepAxisLocalA(const ConvexPolyhedronCL* hullA, __global const ConvexPolyhedronCL* hullB, \n"
|
||||
" const float4 posA,const float4 ornA,\n"
|
||||
" const float4 posB,const float4 ornB,\n"
|
||||
@@ -265,28 +219,19 @@ static const char* satKernelsCL= \
|
||||
" float Min1,Max1;\n"
|
||||
" projectLocal(hullA,posA,ornA,sep_axis,verticesA, &Min0, &Max0);\n"
|
||||
" project(hullB,posB,ornB, sep_axis,verticesB, &Min1, &Max1);\n"
|
||||
"\n"
|
||||
" if(Max0<Min1 || Max1<Min0)\n"
|
||||
" return false;\n"
|
||||
"\n"
|
||||
" float d0 = Max0 - Min1;\n"
|
||||
" float d1 = Max1 - Min0;\n"
|
||||
" *depth = d0<d1 ? d0:d1;\n"
|
||||
" return true;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"inline bool IsAlmostZero(const float4 v)\n"
|
||||
"{\n"
|
||||
" if(fabs(v.x)>1e-6f || fabs(v.y)>1e-6f || fabs(v.z)>1e-6f)\n"
|
||||
" return false;\n"
|
||||
" return true;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"bool findSeparatingAxisLocalA( const ConvexPolyhedronCL* hullA, __global const ConvexPolyhedronCL* hullB, \n"
|
||||
" const float4 posA1,\n"
|
||||
" const float4 ornA,\n"
|
||||
@@ -298,7 +243,6 @@ static const char* satKernelsCL= \
|
||||
" const float4* uniqueEdgesA, \n"
|
||||
" const btGpuFace* facesA,\n"
|
||||
" const int* indicesA,\n"
|
||||
"\n"
|
||||
" __global const float4* verticesB, \n"
|
||||
" __global const float4* uniqueEdgesB, \n"
|
||||
" __global const btGpuFace* facesB,\n"
|
||||
@@ -307,7 +251,6 @@ static const char* satKernelsCL= \
|
||||
" float* dmin)\n"
|
||||
"{\n"
|
||||
" int i = get_global_id(0);\n"
|
||||
"\n"
|
||||
" float4 posA = posA1;\n"
|
||||
" posA.w = 0.f;\n"
|
||||
" float4 posB = posB1;\n"
|
||||
@@ -339,7 +282,6 @@ static const char* satKernelsCL= \
|
||||
" }\n"
|
||||
" return true;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"bool findSeparatingAxisLocalB( __global const ConvexPolyhedronCL* hullA, const ConvexPolyhedronCL* hullB, \n"
|
||||
" const float4 posA1,\n"
|
||||
" const float4 ornA,\n"
|
||||
@@ -358,7 +300,6 @@ static const char* satKernelsCL= \
|
||||
" float* dmin)\n"
|
||||
"{\n"
|
||||
" int i = get_global_id(0);\n"
|
||||
"\n"
|
||||
" float4 posA = posA1;\n"
|
||||
" posA.w = 0.f;\n"
|
||||
" float4 posB = posB1;\n"
|
||||
@@ -390,9 +331,6 @@ static const char* satKernelsCL= \
|
||||
" }\n"
|
||||
" return true;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"bool findSeparatingAxisEdgeEdgeLocalA( const ConvexPolyhedronCL* hullA, __global const ConvexPolyhedronCL* hullB, \n"
|
||||
" const float4 posA1,\n"
|
||||
" const float4 ornA,\n"
|
||||
@@ -411,36 +349,28 @@ static const char* satKernelsCL= \
|
||||
" float* dmin)\n"
|
||||
"{\n"
|
||||
" int i = get_global_id(0);\n"
|
||||
"\n"
|
||||
" float4 posA = posA1;\n"
|
||||
" posA.w = 0.f;\n"
|
||||
" float4 posB = posB1;\n"
|
||||
" posB.w = 0.f;\n"
|
||||
"\n"
|
||||
" int curPlaneTests=0;\n"
|
||||
"\n"
|
||||
" int curEdgeEdge = 0;\n"
|
||||
" // Test edges\n"
|
||||
" for(int e0=0;e0<hullA->m_numUniqueEdges;e0++)\n"
|
||||
" {\n"
|
||||
" const float4 edge0 = uniqueEdgesA[hullA->m_uniqueEdgesOffset+e0];\n"
|
||||
" float4 edge0World = qtRotate(ornA,edge0);\n"
|
||||
"\n"
|
||||
" for(int e1=0;e1<hullB->m_numUniqueEdges;e1++)\n"
|
||||
" {\n"
|
||||
" const float4 edge1 = uniqueEdgesB[hullB->m_uniqueEdgesOffset+e1];\n"
|
||||
" float4 edge1World = qtRotate(ornB,edge1);\n"
|
||||
"\n"
|
||||
"\n"
|
||||
" float4 crossje = cross3(edge0World,edge1World);\n"
|
||||
"\n"
|
||||
" curEdgeEdge++;\n"
|
||||
" if(!IsAlmostZero(crossje))\n"
|
||||
" {\n"
|
||||
" crossje = normalize3(crossje);\n"
|
||||
" if (dot3F4(DeltaC2,crossje)<0)\n"
|
||||
" crossje *= -1.f;\n"
|
||||
"\n"
|
||||
" float dist;\n"
|
||||
" bool result = true;\n"
|
||||
" {\n"
|
||||
@@ -456,10 +386,8 @@ static const char* satKernelsCL= \
|
||||
" float d1 = Max1 - Min0;\n"
|
||||
" dist = d0<d1 ? d0:d1;\n"
|
||||
" result = true;\n"
|
||||
"\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
"\n"
|
||||
" if(dist<*dmin)\n"
|
||||
" {\n"
|
||||
" *dmin = dist;\n"
|
||||
@@ -467,9 +395,7 @@ static const char* satKernelsCL= \
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" \n"
|
||||
" if((dot3F4(-DeltaC2,*sep))>0.0f)\n"
|
||||
" {\n"
|
||||
@@ -477,8 +403,6 @@ static const char* satKernelsCL= \
|
||||
" }\n"
|
||||
" return true;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"inline bool TestSepAxis(__global const ConvexPolyhedronCL* hullA, __global const ConvexPolyhedronCL* hullB, \n"
|
||||
" const float4 posA,const float4 ornA,\n"
|
||||
" const float4 posB,const float4 ornB,\n"
|
||||
@@ -488,17 +412,13 @@ static const char* satKernelsCL= \
|
||||
" float Min1,Max1;\n"
|
||||
" project(hullA,posA,ornA,sep_axis,vertices, &Min0, &Max0);\n"
|
||||
" project(hullB,posB,ornB, sep_axis,vertices, &Min1, &Max1);\n"
|
||||
"\n"
|
||||
" if(Max0<Min1 || Max1<Min0)\n"
|
||||
" return false;\n"
|
||||
"\n"
|
||||
" float d0 = Max0 - Min1;\n"
|
||||
" float d1 = Max1 - Min0;\n"
|
||||
" *depth = d0<d1 ? d0:d1;\n"
|
||||
" return true;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"bool findSeparatingAxis( __global const ConvexPolyhedronCL* hullA, __global const ConvexPolyhedronCL* hullB, \n"
|
||||
" const float4 posA1,\n"
|
||||
" const float4 ornA,\n"
|
||||
@@ -513,14 +433,12 @@ static const char* satKernelsCL= \
|
||||
" float* dmin)\n"
|
||||
"{\n"
|
||||
" int i = get_global_id(0);\n"
|
||||
"\n"
|
||||
" float4 posA = posA1;\n"
|
||||
" posA.w = 0.f;\n"
|
||||
" float4 posB = posB1;\n"
|
||||
" posB.w = 0.f;\n"
|
||||
" \n"
|
||||
" int curPlaneTests=0;\n"
|
||||
"\n"
|
||||
" {\n"
|
||||
" int numFacesA = hullA->m_numFaces;\n"
|
||||
" // Test normals from hullA\n"
|
||||
@@ -545,8 +463,6 @@ static const char* satKernelsCL= \
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
"\n"
|
||||
" if((dot3F4(-DeltaC2,*sep))>0.0f)\n"
|
||||
" {\n"
|
||||
" *sep = -(*sep);\n"
|
||||
@@ -554,10 +470,6 @@ static const char* satKernelsCL= \
|
||||
" \n"
|
||||
" return true;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"bool findSeparatingAxisEdgeEdge( __global const ConvexPolyhedronCL* hullA, __global const ConvexPolyhedronCL* hullB, \n"
|
||||
" const float4 posA1,\n"
|
||||
" const float4 ornA,\n"
|
||||
@@ -572,29 +484,22 @@ static const char* satKernelsCL= \
|
||||
" float* dmin)\n"
|
||||
"{\n"
|
||||
" int i = get_global_id(0);\n"
|
||||
"\n"
|
||||
" float4 posA = posA1;\n"
|
||||
" posA.w = 0.f;\n"
|
||||
" float4 posB = posB1;\n"
|
||||
" posB.w = 0.f;\n"
|
||||
"\n"
|
||||
" int curPlaneTests=0;\n"
|
||||
"\n"
|
||||
" int curEdgeEdge = 0;\n"
|
||||
" // Test edges\n"
|
||||
" for(int e0=0;e0<hullA->m_numUniqueEdges;e0++)\n"
|
||||
" {\n"
|
||||
" const float4 edge0 = uniqueEdges[hullA->m_uniqueEdgesOffset+e0];\n"
|
||||
" float4 edge0World = qtRotate(ornA,edge0);\n"
|
||||
"\n"
|
||||
" for(int e1=0;e1<hullB->m_numUniqueEdges;e1++)\n"
|
||||
" {\n"
|
||||
" const float4 edge1 = uniqueEdges[hullB->m_uniqueEdgesOffset+e1];\n"
|
||||
" float4 edge1World = qtRotate(ornB,edge1);\n"
|
||||
"\n"
|
||||
"\n"
|
||||
" float4 crossje = cross3(edge0World,edge1World);\n"
|
||||
"\n"
|
||||
" curEdgeEdge++;\n"
|
||||
" if(!IsAlmostZero(crossje))\n"
|
||||
" {\n"
|
||||
@@ -617,10 +522,8 @@ static const char* satKernelsCL= \
|
||||
" float d1 = Max1 - Min0;\n"
|
||||
" dist = d0<d1 ? d0:d1;\n"
|
||||
" result = true;\n"
|
||||
"\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
"\n"
|
||||
" if(dist<*dmin)\n"
|
||||
" {\n"
|
||||
" *dmin = dist;\n"
|
||||
@@ -628,9 +531,7 @@ static const char* satKernelsCL= \
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" \n"
|
||||
" if((dot3F4(-DeltaC2,*sep))>0.0f)\n"
|
||||
" {\n"
|
||||
@@ -638,8 +539,6 @@ static const char* satKernelsCL= \
|
||||
" }\n"
|
||||
" return true;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"// work-in-progress\n"
|
||||
"__kernel void processCompoundPairsKernel( __global const int4* gpuCompoundPairs,\n"
|
||||
" __global const BodyData* rigidBodies, \n"
|
||||
@@ -656,13 +555,11 @@ static const char* satKernelsCL= \
|
||||
" int numCompoundPairs\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"
|
||||
@@ -711,12 +608,10 @@ static const char* satKernelsCL= \
|
||||
" int shapeTypeA = collidables[collidableIndexA].m_shapeType;\n"
|
||||
" int shapeTypeB = collidables[collidableIndexB].m_shapeType;\n"
|
||||
" \n"
|
||||
"\n"
|
||||
" if ((shapeTypeA != SHAPE_CONVEX_HULL) || (shapeTypeB != SHAPE_CONVEX_HULL))\n"
|
||||
" {\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" int hasSeparatingAxis = 5;\n"
|
||||
" \n"
|
||||
" int numFacesA = convexShapes[shapeIndexA].m_numFaces;\n"
|
||||
@@ -737,7 +632,6 @@ static const char* satKernelsCL= \
|
||||
" } else\n"
|
||||
" {\n"
|
||||
" bool sepB = findSeparatingAxis( &convexShapes[shapeIndexB],&convexShapes[shapeIndexA],posB,ornB,posA,ornA,DeltaC2,vertices,uniqueEdges,faces,indices,&sepNormal,&dmin);\n"
|
||||
"\n"
|
||||
" if (!sepB)\n"
|
||||
" {\n"
|
||||
" hasSeparatingAxis = 0;\n"
|
||||
@@ -756,7 +650,6 @@ static const char* satKernelsCL= \
|
||||
" }\n"
|
||||
" \n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"// work-in-progress\n"
|
||||
"__kernel void findCompoundPairsKernel( __global const int4* pairs, \n"
|
||||
" __global const BodyData* rigidBodies, \n"
|
||||
@@ -774,48 +667,36 @@ static const char* satKernelsCL= \
|
||||
" int maxNumCompoundPairsCapacity\n"
|
||||
" )\n"
|
||||
"{\n"
|
||||
"\n"
|
||||
" int i = get_global_id(0);\n"
|
||||
"\n"
|
||||
" if (i<numPairs)\n"
|
||||
" {\n"
|
||||
" int bodyIndexA = pairs[i].x;\n"
|
||||
" int bodyIndexB = pairs[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"
|
||||
"\n"
|
||||
" //once the broadphase avoids static-static pairs, we can remove this test\n"
|
||||
" if ((rigidBodies[bodyIndexA].m_invMass==0) &&(rigidBodies[bodyIndexB].m_invMass==0))\n"
|
||||
" {\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if ((collidables[collidableIndexA].m_shapeType==SHAPE_COMPOUND_OF_CONVEX_HULLS) ||(collidables[collidableIndexB].m_shapeType==SHAPE_COMPOUND_OF_CONVEX_HULLS))\n"
|
||||
" {\n"
|
||||
"\n"
|
||||
" if (collidables[collidableIndexA].m_shapeType==SHAPE_COMPOUND_OF_CONVEX_HULLS) \n"
|
||||
" {\n"
|
||||
"\n"
|
||||
" int numChildrenA = collidables[collidableIndexA].m_numChildShapes;\n"
|
||||
" for (int c=0;c<numChildrenA;c++)\n"
|
||||
" {\n"
|
||||
" int childShapeIndexA = collidables[collidableIndexA].m_shapeIndex+c;\n"
|
||||
" int childColIndexA = gpuChildShapes[childShapeIndexA].m_shapeIndex;\n"
|
||||
"\n"
|
||||
" float4 posA = rigidBodies[bodyIndexA].m_pos;\n"
|
||||
" float4 ornA = rigidBodies[bodyIndexA].m_quat;\n"
|
||||
" float4 childPosA = gpuChildShapes[childShapeIndexA].m_childPosition;\n"
|
||||
" float4 childOrnA = gpuChildShapes[childShapeIndexA].m_childOrientation;\n"
|
||||
" float4 newPosA = qtRotate(ornA,childPosA)+posA;\n"
|
||||
" float4 newOrnA = qtMul(ornA,childOrnA);\n"
|
||||
"\n"
|
||||
" int shapeIndexA = collidables[childColIndexA].m_shapeIndex;\n"
|
||||
"\n"
|
||||
" if (collidables[collidableIndexB].m_shapeType==SHAPE_COMPOUND_OF_CONVEX_HULLS)\n"
|
||||
" {\n"
|
||||
" int numChildrenB = collidables[collidableIndexB].m_numChildShapes;\n"
|
||||
@@ -829,9 +710,7 @@ static const char* satKernelsCL= \
|
||||
" float4 childOrnB = gpuChildShapes[childShapeIndexB].m_childOrientation;\n"
|
||||
" float4 newPosB = transform(&childPosB,&posB,&ornB);\n"
|
||||
" float4 newOrnB = qtMul(ornB,childOrnB);\n"
|
||||
"\n"
|
||||
" int shapeIndexB = collidables[childColIndexB].m_shapeIndex;\n"
|
||||
"\n"
|
||||
" if (1)\n"
|
||||
" {\n"
|
||||
" int numFacesA = convexShapes[shapeIndexA].m_numFaces;\n"
|
||||
@@ -847,7 +726,6 @@ static const char* satKernelsCL= \
|
||||
" float4 ornB =newOrnB;\n"
|
||||
" float4 c1 = transform(&c1local,&posB,&ornB);\n"
|
||||
" const float4 DeltaC2 = c0 - c1;\n"
|
||||
"\n"
|
||||
" {//\n"
|
||||
" int compoundPairIdx = atomic_inc(numCompoundPairsOut);\n"
|
||||
" if (compoundPairIdx<maxNumCompoundPairsCapacity)\n"
|
||||
@@ -875,7 +753,6 @@ static const char* satKernelsCL= \
|
||||
" float4 ornB = rigidBodies[bodyIndexB].m_quat;\n"
|
||||
" float4 c1 = transform(&c1local,&posB,&ornB);\n"
|
||||
" const float4 DeltaC2 = c0 - c1;\n"
|
||||
"\n"
|
||||
" {\n"
|
||||
" int compoundPairIdx = atomic_inc(numCompoundPairsOut);\n"
|
||||
" if (compoundPairIdx<maxNumCompoundPairsCapacity)\n"
|
||||
@@ -902,12 +779,8 @@ static const char* satKernelsCL= \
|
||||
" float4 childOrnB = gpuChildShapes[childShapeIndexB].m_childOrientation;\n"
|
||||
" float4 newPosB = qtRotate(ornB,childPosB)+posB;\n"
|
||||
" float4 newOrnB = qtMul(ornB,childOrnB);\n"
|
||||
"\n"
|
||||
" int shapeIndexB = collidables[childColIndexB].m_shapeIndex;\n"
|
||||
"\n"
|
||||
"\n"
|
||||
" //////////////////////////////////////\n"
|
||||
"\n"
|
||||
" if (1)\n"
|
||||
" {\n"
|
||||
" int numFacesA = convexShapes[shapeIndexA].m_numFaces;\n"
|
||||
@@ -938,7 +811,6 @@ static const char* satKernelsCL= \
|
||||
" }//fi ((collidables[collidableIndexA].m_shapeType==SHAPE_COMPOUND_OF_CONVEX_HULLS) ||(collidables[collidableIndexB].m_shapeType==SHAPE_COMPOUND_OF_CONVEX_HULLS))\n"
|
||||
" }//i<numPairs\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"// work-in-progress\n"
|
||||
"__kernel void findSeparatingAxisKernel( __global const int4* pairs, \n"
|
||||
" __global const BodyData* rigidBodies, \n"
|
||||
@@ -954,16 +826,13 @@ static const char* satKernelsCL= \
|
||||
" int numPairs\n"
|
||||
" )\n"
|
||||
"{\n"
|
||||
"\n"
|
||||
" int i = get_global_id(0);\n"
|
||||
" \n"
|
||||
" if (i<numPairs)\n"
|
||||
" {\n"
|
||||
"\n"
|
||||
" \n"
|
||||
" int bodyIndexA = pairs[i].x;\n"
|
||||
" int bodyIndexB = pairs[i].y;\n"
|
||||
"\n"
|
||||
" int collidableIndexA = rigidBodies[bodyIndexA].m_collidableIdx;\n"
|
||||
" int collidableIndexB = rigidBodies[bodyIndexB].m_collidableIdx;\n"
|
||||
" \n"
|
||||
@@ -978,7 +847,6 @@ static const char* satKernelsCL= \
|
||||
" return;\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
"\n"
|
||||
" if ((collidables[collidableIndexA].m_shapeType!=SHAPE_CONVEX_HULL) ||(collidables[collidableIndexB].m_shapeType!=SHAPE_CONVEX_HULL))\n"
|
||||
" {\n"
|
||||
" hasSeparatingAxis[i] = 0;\n"
|
||||
@@ -990,11 +858,8 @@ static const char* satKernelsCL= \
|
||||
" hasSeparatingAxis[i] = 0;\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" int numFacesA = convexShapes[shapeIndexA].m_numFaces;\n"
|
||||
"\n"
|
||||
" float dmin = FLT_MAX;\n"
|
||||
"\n"
|
||||
" float4 posA = rigidBodies[bodyIndexA].m_pos;\n"
|
||||
" posA.w = 0.f;\n"
|
||||
" float4 posB = rigidBodies[bodyIndexB].m_pos;\n"
|
||||
@@ -1024,7 +889,6 @@ static const char* satKernelsCL= \
|
||||
" DeltaC2,\n"
|
||||
" vertices,uniqueEdges,faces,\n"
|
||||
" indices,&sepNormal,&dmin);\n"
|
||||
"\n"
|
||||
" if (!sepB)\n"
|
||||
" {\n"
|
||||
" hasSeparatingAxis[i] = 0;\n"
|
||||
@@ -1047,12 +911,7 @@ static const char* satKernelsCL= \
|
||||
" }\n"
|
||||
" \n"
|
||||
" }\n"
|
||||
"\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"// work-in-progress\n"
|
||||
"__kernel void findConcaveSeparatingAxisKernel( __global int4* concavePairs,\n"
|
||||
" __global const BodyData* rigidBodies,\n"
|
||||
@@ -1068,30 +927,22 @@ static const char* satKernelsCL= \
|
||||
" int numConcavePairs\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_CONVEX_HULL&&\n"
|
||||
" collidables[collidableIndexB].m_shapeType!=SHAPE_COMPOUND_OF_CONVEX_HULLS)\n"
|
||||
" {\n"
|
||||
" concavePairs[pairIdx].w = -1;\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
" int numFacesA = convexShapes[shapeIndexA].m_numFaces;\n"
|
||||
" int numActualConcaveConvexTests = 0;\n"
|
||||
" \n"
|
||||
@@ -1100,12 +951,10 @@ static const char* satKernelsCL= \
|
||||
" bool overlap = false;\n"
|
||||
" \n"
|
||||
" ConvexPolyhedronCL convexPolyhedronA;\n"
|
||||
"\n"
|
||||
" //add 3 vertices of the triangle\n"
|
||||
" convexPolyhedronA.m_numVertices = 3;\n"
|
||||
" convexPolyhedronA.m_vertexOffset = 0;\n"
|
||||
" float4 localCenter = make_float4(0.f,0.f,0.f,0.f);\n"
|
||||
"\n"
|
||||
" btGpuFace face = faces[convexShapes[shapeIndexA].m_faceOffset+f];\n"
|
||||
" float4 triMinAabb, triMaxAabb;\n"
|
||||
" btAabbCL triAabb;\n"
|
||||
@@ -1122,9 +971,7 @@ static const char* satKernelsCL= \
|
||||
" \n"
|
||||
" triAabb.m_min = min(triAabb.m_min,vert); \n"
|
||||
" triAabb.m_max = max(triAabb.m_max,vert); \n"
|
||||
"\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" overlap = true;\n"
|
||||
" overlap = (triAabb.m_min.x > aabbs[bodyIndexB].m_max.x || triAabb.m_max.x < aabbs[bodyIndexB].m_min.x) ? false : overlap;\n"
|
||||
" overlap = (triAabb.m_min.z > aabbs[bodyIndexB].m_max.z || triAabb.m_max.z < aabbs[bodyIndexB].m_min.z) ? false : overlap;\n"
|
||||
@@ -1135,10 +982,8 @@ static const char* satKernelsCL= \
|
||||
" float dmin = FLT_MAX;\n"
|
||||
" int hasSeparatingAxis=5;\n"
|
||||
" float4 sepAxis=make_float4(1,2,3,4);\n"
|
||||
"\n"
|
||||
" int localCC=0;\n"
|
||||
" numActualConcaveConvexTests++;\n"
|
||||
"\n"
|
||||
" //a triangle has 3 unique edges\n"
|
||||
" convexPolyhedronA.m_numUniqueEdges = 3;\n"
|
||||
" convexPolyhedronA.m_uniqueEdgesOffset = 0;\n"
|
||||
@@ -1147,8 +992,6 @@ static const char* satKernelsCL= \
|
||||
" uniqueEdgesA[0] = (verticesA[1]-verticesA[0]);\n"
|
||||
" uniqueEdgesA[1] = (verticesA[2]-verticesA[1]);\n"
|
||||
" uniqueEdgesA[2] = (verticesA[0]-verticesA[2]);\n"
|
||||
"\n"
|
||||
"\n"
|
||||
" convexPolyhedronA.m_faceOffset = 0;\n"
|
||||
" \n"
|
||||
" float4 normal = make_float4(face.m_plane.x,face.m_plane.y,face.m_plane.z,0.f);\n"
|
||||
@@ -1157,7 +1000,6 @@ static const char* satKernelsCL= \
|
||||
" int indicesA[3+3+2+2+2];\n"
|
||||
" int curUsedIndices=0;\n"
|
||||
" int fidx=0;\n"
|
||||
"\n"
|
||||
" //front size of triangle\n"
|
||||
" {\n"
|
||||
" facesA[fidx].m_indexOffset=curUsedIndices;\n"
|
||||
@@ -1189,7 +1031,6 @@ static const char* satKernelsCL= \
|
||||
" facesA[fidx].m_numIndices=3;\n"
|
||||
" }\n"
|
||||
" fidx++;\n"
|
||||
"\n"
|
||||
" bool addEdgePlanes = true;\n"
|
||||
" if (addEdgePlanes)\n"
|
||||
" {\n"
|
||||
@@ -1202,7 +1043,6 @@ static const char* satKernelsCL= \
|
||||
" \n"
|
||||
" float4 edgeNormal = normalize(cross(normal,v1-v0));\n"
|
||||
" float c = -dot(edgeNormal,v0);\n"
|
||||
"\n"
|
||||
" facesA[fidx].m_numIndices = 2;\n"
|
||||
" facesA[fidx].m_indexOffset=curUsedIndices;\n"
|
||||
" indicesA[curUsedIndices++]=i;\n"
|
||||
@@ -1218,22 +1058,15 @@ static const char* satKernelsCL= \
|
||||
" }\n"
|
||||
" convexPolyhedronA.m_numFaces = TRIANGLE_NUM_CONVEX_FACES;\n"
|
||||
" convexPolyhedronA.m_localCenter = localCenter*(1.f/3.f);\n"
|
||||
"\n"
|
||||
"\n"
|
||||
" float4 posA = rigidBodies[bodyIndexA].m_pos;\n"
|
||||
" posA.w = 0.f;\n"
|
||||
" float4 posB = rigidBodies[bodyIndexB].m_pos;\n"
|
||||
" posB.w = 0.f;\n"
|
||||
"\n"
|
||||
" float4 ornA = rigidBodies[bodyIndexA].m_quat;\n"
|
||||
" float4 ornB =rigidBodies[bodyIndexB].m_quat;\n"
|
||||
"\n"
|
||||
" \n"
|
||||
"\n"
|
||||
"\n"
|
||||
" ///////////////////\n"
|
||||
" ///compound shape support\n"
|
||||
"\n"
|
||||
" if (collidables[collidableIndexB].m_shapeType==SHAPE_COMPOUND_OF_CONVEX_HULLS)\n"
|
||||
" {\n"
|
||||
" int compoundChild = concavePairs[pairIdx].w;\n"
|
||||
@@ -1248,14 +1081,11 @@ static const char* satKernelsCL= \
|
||||
" shapeIndexB = collidables[childColIndexB].m_shapeIndex;\n"
|
||||
" }\n"
|
||||
" //////////////////\n"
|
||||
"\n"
|
||||
" float4 c0local = convexPolyhedronA.m_localCenter;\n"
|
||||
" float4 c0 = transform(&c0local, &posA, &ornA);\n"
|
||||
" float4 c1local = convexShapes[shapeIndexB].m_localCenter;\n"
|
||||
" float4 c1 = transform(&c1local,&posB,&ornB);\n"
|
||||
" const float4 DeltaC2 = c0 - c1;\n"
|
||||
"\n"
|
||||
"\n"
|
||||
" bool sepA = findSeparatingAxisLocalA( &convexPolyhedronA, &convexShapes[shapeIndexB],\n"
|
||||
" posA,ornA,\n"
|
||||
" posB,ornB,\n"
|
||||
@@ -1276,7 +1106,6 @@ static const char* satKernelsCL= \
|
||||
" vertices,uniqueEdges,faces,indices,\n"
|
||||
" verticesA,uniqueEdgesA,facesA,indicesA,\n"
|
||||
" &sepAxis,&dmin);\n"
|
||||
"\n"
|
||||
" if (!sepB)\n"
|
||||
" {\n"
|
||||
" hasSeparatingAxis = 0;\n"
|
||||
|
||||
Reference in New Issue
Block a user