pairsKernel.cl 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. __kernel void moveObjectsKernel(__global float4* posOrnColors, int numObjects)
  2. {
  3. int iGID = get_global_id(0);
  4. if (iGID>=numObjects)
  5. return;
  6. __global float4* positions = &posOrnColors[0];
  7. if (iGID<0.5*numObjects)
  8. {
  9. positions[iGID].y +=0.01f;
  10. }
  11. __global float4* colors = &posOrnColors[numObjects*2];
  12. colors[iGID] = (float4)(0,0,1,1);
  13. }
  14. __kernel void colorPairsKernel2(__global float4* posOrnColors, int numObjects, __global const int4* pairs, int indexOffset, int numPairs)
  15. {
  16. int iPairId = get_global_id(0);
  17. if (iPairId>=numPairs)
  18. return;
  19. __global float4* colors = &posOrnColors[numObjects*2];
  20. int iObjectA = pairs[iPairId].x-indexOffset;
  21. int iObjectB = pairs[iPairId].y-indexOffset;
  22. colors[iObjectA] = (float4)(1,0,0,1);
  23. colors[iObjectB] = (float4)(1,0,0,1);
  24. }
  25. __kernel void
  26. sineWaveKernel( __global float4* posOrnColors, __global float* pBodyTimes,float timeStepPos, float mAmplitude,const int numNodes)
  27. {
  28. int nodeID = get_global_id(0);
  29. if( nodeID < numNodes )
  30. {
  31. pBodyTimes[nodeID] += timeStepPos;
  32. float4 position = posOrnColors[nodeID];
  33. position.x = native_cos(pBodyTimes[nodeID]*2.17f)*mAmplitude + native_sin(pBodyTimes[nodeID])*mAmplitude*0.5f;
  34. position.y = native_cos(pBodyTimes[nodeID]*1.38f)*mAmplitude + native_sin(pBodyTimes[nodeID]*mAmplitude);
  35. position.z = native_cos(pBodyTimes[nodeID]*2.17f)*mAmplitude + native_sin(pBodyTimes[nodeID]*0.777f)*mAmplitude;
  36. posOrnColors[nodeID] = position;
  37. __global float4* colors = &posOrnColors[numNodes*2];
  38. colors[nodeID] = (float4)(0,0,1,1);
  39. }
  40. }
  41. typedef struct
  42. {
  43. float fx;
  44. float fy;
  45. float fz;
  46. int uw;
  47. } b3AABBCL;
  48. __kernel void updateAabbSimple( __global float4* posOrnColors, const int numNodes, __global b3AABBCL* pAABB)
  49. {
  50. int nodeId = get_global_id(0);
  51. if( nodeId < numNodes )
  52. {
  53. b3AABBCL orgAabbMin = pAABB[nodeId*2];
  54. b3AABBCL orgAabbMax = pAABB[nodeId*2+1];
  55. int orgNodeId = orgAabbMin.uw;
  56. int orgBroadphaseIndex = orgAabbMax.uw;
  57. float4 position = posOrnColors[nodeId];
  58. float4 argAabbMinVec = (float4)(orgAabbMin.fx,orgAabbMin.fy,orgAabbMin.fz,0.f);
  59. float4 argAabbMaxVec = (float4)(orgAabbMax.fx,orgAabbMax.fy,orgAabbMax.fz,0.f);
  60. float4 halfExtents = 0.5f*(argAabbMaxVec-argAabbMinVec);
  61. pAABB[nodeId*2].fx = position.x-halfExtents.x;
  62. pAABB[nodeId*2].fy = position.y-halfExtents.y;
  63. pAABB[nodeId*2].fz = position.z-halfExtents.z;
  64. pAABB[nodeId*2].uw = orgNodeId;
  65. pAABB[nodeId*2+1].fx = position.x+halfExtents.x;
  66. pAABB[nodeId*2+1].fy = position.y+halfExtents.y;
  67. pAABB[nodeId*2+1].fz = position.z+halfExtents.z;
  68. pAABB[nodeId*2+1].uw = orgBroadphaseIndex;
  69. }
  70. }