split OpenCL kernels: fatal error C1091: compiler limit: string exceeds 65535 bytes in length
This commit is contained in:
@@ -17,6 +17,10 @@ premake4 --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/Broadphas
|
|||||||
|
|
||||||
|
|
||||||
premake4 --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/sat.cl" --headerfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/satKernels.h" --stringname="satKernelsCL" stringify
|
premake4 --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/sat.cl" --headerfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/satKernels.h" --stringname="satKernelsCL" stringify
|
||||||
|
premake4 --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/satConcave.cl" --headerfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/satConcaveKernels.h" --stringname="satConcaveKernelsCL" stringify
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
premake4 --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/satClipHullContacts.cl" --headerfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/satClipHullContacts.h" --stringname="satClipKernelsCL" stringify
|
premake4 --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/satClipHullContacts.cl" --headerfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/satClipHullContacts.h" --stringname="satClipKernelsCL" stringify
|
||||||
premake4 --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/primitiveContacts.cl" --headerfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/primitiveContacts.h" --stringname="primitiveContactsKernelsCL" stringify
|
premake4 --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/primitiveContacts.cl" --headerfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/primitiveContacts.h" --stringname="primitiveContactsKernelsCL" stringify
|
||||||
premake4 --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/bvhTraversal.cl" --headerfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/bvhTraversal.h" --stringname="bvhTraversalKernelCL" stringify
|
premake4 --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/bvhTraversal.cl" --headerfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/bvhTraversal.h" --stringname="bvhTraversalKernelCL" stringify
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ subject to the following restrictions:
|
|||||||
bool findSeparatingAxisOnGpu = true;
|
bool findSeparatingAxisOnGpu = true;
|
||||||
bool splitSearchSepAxisConcave = false;
|
bool splitSearchSepAxisConcave = false;
|
||||||
bool splitSearchSepAxisConvex = true;
|
bool splitSearchSepAxisConvex = true;
|
||||||
|
|
||||||
bool bvhTraversalKernelGPU = true;
|
bool bvhTraversalKernelGPU = true;
|
||||||
bool findConcaveSeparatingAxisKernelGPU = true;
|
bool findConcaveSeparatingAxisKernelGPU = true;
|
||||||
bool clipConcaveFacesAndFindContactsCPU = false;//false;//true;
|
bool clipConcaveFacesAndFindContactsCPU = false;//false;//true;
|
||||||
@@ -54,6 +53,8 @@ typedef b3AlignedObjectArray<b3Vector3> b3VertexArray;
|
|||||||
//#include "AdlQuaternion.h"
|
//#include "AdlQuaternion.h"
|
||||||
|
|
||||||
#include "kernels/satKernels.h"
|
#include "kernels/satKernels.h"
|
||||||
|
#include "kernels/satConcaveKernels.h"
|
||||||
|
|
||||||
#include "kernels/satClipHullContacts.h"
|
#include "kernels/satClipHullContacts.h"
|
||||||
#include "kernels/bvhTraversal.h"
|
#include "kernels/bvhTraversal.h"
|
||||||
#include "kernels/primitiveContacts.h"
|
#include "kernels/primitiveContacts.h"
|
||||||
@@ -62,6 +63,10 @@ typedef b3AlignedObjectArray<b3Vector3> b3VertexArray;
|
|||||||
#include "Bullet3Geometry/b3AabbUtil.h"
|
#include "Bullet3Geometry/b3AabbUtil.h"
|
||||||
|
|
||||||
#define BT_NARROWPHASE_SAT_PATH "src/Bullet3OpenCL/NarrowphaseCollision/kernels/sat.cl"
|
#define BT_NARROWPHASE_SAT_PATH "src/Bullet3OpenCL/NarrowphaseCollision/kernels/sat.cl"
|
||||||
|
#define BT_NARROWPHASE_SAT_CONCAVE_PATH "src/Bullet3OpenCL/NarrowphaseCollision/kernels/satConcave.cl"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define BT_NARROWPHASE_CLIPHULL_PATH "src/Bullet3OpenCL/NarrowphaseCollision/kernels/satClipHullContacts.cl"
|
#define BT_NARROWPHASE_CLIPHULL_PATH "src/Bullet3OpenCL/NarrowphaseCollision/kernels/satClipHullContacts.cl"
|
||||||
#define BT_NARROWPHASE_BVH_TRAVERSAL_PATH "src/Bullet3OpenCL/NarrowphaseCollision/kernels/bvhTraversal.cl"
|
#define BT_NARROWPHASE_BVH_TRAVERSAL_PATH "src/Bullet3OpenCL/NarrowphaseCollision/kernels/bvhTraversal.cl"
|
||||||
#define BT_NARROWPHASE_PRIMITIVE_CONTACT_PATH "src/Bullet3OpenCL/NarrowphaseCollision/kernels/primitiveContacts.cl"
|
#define BT_NARROWPHASE_PRIMITIVE_CONTACT_PATH "src/Bullet3OpenCL/NarrowphaseCollision/kernels/primitiveContacts.cl"
|
||||||
@@ -111,7 +116,7 @@ m_dmins(m_context,m_queue)
|
|||||||
if (1)
|
if (1)
|
||||||
{
|
{
|
||||||
const char* src = satKernelsCL;
|
const char* src = satKernelsCL;
|
||||||
|
const char* srcConcave = satConcaveKernelsCL;
|
||||||
char flags[1024]={0};
|
char flags[1024]={0};
|
||||||
//#ifdef CL_PLATFORM_INTEL
|
//#ifdef CL_PLATFORM_INTEL
|
||||||
// sprintf(flags,"-g -s \"%s\"","C:/develop/bullet3_experiments2/opencl/gpu_narrowphase/kernels/sat.cl");
|
// sprintf(flags,"-g -s \"%s\"","C:/develop/bullet3_experiments2/opencl/gpu_narrowphase/kernels/sat.cl");
|
||||||
@@ -120,6 +125,9 @@ m_dmins(m_context,m_queue)
|
|||||||
cl_program satProg = b3OpenCLUtils::compileCLProgramFromString(m_context,m_device,src,&errNum,flags,BT_NARROWPHASE_SAT_PATH);
|
cl_program satProg = b3OpenCLUtils::compileCLProgramFromString(m_context,m_device,src,&errNum,flags,BT_NARROWPHASE_SAT_PATH);
|
||||||
b3Assert(errNum==CL_SUCCESS);
|
b3Assert(errNum==CL_SUCCESS);
|
||||||
|
|
||||||
|
cl_program satConcaveProg = b3OpenCLUtils::compileCLProgramFromString(m_context,m_device,srcConcave,&errNum,flags,BT_NARROWPHASE_SAT_CONCAVE_PATH);
|
||||||
|
b3Assert(errNum==CL_SUCCESS);
|
||||||
|
|
||||||
m_findSeparatingAxisKernel = b3OpenCLUtils::compileCLKernelFromString(m_context, m_device,src, "findSeparatingAxisKernel",&errNum,satProg );
|
m_findSeparatingAxisKernel = b3OpenCLUtils::compileCLKernelFromString(m_context, m_device,src, "findSeparatingAxisKernel",&errNum,satProg );
|
||||||
b3Assert(m_findSeparatingAxisKernel);
|
b3Assert(m_findSeparatingAxisKernel);
|
||||||
b3Assert(errNum==CL_SUCCESS);
|
b3Assert(errNum==CL_SUCCESS);
|
||||||
@@ -136,11 +144,11 @@ m_dmins(m_context,m_queue)
|
|||||||
b3Assert(m_findConcaveSeparatingAxisKernel);
|
b3Assert(m_findConcaveSeparatingAxisKernel);
|
||||||
b3Assert(errNum==CL_SUCCESS);
|
b3Assert(errNum==CL_SUCCESS);
|
||||||
|
|
||||||
m_findConcaveSeparatingAxisVertexFaceKernel = b3OpenCLUtils::compileCLKernelFromString(m_context, m_device,src, "findConcaveSeparatingAxisVertexFaceKernel",&errNum,satProg );
|
m_findConcaveSeparatingAxisVertexFaceKernel = b3OpenCLUtils::compileCLKernelFromString(m_context, m_device,srcConcave, "findConcaveSeparatingAxisVertexFaceKernel",&errNum,satConcaveProg );
|
||||||
b3Assert(m_findConcaveSeparatingAxisVertexFaceKernel);
|
b3Assert(m_findConcaveSeparatingAxisVertexFaceKernel);
|
||||||
b3Assert(errNum==CL_SUCCESS);
|
b3Assert(errNum==CL_SUCCESS);
|
||||||
|
|
||||||
m_findConcaveSeparatingAxisEdgeEdgeKernel = b3OpenCLUtils::compileCLKernelFromString(m_context, m_device,src, "findConcaveSeparatingAxisEdgeEdgeKernel",&errNum,satProg );
|
m_findConcaveSeparatingAxisEdgeEdgeKernel = b3OpenCLUtils::compileCLKernelFromString(m_context, m_device,srcConcave, "findConcaveSeparatingAxisEdgeEdgeKernel",&errNum,satConcaveProg );
|
||||||
b3Assert(m_findConcaveSeparatingAxisEdgeEdgeKernel);
|
b3Assert(m_findConcaveSeparatingAxisEdgeEdgeKernel);
|
||||||
b3Assert(errNum==CL_SUCCESS);
|
b3Assert(errNum==CL_SUCCESS);
|
||||||
|
|
||||||
|
|||||||
@@ -1922,540 +1922,3 @@ __kernel void findConcaveSeparatingAxisKernel( __global int4* concavePairs,
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// work-in-progress
|
|
||||||
__kernel void findConcaveSeparatingAxisVertexFaceKernel( __global int4* concavePairs,
|
|
||||||
__global const BodyData* rigidBodies,
|
|
||||||
__global const btCollidableGpu* collidables,
|
|
||||||
__global const ConvexPolyhedronCL* convexShapes,
|
|
||||||
__global const float4* vertices,
|
|
||||||
__global const float4* uniqueEdges,
|
|
||||||
__global const btGpuFace* faces,
|
|
||||||
__global const int* indices,
|
|
||||||
__global const btGpuChildShape* gpuChildShapes,
|
|
||||||
__global btAabbCL* aabbs,
|
|
||||||
__global float4* concaveSeparatingNormalsOut,
|
|
||||||
__global int* concaveHasSeparatingNormals,
|
|
||||||
__global int4* clippingFacesOut,
|
|
||||||
__global float4* worldVertsA1GPU,
|
|
||||||
__global float4* worldNormalsAGPU,
|
|
||||||
__global float4* worldVertsB1GPU,
|
|
||||||
__global float* dmins,
|
|
||||||
int vertexFaceCapacity,
|
|
||||||
int numConcavePairs
|
|
||||||
)
|
|
||||||
{
|
|
||||||
|
|
||||||
int i = get_global_id(0);
|
|
||||||
if (i>=numConcavePairs)
|
|
||||||
return;
|
|
||||||
|
|
||||||
concaveHasSeparatingNormals[i] = 0;
|
|
||||||
|
|
||||||
int pairIdx = i;
|
|
||||||
|
|
||||||
int bodyIndexA = concavePairs[i].x;
|
|
||||||
int bodyIndexB = concavePairs[i].y;
|
|
||||||
|
|
||||||
int collidableIndexA = rigidBodies[bodyIndexA].m_collidableIdx;
|
|
||||||
int collidableIndexB = rigidBodies[bodyIndexB].m_collidableIdx;
|
|
||||||
|
|
||||||
int shapeIndexA = collidables[collidableIndexA].m_shapeIndex;
|
|
||||||
int shapeIndexB = collidables[collidableIndexB].m_shapeIndex;
|
|
||||||
|
|
||||||
if (collidables[collidableIndexB].m_shapeType!=SHAPE_CONVEX_HULL&&
|
|
||||||
collidables[collidableIndexB].m_shapeType!=SHAPE_COMPOUND_OF_CONVEX_HULLS)
|
|
||||||
{
|
|
||||||
concavePairs[pairIdx].w = -1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int numFacesA = convexShapes[shapeIndexA].m_numFaces;
|
|
||||||
int numActualConcaveConvexTests = 0;
|
|
||||||
|
|
||||||
int f = concavePairs[i].z;
|
|
||||||
|
|
||||||
bool overlap = false;
|
|
||||||
|
|
||||||
ConvexPolyhedronCL convexPolyhedronA;
|
|
||||||
|
|
||||||
//add 3 vertices of the triangle
|
|
||||||
convexPolyhedronA.m_numVertices = 3;
|
|
||||||
convexPolyhedronA.m_vertexOffset = 0;
|
|
||||||
float4 localCenter = make_float4(0.f,0.f,0.f,0.f);
|
|
||||||
|
|
||||||
btGpuFace face = faces[convexShapes[shapeIndexA].m_faceOffset+f];
|
|
||||||
float4 triMinAabb, triMaxAabb;
|
|
||||||
btAabbCL triAabb;
|
|
||||||
triAabb.m_min = make_float4(1e30f,1e30f,1e30f,0.f);
|
|
||||||
triAabb.m_max = make_float4(-1e30f,-1e30f,-1e30f,0.f);
|
|
||||||
|
|
||||||
float4 verticesA[3];
|
|
||||||
for (int i=0;i<3;i++)
|
|
||||||
{
|
|
||||||
int index = indices[face.m_indexOffset+i];
|
|
||||||
float4 vert = vertices[convexShapes[shapeIndexA].m_vertexOffset+index];
|
|
||||||
verticesA[i] = vert;
|
|
||||||
localCenter += vert;
|
|
||||||
|
|
||||||
triAabb.m_min = min(triAabb.m_min,vert);
|
|
||||||
triAabb.m_max = max(triAabb.m_max,vert);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
overlap = true;
|
|
||||||
overlap = (triAabb.m_min.x > aabbs[bodyIndexB].m_max.x || triAabb.m_max.x < aabbs[bodyIndexB].m_min.x) ? false : overlap;
|
|
||||||
overlap = (triAabb.m_min.z > aabbs[bodyIndexB].m_max.z || triAabb.m_max.z < aabbs[bodyIndexB].m_min.z) ? false : overlap;
|
|
||||||
overlap = (triAabb.m_min.y > aabbs[bodyIndexB].m_max.y || triAabb.m_max.y < aabbs[bodyIndexB].m_min.y) ? false : overlap;
|
|
||||||
|
|
||||||
if (overlap)
|
|
||||||
{
|
|
||||||
float dmin = FLT_MAX;
|
|
||||||
int hasSeparatingAxis=5;
|
|
||||||
float4 sepAxis=make_float4(1,2,3,4);
|
|
||||||
|
|
||||||
int localCC=0;
|
|
||||||
numActualConcaveConvexTests++;
|
|
||||||
|
|
||||||
//a triangle has 3 unique edges
|
|
||||||
convexPolyhedronA.m_numUniqueEdges = 3;
|
|
||||||
convexPolyhedronA.m_uniqueEdgesOffset = 0;
|
|
||||||
float4 uniqueEdgesA[3];
|
|
||||||
|
|
||||||
uniqueEdgesA[0] = (verticesA[1]-verticesA[0]);
|
|
||||||
uniqueEdgesA[1] = (verticesA[2]-verticesA[1]);
|
|
||||||
uniqueEdgesA[2] = (verticesA[0]-verticesA[2]);
|
|
||||||
|
|
||||||
|
|
||||||
convexPolyhedronA.m_faceOffset = 0;
|
|
||||||
|
|
||||||
float4 normal = make_float4(face.m_plane.x,face.m_plane.y,face.m_plane.z,0.f);
|
|
||||||
|
|
||||||
btGpuFace facesA[TRIANGLE_NUM_CONVEX_FACES];
|
|
||||||
int indicesA[3+3+2+2+2];
|
|
||||||
int curUsedIndices=0;
|
|
||||||
int fidx=0;
|
|
||||||
|
|
||||||
//front size of triangle
|
|
||||||
{
|
|
||||||
facesA[fidx].m_indexOffset=curUsedIndices;
|
|
||||||
indicesA[0] = 0;
|
|
||||||
indicesA[1] = 1;
|
|
||||||
indicesA[2] = 2;
|
|
||||||
curUsedIndices+=3;
|
|
||||||
float c = face.m_plane.w;
|
|
||||||
facesA[fidx].m_plane.x = normal.x;
|
|
||||||
facesA[fidx].m_plane.y = normal.y;
|
|
||||||
facesA[fidx].m_plane.z = normal.z;
|
|
||||||
facesA[fidx].m_plane.w = c;
|
|
||||||
facesA[fidx].m_numIndices=3;
|
|
||||||
}
|
|
||||||
fidx++;
|
|
||||||
//back size of triangle
|
|
||||||
{
|
|
||||||
facesA[fidx].m_indexOffset=curUsedIndices;
|
|
||||||
indicesA[3]=2;
|
|
||||||
indicesA[4]=1;
|
|
||||||
indicesA[5]=0;
|
|
||||||
curUsedIndices+=3;
|
|
||||||
float c = dot(normal,verticesA[0]);
|
|
||||||
float c1 = -face.m_plane.w;
|
|
||||||
facesA[fidx].m_plane.x = -normal.x;
|
|
||||||
facesA[fidx].m_plane.y = -normal.y;
|
|
||||||
facesA[fidx].m_plane.z = -normal.z;
|
|
||||||
facesA[fidx].m_plane.w = c;
|
|
||||||
facesA[fidx].m_numIndices=3;
|
|
||||||
}
|
|
||||||
fidx++;
|
|
||||||
|
|
||||||
bool addEdgePlanes = true;
|
|
||||||
if (addEdgePlanes)
|
|
||||||
{
|
|
||||||
int numVertices=3;
|
|
||||||
int prevVertex = numVertices-1;
|
|
||||||
for (int i=0;i<numVertices;i++)
|
|
||||||
{
|
|
||||||
float4 v0 = verticesA[i];
|
|
||||||
float4 v1 = verticesA[prevVertex];
|
|
||||||
|
|
||||||
float4 edgeNormal = normalize(cross(normal,v1-v0));
|
|
||||||
float c = -dot(edgeNormal,v0);
|
|
||||||
|
|
||||||
facesA[fidx].m_numIndices = 2;
|
|
||||||
facesA[fidx].m_indexOffset=curUsedIndices;
|
|
||||||
indicesA[curUsedIndices++]=i;
|
|
||||||
indicesA[curUsedIndices++]=prevVertex;
|
|
||||||
|
|
||||||
facesA[fidx].m_plane.x = edgeNormal.x;
|
|
||||||
facesA[fidx].m_plane.y = edgeNormal.y;
|
|
||||||
facesA[fidx].m_plane.z = edgeNormal.z;
|
|
||||||
facesA[fidx].m_plane.w = c;
|
|
||||||
fidx++;
|
|
||||||
prevVertex = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
convexPolyhedronA.m_numFaces = TRIANGLE_NUM_CONVEX_FACES;
|
|
||||||
convexPolyhedronA.m_localCenter = localCenter*(1.f/3.f);
|
|
||||||
|
|
||||||
|
|
||||||
float4 posA = rigidBodies[bodyIndexA].m_pos;
|
|
||||||
posA.w = 0.f;
|
|
||||||
float4 posB = rigidBodies[bodyIndexB].m_pos;
|
|
||||||
posB.w = 0.f;
|
|
||||||
|
|
||||||
float4 ornA = rigidBodies[bodyIndexA].m_quat;
|
|
||||||
float4 ornB =rigidBodies[bodyIndexB].m_quat;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////
|
|
||||||
///compound shape support
|
|
||||||
|
|
||||||
if (collidables[collidableIndexB].m_shapeType==SHAPE_COMPOUND_OF_CONVEX_HULLS)
|
|
||||||
{
|
|
||||||
int compoundChild = concavePairs[pairIdx].w;
|
|
||||||
int childShapeIndexB = compoundChild;//collidables[collidableIndexB].m_shapeIndex+compoundChild;
|
|
||||||
int childColIndexB = gpuChildShapes[childShapeIndexB].m_shapeIndex;
|
|
||||||
float4 childPosB = gpuChildShapes[childShapeIndexB].m_childPosition;
|
|
||||||
float4 childOrnB = gpuChildShapes[childShapeIndexB].m_childOrientation;
|
|
||||||
float4 newPosB = transform(&childPosB,&posB,&ornB);
|
|
||||||
float4 newOrnB = qtMul(ornB,childOrnB);
|
|
||||||
posB = newPosB;
|
|
||||||
ornB = newOrnB;
|
|
||||||
shapeIndexB = collidables[childColIndexB].m_shapeIndex;
|
|
||||||
}
|
|
||||||
//////////////////
|
|
||||||
|
|
||||||
float4 c0local = convexPolyhedronA.m_localCenter;
|
|
||||||
float4 c0 = transform(&c0local, &posA, &ornA);
|
|
||||||
float4 c1local = convexShapes[shapeIndexB].m_localCenter;
|
|
||||||
float4 c1 = transform(&c1local,&posB,&ornB);
|
|
||||||
const float4 DeltaC2 = c0 - c1;
|
|
||||||
|
|
||||||
|
|
||||||
bool sepA = findSeparatingAxisLocalA( &convexPolyhedronA, &convexShapes[shapeIndexB],
|
|
||||||
posA,ornA,
|
|
||||||
posB,ornB,
|
|
||||||
DeltaC2,
|
|
||||||
verticesA,uniqueEdgesA,facesA,indicesA,
|
|
||||||
vertices,uniqueEdges,faces,indices,
|
|
||||||
&sepAxis,&dmin);
|
|
||||||
hasSeparatingAxis = 4;
|
|
||||||
if (!sepA)
|
|
||||||
{
|
|
||||||
hasSeparatingAxis = 0;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
bool sepB = findSeparatingAxisLocalB( &convexShapes[shapeIndexB],&convexPolyhedronA,
|
|
||||||
posB,ornB,
|
|
||||||
posA,ornA,
|
|
||||||
DeltaC2,
|
|
||||||
vertices,uniqueEdges,faces,indices,
|
|
||||||
verticesA,uniqueEdgesA,facesA,indicesA,
|
|
||||||
&sepAxis,&dmin);
|
|
||||||
|
|
||||||
if (!sepB)
|
|
||||||
{
|
|
||||||
hasSeparatingAxis = 0;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
hasSeparatingAxis = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasSeparatingAxis)
|
|
||||||
{
|
|
||||||
dmins[i] = dmin;
|
|
||||||
concaveSeparatingNormalsOut[pairIdx]=sepAxis;
|
|
||||||
concaveHasSeparatingNormals[i]=1;
|
|
||||||
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
//mark this pair as in-active
|
|
||||||
concavePairs[pairIdx].w = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//mark this pair as in-active
|
|
||||||
concavePairs[pairIdx].w = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// work-in-progress
|
|
||||||
__kernel void findConcaveSeparatingAxisEdgeEdgeKernel( __global int4* concavePairs,
|
|
||||||
__global const BodyData* rigidBodies,
|
|
||||||
__global const btCollidableGpu* collidables,
|
|
||||||
__global const ConvexPolyhedronCL* convexShapes,
|
|
||||||
__global const float4* vertices,
|
|
||||||
__global const float4* uniqueEdges,
|
|
||||||
__global const btGpuFace* faces,
|
|
||||||
__global const int* indices,
|
|
||||||
__global const btGpuChildShape* gpuChildShapes,
|
|
||||||
__global btAabbCL* aabbs,
|
|
||||||
__global float4* concaveSeparatingNormalsOut,
|
|
||||||
__global int* concaveHasSeparatingNormals,
|
|
||||||
__global int4* clippingFacesOut,
|
|
||||||
__global float4* worldVertsA1GPU,
|
|
||||||
__global float4* worldNormalsAGPU,
|
|
||||||
__global float4* worldVertsB1GPU,
|
|
||||||
__global float* dmins,
|
|
||||||
int vertexFaceCapacity,
|
|
||||||
int numConcavePairs
|
|
||||||
)
|
|
||||||
{
|
|
||||||
|
|
||||||
int i = get_global_id(0);
|
|
||||||
if (i>=numConcavePairs)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!concaveHasSeparatingNormals[i])
|
|
||||||
return;
|
|
||||||
|
|
||||||
int pairIdx = i;
|
|
||||||
|
|
||||||
int bodyIndexA = concavePairs[i].x;
|
|
||||||
int bodyIndexB = concavePairs[i].y;
|
|
||||||
|
|
||||||
int collidableIndexA = rigidBodies[bodyIndexA].m_collidableIdx;
|
|
||||||
int collidableIndexB = rigidBodies[bodyIndexB].m_collidableIdx;
|
|
||||||
|
|
||||||
int shapeIndexA = collidables[collidableIndexA].m_shapeIndex;
|
|
||||||
int shapeIndexB = collidables[collidableIndexB].m_shapeIndex;
|
|
||||||
|
|
||||||
|
|
||||||
int numFacesA = convexShapes[shapeIndexA].m_numFaces;
|
|
||||||
int numActualConcaveConvexTests = 0;
|
|
||||||
|
|
||||||
int f = concavePairs[i].z;
|
|
||||||
|
|
||||||
bool overlap = false;
|
|
||||||
|
|
||||||
ConvexPolyhedronCL convexPolyhedronA;
|
|
||||||
|
|
||||||
//add 3 vertices of the triangle
|
|
||||||
convexPolyhedronA.m_numVertices = 3;
|
|
||||||
convexPolyhedronA.m_vertexOffset = 0;
|
|
||||||
float4 localCenter = make_float4(0.f,0.f,0.f,0.f);
|
|
||||||
|
|
||||||
btGpuFace face = faces[convexShapes[shapeIndexA].m_faceOffset+f];
|
|
||||||
float4 triMinAabb, triMaxAabb;
|
|
||||||
btAabbCL triAabb;
|
|
||||||
triAabb.m_min = make_float4(1e30f,1e30f,1e30f,0.f);
|
|
||||||
triAabb.m_max = make_float4(-1e30f,-1e30f,-1e30f,0.f);
|
|
||||||
|
|
||||||
float4 verticesA[3];
|
|
||||||
for (int i=0;i<3;i++)
|
|
||||||
{
|
|
||||||
int index = indices[face.m_indexOffset+i];
|
|
||||||
float4 vert = vertices[convexShapes[shapeIndexA].m_vertexOffset+index];
|
|
||||||
verticesA[i] = vert;
|
|
||||||
localCenter += vert;
|
|
||||||
|
|
||||||
triAabb.m_min = min(triAabb.m_min,vert);
|
|
||||||
triAabb.m_max = max(triAabb.m_max,vert);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
overlap = true;
|
|
||||||
overlap = (triAabb.m_min.x > aabbs[bodyIndexB].m_max.x || triAabb.m_max.x < aabbs[bodyIndexB].m_min.x) ? false : overlap;
|
|
||||||
overlap = (triAabb.m_min.z > aabbs[bodyIndexB].m_max.z || triAabb.m_max.z < aabbs[bodyIndexB].m_min.z) ? false : overlap;
|
|
||||||
overlap = (triAabb.m_min.y > aabbs[bodyIndexB].m_max.y || triAabb.m_max.y < aabbs[bodyIndexB].m_min.y) ? false : overlap;
|
|
||||||
|
|
||||||
if (overlap)
|
|
||||||
{
|
|
||||||
float dmin = dmins[i];
|
|
||||||
int hasSeparatingAxis=5;
|
|
||||||
float4 sepAxis=make_float4(1,2,3,4);
|
|
||||||
sepAxis = concaveSeparatingNormalsOut[pairIdx];
|
|
||||||
|
|
||||||
int localCC=0;
|
|
||||||
numActualConcaveConvexTests++;
|
|
||||||
|
|
||||||
//a triangle has 3 unique edges
|
|
||||||
convexPolyhedronA.m_numUniqueEdges = 3;
|
|
||||||
convexPolyhedronA.m_uniqueEdgesOffset = 0;
|
|
||||||
float4 uniqueEdgesA[3];
|
|
||||||
|
|
||||||
uniqueEdgesA[0] = (verticesA[1]-verticesA[0]);
|
|
||||||
uniqueEdgesA[1] = (verticesA[2]-verticesA[1]);
|
|
||||||
uniqueEdgesA[2] = (verticesA[0]-verticesA[2]);
|
|
||||||
|
|
||||||
|
|
||||||
convexPolyhedronA.m_faceOffset = 0;
|
|
||||||
|
|
||||||
float4 normal = make_float4(face.m_plane.x,face.m_plane.y,face.m_plane.z,0.f);
|
|
||||||
|
|
||||||
btGpuFace facesA[TRIANGLE_NUM_CONVEX_FACES];
|
|
||||||
int indicesA[3+3+2+2+2];
|
|
||||||
int curUsedIndices=0;
|
|
||||||
int fidx=0;
|
|
||||||
|
|
||||||
//front size of triangle
|
|
||||||
{
|
|
||||||
facesA[fidx].m_indexOffset=curUsedIndices;
|
|
||||||
indicesA[0] = 0;
|
|
||||||
indicesA[1] = 1;
|
|
||||||
indicesA[2] = 2;
|
|
||||||
curUsedIndices+=3;
|
|
||||||
float c = face.m_plane.w;
|
|
||||||
facesA[fidx].m_plane.x = normal.x;
|
|
||||||
facesA[fidx].m_plane.y = normal.y;
|
|
||||||
facesA[fidx].m_plane.z = normal.z;
|
|
||||||
facesA[fidx].m_plane.w = c;
|
|
||||||
facesA[fidx].m_numIndices=3;
|
|
||||||
}
|
|
||||||
fidx++;
|
|
||||||
//back size of triangle
|
|
||||||
{
|
|
||||||
facesA[fidx].m_indexOffset=curUsedIndices;
|
|
||||||
indicesA[3]=2;
|
|
||||||
indicesA[4]=1;
|
|
||||||
indicesA[5]=0;
|
|
||||||
curUsedIndices+=3;
|
|
||||||
float c = dot(normal,verticesA[0]);
|
|
||||||
float c1 = -face.m_plane.w;
|
|
||||||
facesA[fidx].m_plane.x = -normal.x;
|
|
||||||
facesA[fidx].m_plane.y = -normal.y;
|
|
||||||
facesA[fidx].m_plane.z = -normal.z;
|
|
||||||
facesA[fidx].m_plane.w = c;
|
|
||||||
facesA[fidx].m_numIndices=3;
|
|
||||||
}
|
|
||||||
fidx++;
|
|
||||||
|
|
||||||
bool addEdgePlanes = true;
|
|
||||||
if (addEdgePlanes)
|
|
||||||
{
|
|
||||||
int numVertices=3;
|
|
||||||
int prevVertex = numVertices-1;
|
|
||||||
for (int i=0;i<numVertices;i++)
|
|
||||||
{
|
|
||||||
float4 v0 = verticesA[i];
|
|
||||||
float4 v1 = verticesA[prevVertex];
|
|
||||||
|
|
||||||
float4 edgeNormal = normalize(cross(normal,v1-v0));
|
|
||||||
float c = -dot(edgeNormal,v0);
|
|
||||||
|
|
||||||
facesA[fidx].m_numIndices = 2;
|
|
||||||
facesA[fidx].m_indexOffset=curUsedIndices;
|
|
||||||
indicesA[curUsedIndices++]=i;
|
|
||||||
indicesA[curUsedIndices++]=prevVertex;
|
|
||||||
|
|
||||||
facesA[fidx].m_plane.x = edgeNormal.x;
|
|
||||||
facesA[fidx].m_plane.y = edgeNormal.y;
|
|
||||||
facesA[fidx].m_plane.z = edgeNormal.z;
|
|
||||||
facesA[fidx].m_plane.w = c;
|
|
||||||
fidx++;
|
|
||||||
prevVertex = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
convexPolyhedronA.m_numFaces = TRIANGLE_NUM_CONVEX_FACES;
|
|
||||||
convexPolyhedronA.m_localCenter = localCenter*(1.f/3.f);
|
|
||||||
|
|
||||||
|
|
||||||
float4 posA = rigidBodies[bodyIndexA].m_pos;
|
|
||||||
posA.w = 0.f;
|
|
||||||
float4 posB = rigidBodies[bodyIndexB].m_pos;
|
|
||||||
posB.w = 0.f;
|
|
||||||
|
|
||||||
float4 ornA = rigidBodies[bodyIndexA].m_quat;
|
|
||||||
float4 ornB =rigidBodies[bodyIndexB].m_quat;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////
|
|
||||||
///compound shape support
|
|
||||||
|
|
||||||
if (collidables[collidableIndexB].m_shapeType==SHAPE_COMPOUND_OF_CONVEX_HULLS)
|
|
||||||
{
|
|
||||||
int compoundChild = concavePairs[pairIdx].w;
|
|
||||||
int childShapeIndexB = compoundChild;//collidables[collidableIndexB].m_shapeIndex+compoundChild;
|
|
||||||
int childColIndexB = gpuChildShapes[childShapeIndexB].m_shapeIndex;
|
|
||||||
float4 childPosB = gpuChildShapes[childShapeIndexB].m_childPosition;
|
|
||||||
float4 childOrnB = gpuChildShapes[childShapeIndexB].m_childOrientation;
|
|
||||||
float4 newPosB = transform(&childPosB,&posB,&ornB);
|
|
||||||
float4 newOrnB = qtMul(ornB,childOrnB);
|
|
||||||
posB = newPosB;
|
|
||||||
ornB = newOrnB;
|
|
||||||
shapeIndexB = collidables[childColIndexB].m_shapeIndex;
|
|
||||||
}
|
|
||||||
//////////////////
|
|
||||||
|
|
||||||
float4 c0local = convexPolyhedronA.m_localCenter;
|
|
||||||
float4 c0 = transform(&c0local, &posA, &ornA);
|
|
||||||
float4 c1local = convexShapes[shapeIndexB].m_localCenter;
|
|
||||||
float4 c1 = transform(&c1local,&posB,&ornB);
|
|
||||||
const float4 DeltaC2 = c0 - c1;
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
bool sepEE = findSeparatingAxisEdgeEdgeLocalA( &convexPolyhedronA, &convexShapes[shapeIndexB],
|
|
||||||
posA,ornA,
|
|
||||||
posB,ornB,
|
|
||||||
DeltaC2,
|
|
||||||
verticesA,uniqueEdgesA,facesA,indicesA,
|
|
||||||
vertices,uniqueEdges,faces,indices,
|
|
||||||
&sepAxis,&dmin);
|
|
||||||
|
|
||||||
if (!sepEE)
|
|
||||||
{
|
|
||||||
hasSeparatingAxis = 0;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
hasSeparatingAxis = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (hasSeparatingAxis)
|
|
||||||
{
|
|
||||||
sepAxis.w = dmin;
|
|
||||||
dmins[i] = dmin;
|
|
||||||
concaveSeparatingNormalsOut[pairIdx]=sepAxis;
|
|
||||||
concaveHasSeparatingNormals[i]=1;
|
|
||||||
|
|
||||||
float minDist = -1e30f;
|
|
||||||
float maxDist = 0.02f;
|
|
||||||
|
|
||||||
findClippingFaces(sepAxis,
|
|
||||||
&convexPolyhedronA,
|
|
||||||
&convexShapes[shapeIndexB],
|
|
||||||
posA,ornA,
|
|
||||||
posB,ornB,
|
|
||||||
worldVertsA1GPU,
|
|
||||||
worldNormalsAGPU,
|
|
||||||
worldVertsB1GPU,
|
|
||||||
vertexFaceCapacity,
|
|
||||||
minDist, maxDist,
|
|
||||||
verticesA,
|
|
||||||
facesA,
|
|
||||||
indicesA,
|
|
||||||
vertices,
|
|
||||||
faces,
|
|
||||||
indices,
|
|
||||||
clippingFacesOut, pairIdx);
|
|
||||||
|
|
||||||
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
//mark this pair as in-active
|
|
||||||
concavePairs[pairIdx].w = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//mark this pair as in-active
|
|
||||||
concavePairs[pairIdx].w = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
1213
src/Bullet3OpenCL/NarrowphaseCollision/kernels/satConcave.cl
Normal file
1213
src/Bullet3OpenCL/NarrowphaseCollision/kernels/satConcave.cl
Normal file
File diff suppressed because it is too large
Load Diff
1416
src/Bullet3OpenCL/NarrowphaseCollision/kernels/satConcaveKernels.h
Normal file
1416
src/Bullet3OpenCL/NarrowphaseCollision/kernels/satConcaveKernels.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1980,531 +1980,4 @@ static const char* satKernelsCL= \
|
|||||||
" concavePairs[pairIdx].w = -1;\n"
|
" concavePairs[pairIdx].w = -1;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"// work-in-progress\n"
|
|
||||||
"__kernel void findConcaveSeparatingAxisVertexFaceKernel( __global int4* concavePairs,\n"
|
|
||||||
" __global const BodyData* rigidBodies,\n"
|
|
||||||
" __global const btCollidableGpu* collidables,\n"
|
|
||||||
" __global const ConvexPolyhedronCL* convexShapes,\n"
|
|
||||||
" __global const float4* vertices,\n"
|
|
||||||
" __global const float4* uniqueEdges,\n"
|
|
||||||
" __global const btGpuFace* faces,\n"
|
|
||||||
" __global const int* indices,\n"
|
|
||||||
" __global const btGpuChildShape* gpuChildShapes,\n"
|
|
||||||
" __global btAabbCL* aabbs,\n"
|
|
||||||
" __global float4* concaveSeparatingNormalsOut,\n"
|
|
||||||
" __global int* concaveHasSeparatingNormals,\n"
|
|
||||||
" __global int4* clippingFacesOut,\n"
|
|
||||||
" __global float4* worldVertsA1GPU,\n"
|
|
||||||
" __global float4* worldNormalsAGPU,\n"
|
|
||||||
" __global float4* worldVertsB1GPU,\n"
|
|
||||||
" __global float* dmins,\n"
|
|
||||||
" int vertexFaceCapacity,\n"
|
|
||||||
" int numConcavePairs\n"
|
|
||||||
" )\n"
|
|
||||||
"{\n"
|
|
||||||
" \n"
|
|
||||||
" int i = get_global_id(0);\n"
|
|
||||||
" if (i>=numConcavePairs)\n"
|
|
||||||
" return;\n"
|
|
||||||
" \n"
|
|
||||||
" concaveHasSeparatingNormals[i] = 0;\n"
|
|
||||||
" \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"
|
|
||||||
" int f = concavePairs[i].z;\n"
|
|
||||||
" \n"
|
|
||||||
" 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"
|
|
||||||
" triAabb.m_min = make_float4(1e30f,1e30f,1e30f,0.f);\n"
|
|
||||||
" triAabb.m_max = make_float4(-1e30f,-1e30f,-1e30f,0.f);\n"
|
|
||||||
" \n"
|
|
||||||
" float4 verticesA[3];\n"
|
|
||||||
" for (int i=0;i<3;i++)\n"
|
|
||||||
" {\n"
|
|
||||||
" int index = indices[face.m_indexOffset+i];\n"
|
|
||||||
" float4 vert = vertices[convexShapes[shapeIndexA].m_vertexOffset+index];\n"
|
|
||||||
" verticesA[i] = vert;\n"
|
|
||||||
" localCenter += vert;\n"
|
|
||||||
" \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"
|
|
||||||
" overlap = (triAabb.m_min.y > aabbs[bodyIndexB].m_max.y || triAabb.m_max.y < aabbs[bodyIndexB].m_min.y) ? false : overlap;\n"
|
|
||||||
" \n"
|
|
||||||
" if (overlap)\n"
|
|
||||||
" {\n"
|
|
||||||
" 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"
|
|
||||||
" float4 uniqueEdgesA[3];\n"
|
|
||||||
" \n"
|
|
||||||
" 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"
|
|
||||||
" \n"
|
|
||||||
" btGpuFace facesA[TRIANGLE_NUM_CONVEX_FACES];\n"
|
|
||||||
" 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"
|
|
||||||
" indicesA[0] = 0;\n"
|
|
||||||
" indicesA[1] = 1;\n"
|
|
||||||
" indicesA[2] = 2;\n"
|
|
||||||
" curUsedIndices+=3;\n"
|
|
||||||
" float c = face.m_plane.w;\n"
|
|
||||||
" facesA[fidx].m_plane.x = normal.x;\n"
|
|
||||||
" facesA[fidx].m_plane.y = normal.y;\n"
|
|
||||||
" facesA[fidx].m_plane.z = normal.z;\n"
|
|
||||||
" facesA[fidx].m_plane.w = c;\n"
|
|
||||||
" facesA[fidx].m_numIndices=3;\n"
|
|
||||||
" }\n"
|
|
||||||
" fidx++;\n"
|
|
||||||
" //back size of triangle\n"
|
|
||||||
" {\n"
|
|
||||||
" facesA[fidx].m_indexOffset=curUsedIndices;\n"
|
|
||||||
" indicesA[3]=2;\n"
|
|
||||||
" indicesA[4]=1;\n"
|
|
||||||
" indicesA[5]=0;\n"
|
|
||||||
" curUsedIndices+=3;\n"
|
|
||||||
" float c = dot(normal,verticesA[0]);\n"
|
|
||||||
" float c1 = -face.m_plane.w;\n"
|
|
||||||
" facesA[fidx].m_plane.x = -normal.x;\n"
|
|
||||||
" facesA[fidx].m_plane.y = -normal.y;\n"
|
|
||||||
" facesA[fidx].m_plane.z = -normal.z;\n"
|
|
||||||
" facesA[fidx].m_plane.w = c;\n"
|
|
||||||
" facesA[fidx].m_numIndices=3;\n"
|
|
||||||
" }\n"
|
|
||||||
" fidx++;\n"
|
|
||||||
" \n"
|
|
||||||
" bool addEdgePlanes = true;\n"
|
|
||||||
" if (addEdgePlanes)\n"
|
|
||||||
" {\n"
|
|
||||||
" int numVertices=3;\n"
|
|
||||||
" int prevVertex = numVertices-1;\n"
|
|
||||||
" for (int i=0;i<numVertices;i++)\n"
|
|
||||||
" {\n"
|
|
||||||
" float4 v0 = verticesA[i];\n"
|
|
||||||
" float4 v1 = verticesA[prevVertex];\n"
|
|
||||||
" \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"
|
|
||||||
" indicesA[curUsedIndices++]=prevVertex;\n"
|
|
||||||
" \n"
|
|
||||||
" facesA[fidx].m_plane.x = edgeNormal.x;\n"
|
|
||||||
" facesA[fidx].m_plane.y = edgeNormal.y;\n"
|
|
||||||
" facesA[fidx].m_plane.z = edgeNormal.z;\n"
|
|
||||||
" facesA[fidx].m_plane.w = c;\n"
|
|
||||||
" fidx++;\n"
|
|
||||||
" prevVertex = i;\n"
|
|
||||||
" }\n"
|
|
||||||
" }\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"
|
|
||||||
" int childShapeIndexB = compoundChild;//collidables[collidableIndexB].m_shapeIndex+compoundChild;\n"
|
|
||||||
" int childColIndexB = gpuChildShapes[childShapeIndexB].m_shapeIndex;\n"
|
|
||||||
" float4 childPosB = gpuChildShapes[childShapeIndexB].m_childPosition;\n"
|
|
||||||
" float4 childOrnB = gpuChildShapes[childShapeIndexB].m_childOrientation;\n"
|
|
||||||
" float4 newPosB = transform(&childPosB,&posB,&ornB);\n"
|
|
||||||
" float4 newOrnB = qtMul(ornB,childOrnB);\n"
|
|
||||||
" posB = newPosB;\n"
|
|
||||||
" ornB = newOrnB;\n"
|
|
||||||
" 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"
|
|
||||||
" DeltaC2,\n"
|
|
||||||
" verticesA,uniqueEdgesA,facesA,indicesA,\n"
|
|
||||||
" vertices,uniqueEdges,faces,indices,\n"
|
|
||||||
" &sepAxis,&dmin);\n"
|
|
||||||
" hasSeparatingAxis = 4;\n"
|
|
||||||
" if (!sepA)\n"
|
|
||||||
" {\n"
|
|
||||||
" hasSeparatingAxis = 0;\n"
|
|
||||||
" } else\n"
|
|
||||||
" {\n"
|
|
||||||
" bool sepB = findSeparatingAxisLocalB( &convexShapes[shapeIndexB],&convexPolyhedronA,\n"
|
|
||||||
" posB,ornB,\n"
|
|
||||||
" posA,ornA,\n"
|
|
||||||
" DeltaC2,\n"
|
|
||||||
" vertices,uniqueEdges,faces,indices,\n"
|
|
||||||
" verticesA,uniqueEdgesA,facesA,indicesA,\n"
|
|
||||||
" &sepAxis,&dmin);\n"
|
|
||||||
" \n"
|
|
||||||
" if (!sepB)\n"
|
|
||||||
" {\n"
|
|
||||||
" hasSeparatingAxis = 0;\n"
|
|
||||||
" } else\n"
|
|
||||||
" {\n"
|
|
||||||
" hasSeparatingAxis = 1;\n"
|
|
||||||
" }\n"
|
|
||||||
" } \n"
|
|
||||||
" \n"
|
|
||||||
" if (hasSeparatingAxis)\n"
|
|
||||||
" {\n"
|
|
||||||
" dmins[i] = dmin;\n"
|
|
||||||
" concaveSeparatingNormalsOut[pairIdx]=sepAxis;\n"
|
|
||||||
" concaveHasSeparatingNormals[i]=1;\n"
|
|
||||||
" \n"
|
|
||||||
" } else\n"
|
|
||||||
" { \n"
|
|
||||||
" //mark this pair as in-active\n"
|
|
||||||
" concavePairs[pairIdx].w = -1;\n"
|
|
||||||
" }\n"
|
|
||||||
" }\n"
|
|
||||||
" else\n"
|
|
||||||
" { \n"
|
|
||||||
" //mark this pair as in-active\n"
|
|
||||||
" concavePairs[pairIdx].w = -1;\n"
|
|
||||||
" }\n"
|
|
||||||
"}\n"
|
|
||||||
"// work-in-progress\n"
|
|
||||||
"__kernel void findConcaveSeparatingAxisEdgeEdgeKernel( __global int4* concavePairs,\n"
|
|
||||||
" __global const BodyData* rigidBodies,\n"
|
|
||||||
" __global const btCollidableGpu* collidables,\n"
|
|
||||||
" __global const ConvexPolyhedronCL* convexShapes,\n"
|
|
||||||
" __global const float4* vertices,\n"
|
|
||||||
" __global const float4* uniqueEdges,\n"
|
|
||||||
" __global const btGpuFace* faces,\n"
|
|
||||||
" __global const int* indices,\n"
|
|
||||||
" __global const btGpuChildShape* gpuChildShapes,\n"
|
|
||||||
" __global btAabbCL* aabbs,\n"
|
|
||||||
" __global float4* concaveSeparatingNormalsOut,\n"
|
|
||||||
" __global int* concaveHasSeparatingNormals,\n"
|
|
||||||
" __global int4* clippingFacesOut,\n"
|
|
||||||
" __global float4* worldVertsA1GPU,\n"
|
|
||||||
" __global float4* worldNormalsAGPU,\n"
|
|
||||||
" __global float4* worldVertsB1GPU,\n"
|
|
||||||
" __global float* dmins,\n"
|
|
||||||
" int vertexFaceCapacity,\n"
|
|
||||||
" int numConcavePairs\n"
|
|
||||||
" )\n"
|
|
||||||
"{\n"
|
|
||||||
" \n"
|
|
||||||
" int i = get_global_id(0);\n"
|
|
||||||
" if (i>=numConcavePairs)\n"
|
|
||||||
" return;\n"
|
|
||||||
" \n"
|
|
||||||
" if (!concaveHasSeparatingNormals[i])\n"
|
|
||||||
" return;\n"
|
|
||||||
" \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"
|
|
||||||
" \n"
|
|
||||||
" int numFacesA = convexShapes[shapeIndexA].m_numFaces;\n"
|
|
||||||
" int numActualConcaveConvexTests = 0;\n"
|
|
||||||
" \n"
|
|
||||||
" int f = concavePairs[i].z;\n"
|
|
||||||
" \n"
|
|
||||||
" 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"
|
|
||||||
" triAabb.m_min = make_float4(1e30f,1e30f,1e30f,0.f);\n"
|
|
||||||
" triAabb.m_max = make_float4(-1e30f,-1e30f,-1e30f,0.f);\n"
|
|
||||||
" \n"
|
|
||||||
" float4 verticesA[3];\n"
|
|
||||||
" for (int i=0;i<3;i++)\n"
|
|
||||||
" {\n"
|
|
||||||
" int index = indices[face.m_indexOffset+i];\n"
|
|
||||||
" float4 vert = vertices[convexShapes[shapeIndexA].m_vertexOffset+index];\n"
|
|
||||||
" verticesA[i] = vert;\n"
|
|
||||||
" localCenter += vert;\n"
|
|
||||||
" \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"
|
|
||||||
" overlap = (triAabb.m_min.y > aabbs[bodyIndexB].m_max.y || triAabb.m_max.y < aabbs[bodyIndexB].m_min.y) ? false : overlap;\n"
|
|
||||||
" \n"
|
|
||||||
" if (overlap)\n"
|
|
||||||
" {\n"
|
|
||||||
" float dmin = dmins[i];\n"
|
|
||||||
" int hasSeparatingAxis=5;\n"
|
|
||||||
" float4 sepAxis=make_float4(1,2,3,4);\n"
|
|
||||||
" sepAxis = concaveSeparatingNormalsOut[pairIdx];\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"
|
|
||||||
" float4 uniqueEdgesA[3];\n"
|
|
||||||
" \n"
|
|
||||||
" 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"
|
|
||||||
" \n"
|
|
||||||
" btGpuFace facesA[TRIANGLE_NUM_CONVEX_FACES];\n"
|
|
||||||
" 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"
|
|
||||||
" indicesA[0] = 0;\n"
|
|
||||||
" indicesA[1] = 1;\n"
|
|
||||||
" indicesA[2] = 2;\n"
|
|
||||||
" curUsedIndices+=3;\n"
|
|
||||||
" float c = face.m_plane.w;\n"
|
|
||||||
" facesA[fidx].m_plane.x = normal.x;\n"
|
|
||||||
" facesA[fidx].m_plane.y = normal.y;\n"
|
|
||||||
" facesA[fidx].m_plane.z = normal.z;\n"
|
|
||||||
" facesA[fidx].m_plane.w = c;\n"
|
|
||||||
" facesA[fidx].m_numIndices=3;\n"
|
|
||||||
" }\n"
|
|
||||||
" fidx++;\n"
|
|
||||||
" //back size of triangle\n"
|
|
||||||
" {\n"
|
|
||||||
" facesA[fidx].m_indexOffset=curUsedIndices;\n"
|
|
||||||
" indicesA[3]=2;\n"
|
|
||||||
" indicesA[4]=1;\n"
|
|
||||||
" indicesA[5]=0;\n"
|
|
||||||
" curUsedIndices+=3;\n"
|
|
||||||
" float c = dot(normal,verticesA[0]);\n"
|
|
||||||
" float c1 = -face.m_plane.w;\n"
|
|
||||||
" facesA[fidx].m_plane.x = -normal.x;\n"
|
|
||||||
" facesA[fidx].m_plane.y = -normal.y;\n"
|
|
||||||
" facesA[fidx].m_plane.z = -normal.z;\n"
|
|
||||||
" facesA[fidx].m_plane.w = c;\n"
|
|
||||||
" facesA[fidx].m_numIndices=3;\n"
|
|
||||||
" }\n"
|
|
||||||
" fidx++;\n"
|
|
||||||
" \n"
|
|
||||||
" bool addEdgePlanes = true;\n"
|
|
||||||
" if (addEdgePlanes)\n"
|
|
||||||
" {\n"
|
|
||||||
" int numVertices=3;\n"
|
|
||||||
" int prevVertex = numVertices-1;\n"
|
|
||||||
" for (int i=0;i<numVertices;i++)\n"
|
|
||||||
" {\n"
|
|
||||||
" float4 v0 = verticesA[i];\n"
|
|
||||||
" float4 v1 = verticesA[prevVertex];\n"
|
|
||||||
" \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"
|
|
||||||
" indicesA[curUsedIndices++]=prevVertex;\n"
|
|
||||||
" \n"
|
|
||||||
" facesA[fidx].m_plane.x = edgeNormal.x;\n"
|
|
||||||
" facesA[fidx].m_plane.y = edgeNormal.y;\n"
|
|
||||||
" facesA[fidx].m_plane.z = edgeNormal.z;\n"
|
|
||||||
" facesA[fidx].m_plane.w = c;\n"
|
|
||||||
" fidx++;\n"
|
|
||||||
" prevVertex = i;\n"
|
|
||||||
" }\n"
|
|
||||||
" }\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"
|
|
||||||
" int childShapeIndexB = compoundChild;//collidables[collidableIndexB].m_shapeIndex+compoundChild;\n"
|
|
||||||
" int childColIndexB = gpuChildShapes[childShapeIndexB].m_shapeIndex;\n"
|
|
||||||
" float4 childPosB = gpuChildShapes[childShapeIndexB].m_childPosition;\n"
|
|
||||||
" float4 childOrnB = gpuChildShapes[childShapeIndexB].m_childOrientation;\n"
|
|
||||||
" float4 newPosB = transform(&childPosB,&posB,&ornB);\n"
|
|
||||||
" float4 newOrnB = qtMul(ornB,childOrnB);\n"
|
|
||||||
" posB = newPosB;\n"
|
|
||||||
" ornB = newOrnB;\n"
|
|
||||||
" 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"
|
|
||||||
" {\n"
|
|
||||||
" bool sepEE = findSeparatingAxisEdgeEdgeLocalA( &convexPolyhedronA, &convexShapes[shapeIndexB],\n"
|
|
||||||
" posA,ornA,\n"
|
|
||||||
" posB,ornB,\n"
|
|
||||||
" DeltaC2,\n"
|
|
||||||
" verticesA,uniqueEdgesA,facesA,indicesA,\n"
|
|
||||||
" vertices,uniqueEdges,faces,indices,\n"
|
|
||||||
" &sepAxis,&dmin);\n"
|
|
||||||
" \n"
|
|
||||||
" if (!sepEE)\n"
|
|
||||||
" {\n"
|
|
||||||
" hasSeparatingAxis = 0;\n"
|
|
||||||
" } else\n"
|
|
||||||
" {\n"
|
|
||||||
" hasSeparatingAxis = 1;\n"
|
|
||||||
" }\n"
|
|
||||||
" }\n"
|
|
||||||
" \n"
|
|
||||||
" \n"
|
|
||||||
" if (hasSeparatingAxis)\n"
|
|
||||||
" {\n"
|
|
||||||
" sepAxis.w = dmin;\n"
|
|
||||||
" dmins[i] = dmin;\n"
|
|
||||||
" concaveSeparatingNormalsOut[pairIdx]=sepAxis;\n"
|
|
||||||
" concaveHasSeparatingNormals[i]=1;\n"
|
|
||||||
" \n"
|
|
||||||
" float minDist = -1e30f;\n"
|
|
||||||
" float maxDist = 0.02f;\n"
|
|
||||||
" findClippingFaces(sepAxis,\n"
|
|
||||||
" &convexPolyhedronA,\n"
|
|
||||||
" &convexShapes[shapeIndexB],\n"
|
|
||||||
" posA,ornA,\n"
|
|
||||||
" posB,ornB,\n"
|
|
||||||
" worldVertsA1GPU,\n"
|
|
||||||
" worldNormalsAGPU,\n"
|
|
||||||
" worldVertsB1GPU,\n"
|
|
||||||
" vertexFaceCapacity,\n"
|
|
||||||
" minDist, maxDist,\n"
|
|
||||||
" verticesA,\n"
|
|
||||||
" facesA,\n"
|
|
||||||
" indicesA,\n"
|
|
||||||
" vertices,\n"
|
|
||||||
" faces,\n"
|
|
||||||
" indices,\n"
|
|
||||||
" clippingFacesOut, pairIdx);\n"
|
|
||||||
" \n"
|
|
||||||
" \n"
|
|
||||||
" } else\n"
|
|
||||||
" { \n"
|
|
||||||
" //mark this pair as in-active\n"
|
|
||||||
" concavePairs[pairIdx].w = -1;\n"
|
|
||||||
" }\n"
|
|
||||||
" }\n"
|
|
||||||
" else\n"
|
|
||||||
" { \n"
|
|
||||||
" //mark this pair as in-active\n"
|
|
||||||
" concavePairs[pairIdx].w = -1;\n"
|
|
||||||
" }\n"
|
|
||||||
"}\n"
|
|
||||||
;
|
;
|
||||||
|
|||||||
Reference in New Issue
Block a user