Several changes to sync Bullet trunk with PlayStation 3 spubullet version
Still needs some cross-platform fixes
This commit is contained in:
@@ -10,14 +10,14 @@ ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL
|
||||
IF(INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||
INCLUDE_DIRECTORIES( $ENV{==NVSDKCOMPUTE_ROOT=}/OpenCL/common/inc )
|
||||
IF (CMAKE_CL_64)
|
||||
SET(CMAK_NVSDKCOMPUTE_LIBPATH )
|
||||
SET(CMAK_NVSDKCOMPUTE_LIBPATH $ENV{==NVSDKCOMPUTE_ROOT=}/OpenCL/common/lib/x64 )
|
||||
ELSE(CMAKE_CL_64)
|
||||
SET(CMAK_NVSDKCOMPUTE_LIBPATH $ENV{==NVSDKCOMPUTE_ROOT=}/OpenCL/common/lib/x64 )
|
||||
SET(CMAK_NVSDKCOMPUTE_LIBPATH $ENV{==NVSDKCOMPUTE_ROOT=}/OpenCL/common/lib/Win32 )
|
||||
ENDIF(CMAKE_CL_64)
|
||||
ELSE()
|
||||
INCLUDE_DIRECTORIES( $ENV{NVSDKCOMPUTE_ROOT}/OpenCL/common/inc )
|
||||
IF (CMAKE_CL_64)
|
||||
SET(CMAK_NVSDKCOMPUTE_LIBPATH )
|
||||
SET(CMAK_NVSDKCOMPUTE_LIBPATH $ENV{NVSDKCOMPUTE_ROOT}/OpenCL/common/lib/x64 )
|
||||
ELSE(CMAKE_CL_64)
|
||||
SET(CMAK_NVSDKCOMPUTE_LIBPATH $ENV{NVSDKCOMPUTE_ROOT}/OpenCL/common/lib/Win32 )
|
||||
ENDIF(CMAKE_CL_64)
|
||||
@@ -35,7 +35,6 @@ IF (USE_GLUT)
|
||||
OpenGLSupport
|
||||
BulletDynamics
|
||||
BulletCollision
|
||||
BulletMultiThreaded
|
||||
LinearMath
|
||||
${GLUT_glut_LIBRARY}
|
||||
${OPENGL_gl_LIBRARY}
|
||||
@@ -74,8 +73,6 @@ IF (CMAKE_CL_64)
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/glut64.dll ${CMAKE_CURRENT_BINARY_DIR} )
|
||||
ADD_CUSTOM_COMMAND( TARGET AppParticlesOCL_Nv POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLEW64.DLL ${CMAKE_CURRENT_BINARY_DIR})
|
||||
ADD_CUSTOM_COMMAND( TARGET AppParticlesOCL_Nv POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Demos/ParticlesOpenCL/ParticlesOCL.cl ${CMAKE_CURRENT_BINARY_DIR})
|
||||
ENDIF()
|
||||
ELSE(CMAKE_CL_64)
|
||||
IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||
@@ -83,10 +80,13 @@ ELSE(CMAKE_CL_64)
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLUT32.DLL ${CMAKE_CURRENT_BINARY_DIR})
|
||||
ADD_CUSTOM_COMMAND( TARGET AppParticlesOCL_Nv POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLEW32.DLL ${CMAKE_CURRENT_BINARY_DIR})
|
||||
ENDIF()
|
||||
ENDIF(CMAKE_CL_64)
|
||||
|
||||
IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||
ADD_CUSTOM_COMMAND( TARGET AppParticlesOCL_Nv POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Demos/ParticlesOpenCL/ParticlesOCL.cl ${CMAKE_CURRENT_BINARY_DIR})
|
||||
ENDIF()
|
||||
ENDIF(CMAKE_CL_64)
|
||||
ENDIF(WIN32)
|
||||
|
||||
IF (UNIX)
|
||||
|
||||
@@ -22,8 +22,9 @@ subject to the following restrictions:
|
||||
//#define START_POS_Z btScalar(0.4f)
|
||||
#define ARRAY_SIZE_X 32
|
||||
#define ARRAY_SIZE_Y 32
|
||||
//#define ARRAY_SIZE_Y 5
|
||||
//#define ARRAY_SIZE_Y 16
|
||||
#define ARRAY_SIZE_Z 16
|
||||
//16
|
||||
//#define ARRAY_SIZE_Z 1
|
||||
//#define DIST btScalar(2.f)
|
||||
#define DIST (DEF_PARTICLE_RADIUS * 2.f)
|
||||
@@ -65,7 +66,7 @@ subject to the following restrictions:
|
||||
|
||||
|
||||
|
||||
btScalar gTimeStep = btScalar(1./60.);
|
||||
btScalar gTimeStep = 0.5f;//btScalar(1./60.);
|
||||
|
||||
#define SCALING btScalar(1.f)
|
||||
|
||||
@@ -254,6 +255,7 @@ void ParticlesDemo::initPhysics()
|
||||
|
||||
{
|
||||
// btCollisionShape* colShape = new btSphereShape(btScalar(1.0f));
|
||||
/*
|
||||
btCollisionShape* colShape = new btSphereShape(DEF_PARTICLE_RADIUS);
|
||||
m_collisionShapes.push_back(colShape);
|
||||
btTransform startTransform;
|
||||
@@ -269,37 +271,53 @@ void ParticlesDemo::initPhysics()
|
||||
rbInfo.m_startWorldTransform = startTransform;
|
||||
btRigidBody* body = new btRigidBody(rbInfo);
|
||||
m_pWorld->addRigidBody(body);
|
||||
*/
|
||||
|
||||
init_scene_directly();
|
||||
}
|
||||
clientResetScene();
|
||||
m_pWorld->initDeviceData();
|
||||
}
|
||||
|
||||
static float frand(void) { return 2.0f * (float)rand()/(float)RAND_MAX - 1.0f; }
|
||||
inline float frand(void){
|
||||
return (float)rand() / (float)RAND_MAX;
|
||||
}
|
||||
|
||||
void ParticlesDemo::init_scene_directly()
|
||||
{
|
||||
float start_x = START_POS_X - ARRAY_SIZE_X * DIST * btScalar(0.5f);
|
||||
float start_y = START_POS_Y - ARRAY_SIZE_Y * DIST * btScalar(0.5f);
|
||||
float start_z = START_POS_Z - ARRAY_SIZE_Z * DIST * btScalar(0.5f);
|
||||
int total = ARRAY_SIZE_X * ARRAY_SIZE_Y * ARRAY_SIZE_Z;
|
||||
m_pWorld->m_hPos.resize(total);
|
||||
m_pWorld->m_hVel.resize(total);
|
||||
total = 0;
|
||||
for (int k=0;k<ARRAY_SIZE_Y;k++)
|
||||
{
|
||||
for (int i=0;i<ARRAY_SIZE_X;i++)
|
||||
{
|
||||
for(int j = 0;j<ARRAY_SIZE_Z;j++)
|
||||
{
|
||||
m_pWorld->m_hVel[total] = btVector3(0., 0., 0.);
|
||||
btVector3 jitter = 0.01f * 0.03f * btVector3(frand(), frand(), frand());
|
||||
m_pWorld->m_hPos[total] = btVector3(DIST*i + start_x, DIST*k + start_y, DIST*j + start_z) + jitter;
|
||||
total++;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_pWorld->m_numParticles = total;
|
||||
|
||||
|
||||
srand(1969);
|
||||
float start_x = -1+DEF_PARTICLE_RADIUS;//START_POS_X - ARRAY_SIZE_X * DIST * btScalar(0.5f);
|
||||
float start_y = -1+DEF_PARTICLE_RADIUS;//START_POS_Y - ARRAY_SIZE_Y * DIST * btScalar(0.5f);
|
||||
float start_z = -1+DEF_PARTICLE_RADIUS;//START_POS_Z - ARRAY_SIZE_Z * DIST * btScalar(0.5f);
|
||||
int numParticles = ARRAY_SIZE_X * ARRAY_SIZE_Y * ARRAY_SIZE_Z;
|
||||
m_pWorld->m_hPos.resize(numParticles);
|
||||
m_pWorld->m_hVel.resize(numParticles);
|
||||
|
||||
btScalar spacing = 2 * DEF_PARTICLE_RADIUS;
|
||||
|
||||
for(int z=0; z<ARRAY_SIZE_Z; z++)
|
||||
{
|
||||
for(int y=0; y<ARRAY_SIZE_Y; y++)
|
||||
{
|
||||
for(int x=0; x<ARRAY_SIZE_X; x++)
|
||||
{
|
||||
int i = (z * ARRAY_SIZE_Y * ARRAY_SIZE_X) + (y * ARRAY_SIZE_X) + x;
|
||||
if (i < numParticles)
|
||||
{
|
||||
btVector3 jitter = 0.01f * 0.03f * btVector3(frand(), frand(), frand());
|
||||
m_pWorld->m_hVel[i]= btVector3(0,0,0);
|
||||
m_pWorld->m_hPos[i].setX((spacing * x) + DEF_PARTICLE_RADIUS -WORLD_SIZE+jitter.getX());
|
||||
m_pWorld->m_hPos[i].setY((spacing * y) + DEF_PARTICLE_RADIUS -WORLD_SIZE+jitter.getY());
|
||||
m_pWorld->m_hPos[i].setZ((spacing * z) + DEF_PARTICLE_RADIUS -WORLD_SIZE+jitter.getZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_pWorld->m_numParticles = numParticles;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -314,6 +332,7 @@ void ParticlesDemo::clientResetScene()
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
m_pWorld->grabSimulationData();
|
||||
}
|
||||
}
|
||||
@@ -392,7 +411,7 @@ void ParticlesDemo::renderme()
|
||||
{
|
||||
|
||||
glColor3f(1.0, 1.0, 1.0);
|
||||
glutWireCube(2.0);
|
||||
glutWireCube(2*WORLD_SIZE);
|
||||
|
||||
glPointSize(5.0f);
|
||||
glEnable(GL_POINT_SPRITE_ARB);
|
||||
|
||||
@@ -81,7 +81,7 @@ __kernel void kFindCellStart( int numParticles,
|
||||
__global float4* pSortedVel GUID_ARG)
|
||||
{
|
||||
int index = get_global_id(0);
|
||||
__local int sharedHash[513];
|
||||
__local int sharedHash[1025];//maximum workgroup size 1024
|
||||
int2 sortedData;
|
||||
|
||||
if(index < numParticles)
|
||||
@@ -142,6 +142,8 @@ __kernel void kIntegrateMotion( int numParticles,
|
||||
// collide with world boundaries
|
||||
float4 worldMin = *((__global float4*)(pParams + 1));
|
||||
float4 worldMax = *((__global float4*)(pParams + 2));
|
||||
|
||||
|
||||
if(pos.x < (worldMin.x + particleRad))
|
||||
{
|
||||
pos.x = worldMin.x + particleRad;
|
||||
@@ -216,7 +218,6 @@ float4 collideTwoParticles(
|
||||
}
|
||||
|
||||
|
||||
|
||||
__kernel void kCollideParticles(int numParticles,
|
||||
__global float4* pVel, //output: new velocity
|
||||
__global const float4* pSortedPos, //input: reordered positions
|
||||
@@ -264,8 +265,10 @@ __kernel void kCollideParticles(int numParticles,
|
||||
continue;
|
||||
}
|
||||
//Iterate over particles in this cell
|
||||
int endI = startI + 8;
|
||||
if(endI >= numParticles) endI = numParticles - 1;
|
||||
int endI = startI + 32;
|
||||
if(endI >= numParticles)
|
||||
endI = numParticles ;
|
||||
|
||||
for(int j = startI; j < endI; j++)
|
||||
{
|
||||
uint hashC = pPosHash[j].x;
|
||||
|
||||
@@ -74,6 +74,7 @@ int btParticlesDynamicsWorld::stepSimulation( btScalar timeStep, int maxSubSteps
|
||||
}
|
||||
{
|
||||
BT_PROFILE("CollideParticles");
|
||||
// printf("\ncollide particles\n\n");
|
||||
runCollideParticlesKernel();
|
||||
}
|
||||
gStepNum++;
|
||||
@@ -212,8 +213,8 @@ void btParticlesDynamicsWorld::adjustGrid()
|
||||
m_worldMin -= wsize;
|
||||
m_worldMax += wsize;
|
||||
*/
|
||||
m_worldMin.setValue(-1.f, -1.f, -1.f);
|
||||
m_worldMax.setValue( 1.f, 1.f, 1.f);
|
||||
m_worldMin.setValue(-WORLD_SIZE, -WORLD_SIZE, -WORLD_SIZE);
|
||||
m_worldMax.setValue( WORLD_SIZE, WORLD_SIZE, WORLD_SIZE);
|
||||
wsize = m_worldMax - m_worldMin;
|
||||
|
||||
m_cellSize[0] = m_cellSize[1] = m_cellSize[2] = m_particleRad * btScalar(2.f);
|
||||
@@ -246,7 +247,12 @@ void btParticlesDynamicsWorld::adjustGrid()
|
||||
void btParticlesDynamicsWorld::grabSimulationData()
|
||||
{
|
||||
// const btVector3& gravity = getGravity();
|
||||
btVector3 gravity(0., -0.06, 0.);
|
||||
//btVector3 gravity(0., -0.06, 0.);
|
||||
//btVector3 gravity(0., -0.0003f, 0.);
|
||||
btVector3 gravity(0,-0.0003,0);
|
||||
|
||||
|
||||
|
||||
m_simParams.m_gravity[0] = gravity[0];
|
||||
m_simParams.m_gravity[1] = gravity[1];
|
||||
m_simParams.m_gravity[2] = gravity[2];
|
||||
@@ -258,7 +264,7 @@ void btParticlesDynamicsWorld::grabSimulationData()
|
||||
// m_simParams.m_spring = 0.5f;
|
||||
// m_simParams.m_shear = 0.1f;
|
||||
// m_simParams.m_attraction = 0.0f;
|
||||
m_simParams.m_collisionDamping = 0.02f;
|
||||
m_simParams.m_collisionDamping = 0.025f;//0.02f;
|
||||
m_simParams.m_spring = 0.5f;
|
||||
m_simParams.m_shear = 0.1f;
|
||||
m_simParams.m_attraction = 0.0f;
|
||||
@@ -427,6 +433,7 @@ void btParticlesDynamicsWorld::initCLKernels(int argc, char** argv)
|
||||
ciErrNum |= clSetKernelArg(m_kernels[PARTICLES_KERNEL_CLEAR_CELL_START].m_kernel, 1, sizeof(cl_mem), (void*) &m_dCellStart);
|
||||
|
||||
initKernel(PARTICLES_KERNEL_FIND_CELL_START, "kFindCellStart");
|
||||
// ciErrNum |= clSetKernelArg(m_kernels[PARTICLES_KERNEL_FIND_CELL_START].m_kernel, 0, sizeof(int), (void*) &m_numParticles);
|
||||
ciErrNum |= clSetKernelArg(m_kernels[PARTICLES_KERNEL_FIND_CELL_START].m_kernel, 1, sizeof(cl_mem), (void*) &m_dPosHash);
|
||||
ciErrNum |= clSetKernelArg(m_kernels[PARTICLES_KERNEL_FIND_CELL_START].m_kernel, 2, sizeof(cl_mem), (void*) &m_dCellStart);
|
||||
ciErrNum |= clSetKernelArg(m_kernels[PARTICLES_KERNEL_FIND_CELL_START].m_kernel, 3, sizeof(cl_mem), (void*) &m_dPos);
|
||||
@@ -560,15 +567,28 @@ static btVector3 cpu_collideTwoParticles(
|
||||
float relVelDotNorm = relVel.dot(norm);
|
||||
btVector3 tanVel = relVel - relVelDotNorm * norm;
|
||||
//Spring force (potential)
|
||||
float springFactor = -spring * (collideDist - dist);
|
||||
force = springFactor * norm + damping * relVel + shear * tanVel + attraction * relPos;
|
||||
//float springFactor = -spring * (collideDist - dist);
|
||||
float springFactor = -0.4 * (collideDist - dist);
|
||||
force = springFactor * norm + damping * relVel;// + shear * tanVel + attraction * relPos;
|
||||
}
|
||||
return force;
|
||||
}
|
||||
|
||||
struct btPair
|
||||
{
|
||||
union
|
||||
{
|
||||
int value;
|
||||
short v0[2];
|
||||
};
|
||||
};
|
||||
|
||||
void btParticlesDynamicsWorld::runCollideParticlesKernel()
|
||||
{
|
||||
btAlignedObjectArray<int> pairs;
|
||||
|
||||
float particleRad = m_simParams.m_particleRad;
|
||||
float collideDist2 = (particleRad + particleRad)*(particleRad + particleRad);
|
||||
cl_int ciErrNum;
|
||||
if(m_useCpuControls[SIMSTAGE_COLLIDE_PARTICLES]->m_active)
|
||||
{ // CPU version
|
||||
@@ -585,6 +605,7 @@ void btParticlesDynamicsWorld::runCollideParticlesKernel()
|
||||
ciErrNum = clEnqueueReadBuffer(m_cqCommandQue, m_dCellStart, CL_TRUE, 0, memSize, &(m_hCellStart[0]), 0, NULL, NULL);
|
||||
oclCHECKERROR(ciErrNum, CL_SUCCESS);
|
||||
}
|
||||
|
||||
for(int index = 0; index < m_numParticles; index++)
|
||||
{
|
||||
btVector3 posA = m_hSortedPos[index];
|
||||
@@ -618,7 +639,10 @@ void btParticlesDynamicsWorld::runCollideParticlesKernel()
|
||||
continue;
|
||||
}
|
||||
//Iterate over particles in this cell
|
||||
int endI = startI + 8;
|
||||
int endI = startI + 32;
|
||||
if(endI > m_numParticles)
|
||||
endI = m_numParticles;
|
||||
|
||||
for(int j = startI; j < endI; j++)
|
||||
{
|
||||
unsigned int hashC = m_hPosHash[j].x;
|
||||
@@ -630,6 +654,14 @@ void btParticlesDynamicsWorld::runCollideParticlesKernel()
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
btPair pair;
|
||||
pair.v0[0] = index;
|
||||
pair.v0[1] = j;
|
||||
pairs.push_back(pair.value);
|
||||
|
||||
// printf("index=%d, j=%d\n",index,j);
|
||||
// printf("(index=%d, j=%d) ",index,j);
|
||||
btVector3 posB = m_hSortedPos[j];
|
||||
btVector3 velB = m_hSortedVel[j];
|
||||
//Collide two spheres
|
||||
@@ -642,6 +674,56 @@ void btParticlesDynamicsWorld::runCollideParticlesKernel()
|
||||
//Write new velocity back to original unsorted location
|
||||
m_hVel[unsortedIndex] = velA + force;
|
||||
}
|
||||
|
||||
//#define BRUTE_FORCE_CHECK 1
|
||||
#ifdef BRUTE_FORCE_CHECK
|
||||
for(int index = 0; index < m_numParticles; index++)
|
||||
{
|
||||
btVector3 posA = m_hSortedPos[index];
|
||||
btVector3 velA = m_hSortedVel[index];
|
||||
btVector3 force = btVector3(0, 0, 0);
|
||||
int unsortedIndex = m_hPosHash[index].y;
|
||||
|
||||
float collisionDamping = m_simParams.m_collisionDamping;
|
||||
float spring = m_simParams.m_spring;
|
||||
float shear = m_simParams.m_shear;
|
||||
float attraction = m_simParams.m_attraction;
|
||||
for(int j = 0 ; j < m_numParticles; j++)
|
||||
{
|
||||
if (index!=j)
|
||||
{
|
||||
btVector3 posB = m_hSortedPos[j];
|
||||
btVector3 velB = m_hSortedVel[j];
|
||||
|
||||
|
||||
btVector3 relPos = posB - posA; relPos[3] = 0.f;
|
||||
float dist2 = (relPos[0] * relPos[0] + relPos[1] * relPos[1] + relPos[2] * relPos[2]);
|
||||
|
||||
|
||||
|
||||
if(dist2 < collideDist2)
|
||||
{
|
||||
//Collide two spheres
|
||||
// force += cpu_collideTwoParticles( posA, posB, velA, velB, particleRad, particleRad,
|
||||
// spring, collisionDamping, shear, attraction);
|
||||
|
||||
btPair pair;
|
||||
pair.v0[0] = index;
|
||||
pair.v0[1] = j;
|
||||
if (pairs.findLinearSearch(pair.value)==pairs.size())
|
||||
{
|
||||
printf("not found index=%d, j=%d\n",index,j);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
//Write new velocity back to original unsorted location
|
||||
//m_hVel[unsortedIndex] = velA + force;
|
||||
}
|
||||
#endif //BRUTE_FORCE_CHECK
|
||||
|
||||
memSize = sizeof(btVector3) * m_numParticles;
|
||||
ciErrNum = clEnqueueWriteBuffer(m_cqCommandQue, m_dVel, CL_TRUE, 0, memSize, &(m_hVel[0]), 0, NULL, NULL);
|
||||
oclCHECKERROR(ciErrNum, CL_SUCCESS);
|
||||
@@ -675,7 +757,11 @@ void btParticlesDynamicsWorld::runIntegrateMotionKernel()
|
||||
pos[3] = 1.0f;
|
||||
vel[3] = 0.0f;
|
||||
// apply gravity
|
||||
btVector3 gravity = *((btVector3*)(m_simParams.m_gravity));
|
||||
btVector3 gravity;
|
||||
gravity[0] = m_simParams.m_gravity[0];
|
||||
gravity[1] = m_simParams.m_gravity[1];
|
||||
gravity[2] = m_simParams.m_gravity[2];
|
||||
|
||||
float particleRad = m_simParams.m_particleRad;
|
||||
float globalDamping = m_simParams.m_globalDamping;
|
||||
float boundaryDamping = m_simParams.m_boundaryDamping;
|
||||
@@ -684,8 +770,16 @@ void btParticlesDynamicsWorld::runIntegrateMotionKernel()
|
||||
// integrate position
|
||||
pos += vel * m_timeStep;
|
||||
// collide with world boundaries
|
||||
btVector3 worldMin = *((btVector3*)(m_simParams.m_worldMin));
|
||||
btVector3 worldMax = *((btVector3*)(m_simParams.m_worldMax));
|
||||
btVector3 worldMin;
|
||||
worldMin[0] = m_simParams.m_worldMin[0];
|
||||
worldMin[1] = m_simParams.m_worldMin[1];
|
||||
worldMin[2] = m_simParams.m_worldMin[2];
|
||||
|
||||
btVector3 worldMax;
|
||||
worldMax[0] = m_simParams.m_worldMax[0];
|
||||
worldMax[1] = m_simParams.m_worldMax[1];
|
||||
worldMax[2] = m_simParams.m_worldMax[2];
|
||||
|
||||
for(int j = 0; j < 3; j++)
|
||||
{
|
||||
if(pos[j] < (worldMin[j] + particleRad))
|
||||
@@ -800,7 +894,7 @@ void btParticlesDynamicsWorld::runSortHashKernel()
|
||||
}
|
||||
};
|
||||
btHashPosKey* pHash = (btHashPosKey*)(&m_hPosHash[0]);
|
||||
pHash->quickSort(pHash, 0, m_numParticles - 1);
|
||||
pHash->quickSort(pHash, 0, m_numParticles );
|
||||
// pHash->bitonicSort(pHash, 0, m_hashSize, true);
|
||||
// write back to GPU
|
||||
ciErrNum = clEnqueueWriteBuffer(m_cqCommandQue, m_dPosHash, CL_TRUE, 0, memSize, &(m_hPosHash[0]), 0, NULL, NULL);
|
||||
@@ -899,8 +993,19 @@ void btParticlesDynamicsWorld::initKernel(int kernelId, char* pName)
|
||||
size_t wgSize;
|
||||
ciErrNum = clGetKernelWorkGroupInfo(kernel, m_cdDevice, CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), &wgSize, NULL);
|
||||
oclCHECKERROR(ciErrNum, CL_SUCCESS);
|
||||
// if (wgSize > 64)
|
||||
// wgSize = 64;
|
||||
|
||||
|
||||
|
||||
|
||||
// if (wgSize > 256)
|
||||
// wgSize = 256;
|
||||
|
||||
if (wgSize > 512)
|
||||
wgSize = 512;
|
||||
|
||||
// if (wgSize > 1024)
|
||||
// wgSize = 1024;
|
||||
|
||||
m_kernels[kernelId].m_Id = kernelId;
|
||||
m_kernels[kernelId].m_kernel = kernel;
|
||||
m_kernels[kernelId].m_name = pName;
|
||||
|
||||
@@ -45,6 +45,7 @@ subject to the following restrictions:
|
||||
#define PARTICLES_MAX_PARTICLES (65536)
|
||||
#define PARTICLES_MAX_NEIGHBORS (32)
|
||||
#define DEF_PARTICLE_RADIUS (0.023f)
|
||||
#define WORLD_SIZE 1.9f
|
||||
|
||||
enum
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#define STRINGIFY(A) #A
|
||||
|
||||
#ifdef USE_AMD_OPENCL
|
||||
// vertex shader
|
||||
const char *vertexShader = STRINGIFY(
|
||||
uniform float pointRadius; // point size in world space
|
||||
@@ -17,16 +18,40 @@ void main()
|
||||
//hack around latest AMD graphics cards having troubles with point sprite rendering
|
||||
//the problem is still unresolved on the 5870 card, and results in a black screen
|
||||
//see also http://forums.amd.com/devforum/messageview.cfm?catid=392&threadid=129431
|
||||
#ifdef USE_AMD_OPENCL
|
||||
gl_TexCoord = gl_MultiTexCoord0;
|
||||
#else
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
#endif
|
||||
gl_Position = gl_ModelViewProjectionMatrix * vec4(gl_Vertex.xyz, 1.0);
|
||||
|
||||
gl_Position = gl_ModelViewProjectionMatrix * vec4(gl_Vertex.xyz, 1.0);
|
||||
|
||||
gl_FrontColor = gl_Color;
|
||||
}
|
||||
);
|
||||
#else
|
||||
// vertex shader
|
||||
const char *vertexShader = STRINGIFY(
|
||||
uniform float pointRadius; // point size in world space
|
||||
uniform float pointScale; // scale to calculate size in pixels
|
||||
uniform float densityScale;
|
||||
uniform float densityOffset;
|
||||
varying vec3 posEye;
|
||||
void main()
|
||||
{
|
||||
// calculate window-space point size
|
||||
posEye = vec3(gl_ModelViewMatrix * vec4(gl_Vertex.xyz, 1.0));
|
||||
float dist = length(posEye);
|
||||
gl_PointSize = pointRadius * (pointScale / dist);
|
||||
// gl_PointSize = 4.0;
|
||||
//hack around latest AMD graphics cards having troubles with point sprite rendering
|
||||
//the problem is still unresolved on the 5870 card, and results in a black screen
|
||||
//see also http://forums.amd.com/devforum/messageview.cfm?catid=392&threadid=129431
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
|
||||
gl_Position = gl_ModelViewProjectionMatrix * vec4(gl_Vertex.xyz, 1.0);
|
||||
|
||||
gl_FrontColor = gl_Color;
|
||||
}
|
||||
);
|
||||
|
||||
#endif
|
||||
|
||||
// pixel shader for rendering points as shaded spheres
|
||||
const char *spherePixelShader = STRINGIFY(
|
||||
|
||||
Reference in New Issue
Block a user