Ingen beskrivning
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VertexCubeSlicing.hlsl 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef VERTEX_CUBE_SLICING
  2. # define VERTEX_CUBE_SLICING
  3. // Box - plane slicing from 'A Vertex Program for Efficient Box-Plane Intersection'
  4. // Optimized with 'A COMPARISON OF GPU BOX-PLANE INTERSECTION ALGORITHMS FOR DIRECT VOLUME RENDERING'
  5. static const int sequence[16] = {
  6. 0, 1, 2, 3, 4, 5, 6, 7,
  7. 1, 2, 3, 0, 7, 4, 5, 6,
  8. };
  9. static const int v1[24] = {
  10. 0, 1, 4, -1,
  11. 1, 0, 1, 4,
  12. 0, 2, 5, -1,
  13. 2, 0, 2, 5,
  14. 0, 3, 6, -1,
  15. 3, 0, 3, 6
  16. };
  17. static const int v2[24] = {
  18. 1, 4, 7, -1,
  19. 5, 1, 4, 7,
  20. 2, 5, 7, -1,
  21. 6, 2, 5, 7,
  22. 3, 6, 7, -1,
  23. 4, 3, 6, 7
  24. };
  25. #ifdef GET_CUBE_VERTEX_POSITION
  26. float3 ComputeCubeSliceVertexPositionRWS(float3 cameraViewDirection, float planeDistance, int vertexId)
  27. {
  28. float3 position = 0;
  29. for (int i = 0; i < 4; ++i)
  30. {
  31. int vidx1 = sequence[int(v1[vertexId * 4 + i])];
  32. int vidx2 = sequence[int(v2[vertexId * 4 + i])];
  33. float3 vecV1 = GET_CUBE_VERTEX_POSITION(vidx1);
  34. float3 vecV2 = GET_CUBE_VERTEX_POSITION(vidx2);
  35. float3 intersection = 0;
  36. if (RayPlaneSegmentIntersect(vecV1, vecV2 - vecV1, cameraViewDirection, planeDistance, intersection))
  37. {
  38. position = intersection;
  39. break;
  40. }
  41. }
  42. return position;
  43. }
  44. #endif // GET_CUBE_VERTEX_POSITION
  45. #endif // VERTEX_CUBE_SLICING