fix ray-convex header file

This commit is contained in:
erwincoumans
2013-06-20 16:41:11 -07:00
parent d935eb2520
commit e39af46403
2 changed files with 119 additions and 123 deletions

View File

@@ -234,8 +234,8 @@ GpuRaytraceScene::GpuRaytraceScene()
m_raytraceData = new GpuRaytraceInternalData;
m_raytraceData->m_texId = new GLuint;
m_raytraceData->textureWidth = 256;//1024;//1024;
m_raytraceData->textureHeight = 256;//1024;
m_raytraceData->textureWidth = 512;//1024;//1024;
m_raytraceData->textureHeight = 512;//1024;
//create new texture
glGenTextures(1, m_raytraceData->m_texId);

View File

@@ -89,8 +89,6 @@ static const char* rayCastKernelCL= \
"__inline\n"
" Quaternion qtNormalize(Quaternion in);\n"
"\n"
"__inline\n"
"float4 qtRotate(Quaternion q, float4 vec);\n"
"\n"
"__inline\n"
" Quaternion qtInvert(Quaternion q);\n"
@@ -129,7 +127,8 @@ static const char* rayCastKernelCL= \
" Quaternion qInv = qtInvert( q );\n"
" float4 vcpy = vec;\n"
" vcpy.w = 0.f;\n"
" float4 out = qtMul(qtMul(q,vcpy),qInv);\n"
" float4 out = qtMul(q,vcpy);\n"
" out = qtMul(out,qInv);\n"
" return out;\n"
"}\n"
"\n"
@@ -145,11 +144,7 @@ static const char* rayCastKernelCL= \
" return qtRotate( qtInvert( q ), vec );\n"
"}\n"
"\n"
"__inline\n"
"float4 transform(const float4* p, const float4* translation, const Quaternion* orientation)\n"
"{\n"
" return qtRotate( *orientation, *p ) + (*translation);\n"
"}\n"
"\n"
"\n"
"void trInverse(float4 translationIn, Quaternion orientationIn,\n"
" float4* translationOut, Quaternion* orientationOut)\n"
@@ -158,13 +153,7 @@ static const char* rayCastKernelCL= \
" *translationOut = qtRotate(*orientationOut, -translationIn);\n"
"}\n"
"\n"
"void trMul(float4 translationA, Quaternion orientationA,\n"
" float4 translationB, Quaternion orientationB,\n"
" float4* translationOut, Quaternion* orientationOut)\n"
"{\n"
" *orientationOut = qtMul(orientationA,orientationB);\n"
" *translationOut = transform(&translationB,&translationA,&orientationA);\n"
"}\n"
"\n"
"\n"
"\n"
"\n"
@@ -175,7 +164,7 @@ static const char* rayCastKernelCL= \
" rayToLocal.w = 0.f;\n"
" bool result = true;\n"
"\n"
" float exitFraction = *hitFraction;\n"
" float exitFraction = hitFraction[0];\n"
" float enterFraction = -0.3f;\n"
" float4 curHitNormal = (float4)(0,0,0,0);\n"
" for (int i=0;i<numFaces && result;i++)\n"
@@ -213,12 +202,15 @@ static const char* rayCastKernelCL= \
" result = false;\n"
" }\n"
"\n"
" result = result && (enterFraction < 0.f);\n"
" if (enterFraction < 0.f)\n"
" {\n"
" result = false;\n"
" }\n"
"\n"
" if (result)\n"
" { \n"
" *hitFraction = enterFraction;\n"
" *hitNormal = curHitNormal;\n"
" hitFraction[0] = enterFraction;\n"
" hitNormal[0] = curHitNormal;\n"
" }\n"
" return result;\n"
"}\n"
@@ -240,7 +232,7 @@ static const char* rayCastKernelCL= \
"\n"
" float D = B * B - A*C;\n"
"\n"
" if (D > 0.0)\n"
" if (D > 0.0f)\n"
" {\n"
" float t = (-B - sqrt(D))/A;\n"
"\n"
@@ -274,8 +266,9 @@ static const char* rayCastKernelCL= \
"{\n"
"\n"
" int i = get_global_id(0);\n"
" if (i<numRays)\n"
" {\n"
" if (i>=numRays)\n"
" return;\n"
"\n"
" hitResults[i].m_hitFraction = 1.f;\n"
"\n"
" float4 rayFrom = rays[i].m_from;\n"
@@ -285,18 +278,43 @@ static const char* rayCastKernelCL= \
" float4 hitNormal;\n"
" int hitBodyIndex= -1;\n"
"\n"
" \n"
" \n"
" int cachedCollidableIndex = -1;\n"
" Collidable cachedCollidable;\n"
"\n"
" for (int b=0;b<numBodies;b++)\n"
" {\n"
"\n"
" float4 pos = bodies[b].m_pos;\n"
" float4 orn = bodies[b].m_quat;\n"
" \n"
" int cachedCollidableIndex = bodies[b].m_collidableIdx; \n"
" Collidable cachedCollidable = collidables[cachedCollidableIndex];\n"
" Body body = bodies[b];\n"
" float4 pos = body.m_pos;\n"
" float4 orn = body.m_quat;\n"
" if (cachedCollidableIndex != body.m_collidableIdx)\n"
" {\n"
" cachedCollidableIndex = body.m_collidableIdx;\n"
" cachedCollidable = collidables[cachedCollidableIndex];\n"
" }\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"
" float4 rayToLocal = (float4)(0,0,0,0);\n"
" invOrn = qtInvert(orn);\n"
" invPos = qtRotate(invOrn, -pos);\n"
" rayFromLocal = qtRotate( invOrn, rayFrom ) + invPos;\n"
" rayToLocal = qtRotate( invOrn, rayTo) + invPos;\n"
" rayFromLocal.w = 0.f;\n"
" rayToLocal.w = 0.f;\n"
" int numFaces = convexShapes[cachedCollidable.m_shapeIndex].m_numFaces;\n"
" int faceOffset = convexShapes[cachedCollidable.m_shapeIndex].m_faceOffset;\n"
" if (numFaces)\n"
" {\n"
" if (rayConvex(rayFromLocal, rayToLocal, numFaces, faceOffset,faces, &hitFraction, &hitNormal))\n"
" {\n"
" hitBodyIndex = b;\n"
" }\n"
" }\n"
" }\n"
" if (cachedCollidable.m_shapeType == SHAPE_SPHERE)\n"
" {\n"
" float radius = cachedCollidable.m_radius;\n"
@@ -308,28 +326,6 @@ static const char* rayCastKernelCL= \
" hitNormal = (float4) (hitPoint-bodies[b].m_pos);\n"
" }\n"
" }\n"
" \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"
" float4 rayToLocal = (float4)(0,0,0,0);\n"
" \n"
" trInverse(pos,orn, &invPos, &invOrn);\n"
" rayFromLocal = transform(&rayFrom, &invPos, &invOrn);\n"
" rayToLocal = transform(&rayTo, &invPos, &invOrn);\n"
" \n"
" int numFaces = convexShapes[cachedCollidable.m_shapeIndex].m_numFaces;\n"
" int faceOffset = convexShapes[cachedCollidable.m_shapeIndex].m_faceOffset;\n"
" \n"
" if (rayConvex(rayFromLocal, rayToLocal, numFaces, faceOffset,faces, &hitFraction, &hitNormal))\n"
" {\n"
" hitBodyIndex = b;\n"
" }\n"
" }\n"
" \n"
" }\n"
"\n"
" if (hitBodyIndex>=0)\n"
@@ -339,7 +335,7 @@ static const char* rayCastKernelCL= \
" hitResults[i].m_hitNormal = normalize(hitNormal);\n"
" hitResults[i].m_hitResult0 = hitBodyIndex;\n"
" }\n"
" }\n"
"\n"
"}\n"
"\n"
;