diff --git a/demo/gpudemo/GpuDemo.h b/demo/gpudemo/GpuDemo.h index dcbd72040..fda035a6b 100644 --- a/demo/gpudemo/GpuDemo.h +++ b/demo/gpudemo/GpuDemo.h @@ -38,9 +38,9 @@ public: :useOpenCL(true), preferredOpenCLPlatformIndex(-1), preferredOpenCLDeviceIndex(-1), - arraySizeX(10), - arraySizeY(10), - arraySizeZ(10), + arraySizeX(1), + arraySizeY(5), + arraySizeZ(1), m_useConcaveMesh(false), gapX(14.3), gapY(14.0), diff --git a/demo/gpudemo/main_opengl3core.cpp b/demo/gpudemo/main_opengl3core.cpp index 2c28d370b..e2d131e55 100644 --- a/demo/gpudemo/main_opengl3core.cpp +++ b/demo/gpudemo/main_opengl3core.cpp @@ -29,6 +29,7 @@ #include "rigidbody/ConcaveScene.h" #include "rigidbody/GpuConvexScene.h" #include "rigidbody/GpuCompoundScene.h" +#include "rigidbody/GpuSphereScene.h" //#include "BroadphaseBenchmark.h" @@ -64,7 +65,7 @@ btAlignedObjectArray demoNames; int selectedDemo = 0; GpuDemo::CreateFunc* allDemos[]= { - + GpuSphereScene::MyCreateFunc, GpuConvexScene::MyCreateFunc, ConcaveScene::MyCreateFunc, @@ -82,7 +83,7 @@ GpuDemo::CreateFunc* allDemos[]= //ParticleDemo::MyCreateFunc, - //SpheresDemo::CreateFunc, + //GpuCompoundDemo::CreateFunc, //EmptyDemo::CreateFunc, }; diff --git a/demo/gpudemo/rigidbody/GpuSphereScene.cpp b/demo/gpudemo/rigidbody/GpuSphereScene.cpp new file mode 100644 index 000000000..9d1edcc35 --- /dev/null +++ b/demo/gpudemo/rigidbody/GpuSphereScene.cpp @@ -0,0 +1,152 @@ +#include "GpuSphereScene.h" +#include "GpuRigidBodyDemo.h" +#include "BulletCommon/btQuickprof.h" +#include "OpenGLWindow/ShapeData.h" + +#include "OpenGLWindow/GLInstancingRenderer.h" +#include "BulletCommon/btQuaternion.h" +#include "OpenGLWindow/btgWindowInterface.h" +#include "gpu_broadphase/host/btGpuSapBroadphase.h" +#include "../GpuDemoInternalData.h" +#include "basic_initialize/btOpenCLUtils.h" +#include "OpenGLWindow/OpenGLInclude.h" +#include "OpenGLWindow/GLInstanceRendererInternalData.h" +#include "parallel_primitives/host/btLauncherCL.h" +#include "gpu_rigidbody/host/btGpuRigidBodyPipeline.h" +#include "gpu_rigidbody/host/btGpuNarrowPhase.h" +#include "gpu_rigidbody/host/btConfig.h" +#include "GpuRigidBodyDemoInternalData.h" +#include "../gwenUserInterface.h" + + + + +void GpuSphereScene::setupScene(const ConstructionInfo& ci) +{ + int strideInBytes = 9*sizeof(float); + int numVertices = sizeof(cube_vertices)/strideInBytes; + int numIndices = sizeof(cube_indices)/sizeof(int); + //int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices); + + int group=1; + int mask=1; + int index=0; + + if (0) + { + int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices); + btVector4 scaling(400,0.01,400,1); + //int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling); + btVector3 normal(0,1,0); + float constant=0.01; + + int colIndex = m_data->m_np->registerPlaneShape(normal,constant);//>registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling); + btVector4 position(0,0,0,0); + btQuaternion orn(0,0,0,1); + + btVector4 color(0,0,1,1); + + int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling); + int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(0.f,position,orn,colIndex,index); + + index++; + } + + + + { + + + + int prevGraphicsShapeIndex = -1; + float radius = 1; + if (radius>=100) + { + int numVertices = sizeof(detailed_sphere_vertices)/strideInBytes; + int numIndices = sizeof(detailed_sphere_indices)/sizeof(int); + prevGraphicsShapeIndex = ci.m_instancingRenderer->registerShape(&detailed_sphere_vertices[0],numVertices,detailed_sphere_indices,numIndices); + } else + { + bool usePointSprites = false; + if (usePointSprites) + { + int numVertices = sizeof(point_sphere_vertices)/strideInBytes; + int numIndices = sizeof(point_sphere_indices)/sizeof(int); + prevGraphicsShapeIndex = ci.m_instancingRenderer->registerShape(&point_sphere_vertices[0],numVertices,point_sphere_indices,numIndices,BT_GL_POINTS); + } else + { + if (radius>=10) + { + int numVertices = sizeof(medium_sphere_vertices)/strideInBytes; + int numIndices = sizeof(medium_sphere_indices)/sizeof(int); + prevGraphicsShapeIndex = ci.m_instancingRenderer->registerShape(&medium_sphere_vertices[0],numVertices,medium_sphere_indices,numIndices); + } else + { + int numVertices = sizeof(low_sphere_vertices)/strideInBytes; + int numIndices = sizeof(low_sphere_indices)/sizeof(int); + prevGraphicsShapeIndex = ci.m_instancingRenderer->registerShape(&low_sphere_vertices[0],numVertices,low_sphere_indices,numIndices); + } + } + } + + + + + btVector4 colors[4] = + { + btVector4(1,0,0,1), + btVector4(0,1,0,1), + btVector4(0,1,1,1), + btVector4(1,1,0,1), + }; + + + + + + + + + + int curColor = 0; + float scaling[4] = {1,1,1,1}; + //int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling); + int colIndex = m_data->m_np->registerSphereShape(radius);//>registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling); + for (int i=0;iregisterGraphicsInstance(prevGraphicsShapeIndex,position,orn,color,scaling); + int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass,position,orn,colIndex,index); + + index++; + } + } + } + } + float camPos[4]={ci.arraySizeX,ci.arraySizeY/2,ci.arraySizeZ,0}; + //float camPos[4]={1,12.5,1.5,0}; + m_instancingRenderer->setCameraTargetPosition(camPos); + m_instancingRenderer->setCameraDistance(20); + + + char msg[1024]; + int numInstances = index; + sprintf(msg,"Num objects = %d",numInstances); + ci.m_gui->setStatusBarMessage(msg,true); +} \ No newline at end of file diff --git a/demo/gpudemo/rigidbody/GpuSphereScene.h b/demo/gpudemo/rigidbody/GpuSphereScene.h new file mode 100644 index 000000000..f4f5b3545 --- /dev/null +++ b/demo/gpudemo/rigidbody/GpuSphereScene.h @@ -0,0 +1,27 @@ +#ifndef GPU_SPHERE_SCENE_H +#define GPU_SPHERE_SCENE_H + +#include "GpuRigidBodyDemo.h" + +class GpuSphereScene : public GpuRigidBodyDemo +{ +public: + + GpuSphereScene(){} + virtual ~GpuSphereScene(){} + virtual const char* getName() + { + return "GRBSphere"; + } + + static GpuDemo* MyCreateFunc() + { + GpuDemo* demo = new GpuSphereScene; + return demo; + } + + virtual void setupScene(const ConstructionInfo& ci); + +}; + +#endif //GPU_SPHERE_SCENE_H diff --git a/opencl/gpu_rigidbody/host/btGpuBatchingPgsSolver.cpp b/opencl/gpu_rigidbody/host/btGpuBatchingPgsSolver.cpp index bbb271008..e877dd235 100644 --- a/opencl/gpu_rigidbody/host/btGpuBatchingPgsSolver.cpp +++ b/opencl/gpu_rigidbody/host/btGpuBatchingPgsSolver.cpp @@ -37,8 +37,8 @@ enum }; -bool gpuBatchContacts = true; -bool gpuSolveConstraint = true; +bool gpuBatchContacts = true;//true; +bool gpuSolveConstraint = false;//true;//true; struct btGpuBatchingPgsSolverInternalData diff --git a/opencl/gpu_rigidbody/host/btGpuNarrowPhase.cpp b/opencl/gpu_rigidbody/host/btGpuNarrowPhase.cpp index e0304cc44..406d26365 100644 --- a/opencl/gpu_rigidbody/host/btGpuNarrowPhase.cpp +++ b/opencl/gpu_rigidbody/host/btGpuNarrowPhase.cpp @@ -196,6 +196,85 @@ int btGpuNarrowPhase::allocateCollidable() + + +int btGpuNarrowPhase::registerSphereShape(float radius) +{ + int collidableIndex = allocateCollidable(); + + btCollidable& col = getCollidableCpu(collidableIndex); + col.m_shapeType = SHAPE_SPHERE; + col.m_shapeIndex = 0; + col.m_radius = radius; + + if (col.m_shapeIndex>=0) + { + btSapAabb aabb; + btVector3 myAabbMin(-radius,-radius,-radius); + btVector3 myAabbMax(radius,radius,radius); + + aabb.m_min[0] = myAabbMin[0];//s_convexHeightField->m_aabb.m_min.x; + aabb.m_min[1] = myAabbMin[1];//s_convexHeightField->m_aabb.m_min.y; + aabb.m_min[2] = myAabbMin[2];//s_convexHeightField->m_aabb.m_min.z; + aabb.m_minIndices[3] = 0; + + aabb.m_max[0] = myAabbMax[0];//s_convexHeightField->m_aabb.m_max.x; + aabb.m_max[1] = myAabbMax[1];//s_convexHeightField->m_aabb.m_max.y; + aabb.m_max[2] = myAabbMax[2];//s_convexHeightField->m_aabb.m_max.z; + aabb.m_signedMaxIndices[3] = 0; + + m_data->m_localShapeAABBCPU->push_back(aabb); + m_data->m_localShapeAABBGPU->push_back(aabb); + clFinish(m_queue); + } + + return collidableIndex; +} + + +int btGpuNarrowPhase::registerFace(const btVector3& faceNormal, float faceConstant) +{ + int faceOffset = m_data->m_convexFaces.size(); + btGpuFace& face = m_data->m_convexFaces.expand(); + face.m_plane[0] = faceNormal.getX(); + face.m_plane[1] = faceNormal.getY(); + face.m_plane[2] = faceNormal.getZ(); + face.m_plane[3] = faceConstant; + m_data->m_convexFacesGPU->copyFromHost(m_data->m_convexFaces); + return faceOffset; +} + +int btGpuNarrowPhase::registerPlaneShape(const btVector3& planeNormal, float planeConstant) +{ + int collidableIndex = allocateCollidable(); + + btCollidable& col = getCollidableCpu(collidableIndex); + col.m_shapeType = SHAPE_PLANE; + col.m_shapeIndex = registerFace(planeNormal,planeConstant); + col.m_radius = planeConstant; + + if (col.m_shapeIndex>=0) + { + btSapAabb aabb; + aabb.m_min[0] = -1e30f; + aabb.m_min[1] = -1e30f; + aabb.m_min[2] = -1e30f; + aabb.m_minIndices[3] = 0; + + aabb.m_max[0] = 1e30f; + aabb.m_max[1] = 1e30f; + aabb.m_max[2] = 1e30f; + aabb.m_signedMaxIndices[3] = 0; + + m_data->m_localShapeAABBCPU->push_back(aabb); + m_data->m_localShapeAABBGPU->push_back(aabb); + clFinish(m_queue); + } + + return collidableIndex; +} + + int btGpuNarrowPhase::registerConvexHullShape(btConvexUtility* convexPtr,btCollidable& col) { m_data->m_convexData->resize(m_data->m_numAcceleratedShapes+1); diff --git a/opencl/gpu_rigidbody/host/btGpuNarrowPhase.h b/opencl/gpu_rigidbody/host/btGpuNarrowPhase.h index 50d030c57..d8e0d55df 100644 --- a/opencl/gpu_rigidbody/host/btGpuNarrowPhase.h +++ b/opencl/gpu_rigidbody/host/btGpuNarrowPhase.h @@ -31,7 +31,9 @@ public: virtual ~btGpuNarrowPhase(void); - + int registerSphereShape(float radius); + int registerPlaneShape(const btVector3& planeNormal, float planeConstant); + int registerCompoundShape(btAlignedObjectArray* childShapes); int registerFace(const btVector3& faceNormal, float faceConstant);