move shaders to .glsl files and stringify to .h file.

add crude screenshot facility (using F1 key), it can also be used for debugging
start with shadows using shadowmap, not working yet
add experimental 'ignore' body index in raycast, using b3HitInfo.m_m_hitResult2
This commit is contained in:
erwin coumans
2013-06-28 14:10:23 -07:00
parent bb723f9fd1
commit f2cc840c31
41 changed files with 2060 additions and 645 deletions

View File

@@ -194,6 +194,7 @@ cl_platform_id b3OpenCLUtils_getPlatform(int platformIndex0, cl_int* pErrNum)
void b3OpenCLUtils::getPlatformInfo(cl_platform_id platform, b3OpenCLPlatformInfo* platformInfo)
{
b3Assert(platform);
cl_int ciErrNum;
ciErrNum = clGetPlatformInfo( platform,CL_PLATFORM_VENDOR,B3_MAX_STRING_LENGTH,platformInfo->m_platformVendor,NULL);
oclCHECKERROR(ciErrNum,CL_SUCCESS);

View File

@@ -105,12 +105,19 @@ typedef struct
} b3OpenCLDeviceInfo;
typedef struct
struct b3OpenCLPlatformInfo
{
char m_platformVendor[B3_MAX_STRING_LENGTH];
char m_platformName[B3_MAX_STRING_LENGTH];
char m_platformVersion[B3_MAX_STRING_LENGTH];
} b3OpenCLPlatformInfo;
b3OpenCLPlatformInfo()
{
m_platformVendor[0]=0;
m_platformName[0]=0;
m_platformVersion[0]=0;
}
};
///C++ API for OpenCL utilities: convenience functions

View File

@@ -214,11 +214,16 @@ void b3GpuRaycast::castRays(const b3AlignedObjectArray<b3RayInfo>& rays, b3Align
B3_PROFILE("castRaysGPU");
b3OpenCLArray<b3RayInfo> gpuRays(m_data->m_context,m_data->m_q);
gpuRays.copyFromHost(rays);
b3OpenCLArray<b3RayHit> gpuHitResults(m_data->m_context,m_data->m_q);
gpuHitResults.resize(hitResults.size());
gpuHitResults.copyFromHost(hitResults);
{
B3_PROFILE("raycast copyFromHost");
gpuRays.copyFromHost(rays);
gpuHitResults.resize(hitResults.size());
gpuHitResults.copyFromHost(hitResults);
}
//run kernel
@@ -243,6 +248,9 @@ void b3GpuRaycast::castRays(const b3AlignedObjectArray<b3RayInfo>& rays, b3Align
}
//copy results
gpuHitResults.copyToHost(hitResults);
{
B3_PROFILE("raycast copyToHost");
gpuHitResults.copyToHost(hitResults);
}
}

View File

@@ -281,7 +281,8 @@ __kernel void rayCastKernel(
for (int b=0;b<numBodies;b++)
{
if (hitResults[i].m_hitResult2==b)
continue;
Body body = bodies[b];
float4 pos = body.m_pos;
float4 orn = body.m_quat;
@@ -310,6 +311,7 @@ __kernel void rayCastKernel(
if (rayConvex(rayFromLocal, rayToLocal, numFaces, faceOffset,faces, &hitFraction, &hitNormal))
{
hitBodyIndex = b;
}
}
}
@@ -320,7 +322,6 @@ __kernel void rayCastKernel(
if (sphere_intersect(pos, radius, rayFrom, rayTo, &hitFraction))
{
hitBodyIndex = b;
hitPoint = setInterpolate3(rayFrom, rayTo,hitFraction);
hitNormal = (float4) (hitPoint-bodies[b].m_pos);
}
}
@@ -328,6 +329,7 @@ __kernel void rayCastKernel(
if (hitBodyIndex>=0)
{
hitPoint = setInterpolate3(rayFrom, rayTo,hitFraction);
hitResults[i].m_hitFraction = hitFraction;
hitResults[i].m_hitPoint = hitPoint;
hitResults[i].m_hitNormal = normalize(hitNormal);

View File

@@ -283,7 +283,8 @@ static const char* rayCastKernelCL= \
"\n"
" for (int b=0;b<numBodies;b++)\n"
" {\n"
"\n"
" if (hitResults[i].m_hitResult2==b)\n"
" continue;\n"
" Body body = bodies[b];\n"
" float4 pos = body.m_pos;\n"
" float4 orn = body.m_quat;\n"
@@ -312,6 +313,7 @@ static const char* rayCastKernelCL= \
" if (rayConvex(rayFromLocal, rayToLocal, numFaces, faceOffset,faces, &hitFraction, &hitNormal))\n"
" {\n"
" hitBodyIndex = b;\n"
" \n"
" }\n"
" }\n"
" }\n"
@@ -322,7 +324,6 @@ static const char* rayCastKernelCL= \
" if (sphere_intersect(pos, radius, rayFrom, rayTo, &hitFraction))\n"
" {\n"
" hitBodyIndex = b;\n"
" hitPoint = setInterpolate3(rayFrom, rayTo,hitFraction);\n"
" hitNormal = (float4) (hitPoint-bodies[b].m_pos);\n"
" }\n"
" }\n"
@@ -330,6 +331,7 @@ static const char* rayCastKernelCL= \
"\n"
" if (hitBodyIndex>=0)\n"
" {\n"
" hitPoint = setInterpolate3(rayFrom, rayTo,hitFraction);\n"
" hitResults[i].m_hitFraction = hitFraction;\n"
" hitResults[i].m_hitPoint = hitPoint;\n"
" hitResults[i].m_hitNormal = normalize(hitNormal);\n"