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:
@@ -5,14 +5,11 @@ static const char* rayCastKernelCL= \
|
||||
"#define SHAPE_CONCAVE_TRIMESH 5\n"
|
||||
"#define SHAPE_COMPOUND_OF_CONVEX_HULLS 6\n"
|
||||
"#define SHAPE_SPHERE 7\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"typedef struct\n"
|
||||
"{\n"
|
||||
" float4 m_from;\n"
|
||||
" float4 m_to;\n"
|
||||
"} b3RayInfo;\n"
|
||||
"\n"
|
||||
"typedef struct\n"
|
||||
"{\n"
|
||||
" float m_hitFraction;\n"
|
||||
@@ -22,20 +19,17 @@ static const char* rayCastKernelCL= \
|
||||
" float4 m_hitPoint;\n"
|
||||
" float4 m_hitNormal;\n"
|
||||
"} b3RayHit;\n"
|
||||
"\n"
|
||||
"typedef struct\n"
|
||||
"{\n"
|
||||
" float4 m_pos;\n"
|
||||
" float4 m_quat;\n"
|
||||
" float4 m_linVel;\n"
|
||||
" float4 m_angVel;\n"
|
||||
"\n"
|
||||
" unsigned int m_collidableIdx;\n"
|
||||
" float m_invMass;\n"
|
||||
" float m_restituitionCoeff;\n"
|
||||
" float m_frictionCoeff;\n"
|
||||
"} Body;\n"
|
||||
"\n"
|
||||
"typedef struct Collidable\n"
|
||||
"{\n"
|
||||
" union {\n"
|
||||
@@ -46,53 +40,37 @@ static const char* rayCastKernelCL= \
|
||||
" int m_shapeType;\n"
|
||||
" int m_shapeIndex;\n"
|
||||
"} Collidable;\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"typedef struct \n"
|
||||
"{\n"
|
||||
" float4 m_localCenter;\n"
|
||||
" float4 m_extents;\n"
|
||||
" float4 mC;\n"
|
||||
" float4 mE;\n"
|
||||
"\n"
|
||||
" float m_radius;\n"
|
||||
" 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"
|
||||
"\n"
|
||||
"} ConvexPolyhedronCL;\n"
|
||||
"\n"
|
||||
"typedef struct\n"
|
||||
"{\n"
|
||||
" float4 m_plane;\n"
|
||||
" int m_indexOffset;\n"
|
||||
" int m_numIndices;\n"
|
||||
"} b3GpuFace;\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"
|
||||
"\n"
|
||||
"__inline\n"
|
||||
" Quaternion qtInvert(Quaternion q);\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"__inline\n"
|
||||
" float dot3F4(float4 a, float4 b)\n"
|
||||
"{\n"
|
||||
@@ -100,8 +78,6 @@ static const char* rayCastKernelCL= \
|
||||
" float4 b1 = (float4)(b.xyz,0.f);\n"
|
||||
" return dot(a1, b1);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"__inline\n"
|
||||
" Quaternion qtMul(Quaternion a, Quaternion b)\n"
|
||||
"{\n"
|
||||
@@ -112,7 +88,6 @@ static const char* rayCastKernelCL= \
|
||||
" ans.w = a.w*b.w - dot3F4(a, b);\n"
|
||||
" return ans;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"__inline\n"
|
||||
" Quaternion qtNormalize(Quaternion in)\n"
|
||||
"{\n"
|
||||
@@ -130,39 +105,28 @@ static const char* rayCastKernelCL= \
|
||||
" out = qtMul(out,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"
|
||||
"\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"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"bool rayConvex(float4 rayFromLocal, float4 rayToLocal, int numFaces, int faceOffset,\n"
|
||||
" __global const b3GpuFace* faces, float* hitFraction, float4* hitNormal)\n"
|
||||
"{\n"
|
||||
" rayFromLocal.w = 0.f;\n"
|
||||
" rayToLocal.w = 0.f;\n"
|
||||
" bool result = true;\n"
|
||||
"\n"
|
||||
" float exitFraction = hitFraction[0];\n"
|
||||
" float enterFraction = -0.3f;\n"
|
||||
" float4 curHitNormal = (float4)(0,0,0,0);\n"
|
||||
@@ -200,12 +164,10 @@ static const char* rayCastKernelCL= \
|
||||
" if (exitFraction <= enterFraction)\n"
|
||||
" result = false;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (enterFraction < 0.f)\n"
|
||||
" {\n"
|
||||
" result = false;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (result)\n"
|
||||
" { \n"
|
||||
" hitFraction[0] = enterFraction;\n"
|
||||
@@ -213,12 +175,6 @@ static const char* rayCastKernelCL= \
|
||||
" }\n"
|
||||
" return result;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"bool sphere_intersect(float4 spherePos, float radius, float4 rayFrom, float4 rayTo, float* hitFraction)\n"
|
||||
"{\n"
|
||||
" float4 rs = rayFrom - spherePos;\n"
|
||||
@@ -228,13 +184,10 @@ static const char* rayCastKernelCL= \
|
||||
" float A = dot(rayDir,rayDir);\n"
|
||||
" float B = dot(rs, rayDir);\n"
|
||||
" float C = dot(rs, rs) - (radius * radius);\n"
|
||||
"\n"
|
||||
" float D = B * B - A*C;\n"
|
||||
"\n"
|
||||
" if (D > 0.0f)\n"
|
||||
" {\n"
|
||||
" float t = (-B - sqrt(D))/A;\n"
|
||||
"\n"
|
||||
" if ( (t >= 0.0f) && (t < (*hitFraction)) )\n"
|
||||
" {\n"
|
||||
" *hitFraction = t;\n"
|
||||
@@ -243,7 +196,6 @@ static const char* rayCastKernelCL= \
|
||||
" }\n"
|
||||
" return false;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float4 setInterpolate3(float4 from, float4 to, float t)\n"
|
||||
"{\n"
|
||||
" float s = 1.0f - t;\n"
|
||||
@@ -252,7 +204,6 @@ static const char* rayCastKernelCL= \
|
||||
" result.w = 0.f; \n"
|
||||
" return result; \n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"__kernel void rayCastKernel( \n"
|
||||
" int numRays, \n"
|
||||
" const __global b3RayInfo* rays, \n"
|
||||
@@ -263,23 +214,18 @@ static const char* rayCastKernelCL= \
|
||||
" __global const b3GpuFace* faces,\n"
|
||||
" __global const ConvexPolyhedronCL* convexShapes )\n"
|
||||
"{\n"
|
||||
"\n"
|
||||
" int i = get_global_id(0);\n"
|
||||
" if (i>=numRays)\n"
|
||||
" return;\n"
|
||||
"\n"
|
||||
" hitResults[i].m_hitFraction = 1.f;\n"
|
||||
"\n"
|
||||
" float4 rayFrom = rays[i].m_from;\n"
|
||||
" float4 rayTo = rays[i].m_to;\n"
|
||||
" float hitFraction = 1.f;\n"
|
||||
" float4 hitPoint;\n"
|
||||
" float4 hitNormal;\n"
|
||||
" int hitBodyIndex= -1;\n"
|
||||
"\n"
|
||||
" int cachedCollidableIndex = -1;\n"
|
||||
" Collidable cachedCollidable;\n"
|
||||
"\n"
|
||||
" for (int b=0;b<numBodies;b++)\n"
|
||||
" {\n"
|
||||
" if (hitResults[i].m_hitResult2==b)\n"
|
||||
@@ -294,7 +240,6 @@ static const char* rayCastKernelCL= \
|
||||
" }\n"
|
||||
" if (cachedCollidable.m_shapeType == SHAPE_CONVEX_HULL)\n"
|
||||
" {\n"
|
||||
"\n"
|
||||
" float4 invPos = (float4)(0,0,0,0);\n"
|
||||
" float4 invOrn = (float4)(0,0,0,0);\n"
|
||||
" float4 rayFromLocal = (float4)(0,0,0,0);\n"
|
||||
@@ -327,7 +272,6 @@ static const char* rayCastKernelCL= \
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (hitBodyIndex>=0)\n"
|
||||
" {\n"
|
||||
" hitPoint = setInterpolate3(rayFrom, rayTo,hitFraction);\n"
|
||||
@@ -336,6 +280,5 @@ static const char* rayCastKernelCL= \
|
||||
" hitResults[i].m_hitNormal = normalize(hitNormal);\n"
|
||||
" hitResults[i].m_hitResult0 = hitBodyIndex;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
"}\n"
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user