rtcore_ray.isph 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // ======================================================================== //
  2. // Copyright 2009-2017 Intel Corporation //
  3. // //
  4. // Licensed under the Apache License, Version 2.0 (the "License"); //
  5. // you may not use this file except in compliance with the License. //
  6. // You may obtain a copy of the License at //
  7. // //
  8. // http://www.apache.org/licenses/LICENSE-2.0 //
  9. // //
  10. // Unless required by applicable law or agreed to in writing, software //
  11. // distributed under the License is distributed on an "AS IS" BASIS, //
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
  13. // See the License for the specific language governing permissions and //
  14. // limitations under the License. //
  15. // ======================================================================== //
  16. #ifndef __RTCORE_RAY_ISPH__
  17. #define __RTCORE_RAY_ISPH__
  18. #include "rtcore.isph"
  19. /*! \ingroup embree_kernel_api_ispc */
  20. /*! \{ */
  21. /*! Ray structure for uniform (single) rays. */
  22. #ifndef __RTCRay1__
  23. #define __RTCRay1__
  24. struct RTCRay1
  25. {
  26. /* ray data */
  27. float org[3]; //!< Ray origin
  28. float align0; //!< unused member to force alignment of following members
  29. float dir[3]; //!< Ray direction
  30. float align1; //!< unused member to force alignment of following members
  31. float tnear; //!< Start of ray segment
  32. float tfar; //!< End of ray segment (set to hit distance)
  33. float time; //!< Time of this ray for motion blur
  34. unsigned int mask; //!< Used to mask out objects during traversal
  35. /* hit data */
  36. float Ng[3]; //!< Unnormalized geometry normal
  37. float align2;
  38. float u; //!< Barycentric u coordinate of hit
  39. float v; //!< Barycentric v coordinate of hit
  40. unsigned int geomID; //!< geometry ID
  41. unsigned int primID; //!< primitive ID
  42. unsigned int instID; //!< instance ID
  43. varying unsigned int align[0]; //!< aligns ray on stack to at least 16 bytes
  44. };
  45. #endif
  46. /*! Ray structure for packets of 4 rays. */
  47. #ifndef __RTCRay__
  48. #define __RTCRay__
  49. struct RTCRay
  50. {
  51. /* ray data */
  52. float orgx; //!< x coordinate of ray origin
  53. float orgy; //!< y coordinate of ray origin
  54. float orgz; //!< z coordinate of ray origin
  55. float dirx; //!< x coordinate of ray direction
  56. float diry; //!< y coordinate of ray direction
  57. float dirz; //!< z coordinate of ray direction
  58. float tnear; //!< Start of ray segment
  59. float tfar; //!< End of ray segment
  60. float time; //!< Time of this ray for motion blur
  61. unsigned int mask; //!< Used to mask out objects during traversal
  62. /* hit data */
  63. float Ngx; //!< x coordinate of geometry normal
  64. float Ngy; //!< y coordinate of geometry normal
  65. float Ngz; //!< z coordinate of geometry normal
  66. float u; //!< Barycentric u coordinate of hit
  67. float v; //!< Barycentric v coordinate of hit
  68. unsigned int geomID; //!< geometry ID
  69. unsigned int primID; //!< primitive ID
  70. unsigned int instID; //!< instance ID
  71. };
  72. #endif
  73. /* Helper functions to access ray packets of runtime size N */
  74. #ifndef __RTCRayN__
  75. #define __RTCRayN__
  76. struct RTCRayN {};
  77. inline varying float& RTCRayN_org_x(RTCRayN* uniform ptr, uniform size_t N, uniform size_t i) { uniform size_t N1 = (uniform size_t)(N == 1); return *((varying float* uniform) &((uniform float*)ptr)[0*N+0*N1+i]); } //!< x coordinate of ray origin
  78. inline varying float& RTCRayN_org_y(RTCRayN* uniform ptr, uniform size_t N, uniform size_t i) { uniform size_t N1 = (uniform size_t)(N == 1); return *((varying float* uniform) &((uniform float*)ptr)[1*N+0*N1+i]); } //!< y coordinate of ray origin
  79. inline varying float& RTCRayN_org_z(RTCRayN* uniform ptr, uniform size_t N, uniform size_t i) { uniform size_t N1 = (uniform size_t)(N == 1); return *((varying float* uniform) &((uniform float*)ptr)[2*N+0*N1+i]); }; //!< z coordinate of ray origin
  80. inline varying float& RTCRayN_dir_x(RTCRayN* uniform ptr, uniform size_t N, uniform size_t i) { uniform size_t N1 = (uniform size_t)(N == 1); return *((varying float* uniform) &((uniform float*)ptr)[3*N+1*N1+i]); }; //!< x coordinate of ray direction
  81. inline varying float& RTCRayN_dir_y(RTCRayN* uniform ptr, uniform size_t N, uniform size_t i) { uniform size_t N1 = (uniform size_t)(N == 1); return *((varying float* uniform) &((uniform float*)ptr)[4*N+1*N1+i]); }; //!< y coordinate of ray direction
  82. inline varying float& RTCRayN_dir_z(RTCRayN* uniform ptr, uniform size_t N, uniform size_t i) { uniform size_t N1 = (uniform size_t)(N == 1); return *((varying float* uniform) &((uniform float*)ptr)[5*N+1*N1+i]); }; //!< z coordinate of ray direction
  83. inline varying float& RTCRayN_tnear(RTCRayN* uniform ptr, uniform size_t N, uniform size_t i) { uniform size_t N1 = (uniform size_t)(N == 1); return *((varying float* uniform) &((uniform float*)ptr)[6*N+2*N1+i]); }; //!< Start of ray segment
  84. inline varying float& RTCRayN_tfar (RTCRayN* uniform ptr, uniform size_t N, uniform size_t i) { uniform size_t N1 = (uniform size_t)(N == 1); return *((varying float* uniform) &((uniform float*)ptr)[7*N+2*N1+i]); }; //!< End of ray segment (set to hit distance)
  85. inline varying float& RTCRayN_time(RTCRayN* uniform ptr, uniform size_t N, uniform size_t i) { uniform size_t N1 = (uniform size_t)(N == 1); return *((varying float* uniform) &((uniform float*)ptr)[8*N+2*N1+i]); }; //!< Time of this ray for motion blur
  86. inline varying unsigned int& RTCRayN_mask(RTCRayN* uniform ptr, uniform size_t N, uniform size_t i) { uniform size_t N1 = (uniform size_t)(N == 1); return *((varying unsigned int* uniform) &((uniform unsigned int*)ptr)[9*N+2*N1+i]); }; //!< Used to mask out objects during traversal
  87. inline varying float& RTCRayN_Ng_x(RTCRayN* uniform ptr, uniform size_t N, uniform size_t i) { uniform size_t N1 = (uniform size_t)(N == 1); return *((varying float* uniform) &((uniform float*)ptr)[10*N+2*N1+i]); }; //!< x coordinate of geometry normal
  88. inline varying float& RTCRayN_Ng_y(RTCRayN* uniform ptr, uniform size_t N, uniform size_t i) { uniform size_t N1 = (uniform size_t)(N == 1); return *((varying float* uniform) &((uniform float*)ptr)[11*N+2*N1+i]); }; //!< y coordinate of geometry normal
  89. inline varying float& RTCRayN_Ng_z(RTCRayN* uniform ptr, uniform size_t N, uniform size_t i) { uniform size_t N1 = (uniform size_t)(N == 1); return *((varying float* uniform) &((uniform float*)ptr)[12*N+2*N1+i]); }; //!< z coordinate of geometry normal
  90. inline varying float& RTCRayN_u (RTCRayN* uniform ptr, uniform size_t N, uniform size_t i) { uniform size_t N1 = (uniform size_t)(N == 1); return *((varying float* uniform) &((uniform float*)ptr)[13*N+3*N1+i]); }; //!< Barycentric u coordinate of hit
  91. inline varying float& RTCRayN_v (RTCRayN* uniform ptr, uniform size_t N, uniform size_t i) { uniform size_t N1 = (uniform size_t)(N == 1); return *((varying float* uniform) &((uniform float*)ptr)[14*N+3*N1+i]); }; //!< Barycentric v coordinate of hit
  92. inline varying unsigned int& RTCRayN_geomID(RTCRayN* uniform ptr, uniform size_t N, uniform size_t i) { uniform size_t N1 = (uniform size_t)(N == 1); return *((varying unsigned int* uniform) &((uniform unsigned int* )ptr)[15*N+3*N1+i]); }; //!< geometry ID
  93. inline varying unsigned int& RTCRayN_primID(RTCRayN* uniform ptr, uniform size_t N, uniform size_t i) { uniform size_t N1 = (uniform size_t)(N == 1); return *((varying unsigned int* uniform) &((uniform unsigned int* )ptr)[16*N+3*N1+i]); }; //!< primitive ID
  94. inline varying unsigned int& RTCRayN_instID(RTCRayN* uniform ptr, uniform size_t N, uniform size_t i) { uniform size_t N1 = (uniform size_t)(N == 1); return *((varying unsigned int* uniform) &((uniform unsigned int* )ptr)[17*N+3*N1+i]); }; //!< instance ID
  95. #endif
  96. /*! \brief Ray structure template for packets of N rays in pointer SOA layout. */
  97. #ifndef __RTCRayNp__
  98. #define __RTCRayNp__
  99. struct RTCRayNp
  100. {
  101. /* ray data */
  102. uniform float* uniform orgx; //!< x coordinate of ray origin
  103. uniform float* uniform orgy; //!< y coordinate of ray origin
  104. uniform float* uniform orgz; //!< z coordinate of ray origin
  105. uniform float* uniform dirx; //!< x coordinate of ray direction
  106. uniform float* uniform diry; //!< y coordinate of ray direction
  107. uniform float* uniform dirz; //!< z coordinate of ray direction
  108. uniform float* uniform tnear; //!< Start of ray segment (optional)
  109. uniform float* uniform tfar; //!< End of ray segment (set to hit distance)
  110. uniform float* uniform time; //!< Time of this ray for motion blur (optional)
  111. uniform unsigned int* uniform mask; //!< Used to mask out objects during traversal (optional)
  112. /* hit data */
  113. uniform float* uniform Ngx; //!< x coordinate of geometry normal (optional)
  114. uniform float* uniform Ngy; //!< y coordinate of geometry normal (optional)
  115. uniform float* uniform Ngz; //!< z coordinate of geometry normal (optional)
  116. uniform float* uniform u; //!< Barycentric u coordinate of hit
  117. uniform float* uniform v; //!< Barycentric v coordinate of hit
  118. uniform unsigned int* uniform geomID; //!< geometry ID
  119. uniform unsigned int* uniform primID; //!< primitive ID
  120. uniform unsigned int* uniform instID; //!< instance ID (optional)
  121. };
  122. #endif
  123. /* Helper functions to access hit packets of size N */
  124. #ifndef __RTCHitN__
  125. #define __RTCHitN__
  126. struct RTCHitN {};
  127. inline varying float& RTCHitN_Ng_x(const RTCHitN* uniform ptr, uniform size_t N, uniform size_t i) { return *((varying float* uniform) &((float* uniform)ptr)[0*N+i]); }; //!< x coordinate of geometry normal
  128. inline varying float& RTCHitN_Ng_y(const RTCHitN* uniform ptr, uniform size_t N, uniform size_t i) { return *((varying float* uniform) &((float* uniform)ptr)[1*N+i]); }; //!< y coordinate of geometry normal
  129. inline varying float& RTCHitN_Ng_z(const RTCHitN* uniform ptr, uniform size_t N, uniform size_t i) { return *((varying float* uniform) &((float* uniform)ptr)[2*N+i]); }; //!< z coordinate of geometry normal
  130. inline varying unsigned int& RTCHitN_instID(const RTCHitN* uniform ptr, uniform size_t N, uniform size_t i) { return *((varying unsigned int* uniform) &((unsigned int* uniform )ptr)[3*N+i]); }; //!< instance ID
  131. inline varying unsigned int& RTCHitN_geomID(const RTCHitN* uniform ptr, uniform size_t N, uniform size_t i) { return *((varying unsigned int* uniform) &((unsigned int* uniform )ptr)[4*N+i]); }; //!< geometry ID
  132. inline varying unsigned int& RTCHitN_primID(const RTCHitN* uniform ptr, uniform size_t N, uniform size_t i) { return *((varying unsigned int* uniform) &((unsigned int* uniform )ptr)[5*N+i]); }; //!< primitive ID
  133. inline varying float& RTCHitN_u (const RTCHitN* uniform ptr, uniform size_t N, uniform size_t i) { return *((varying float* uniform) &((float* uniform)ptr)[6*N+i]); }; //!< Barycentric u coordinate of hit
  134. inline varying float& RTCHitN_v (const RTCHitN* uniform ptr, uniform size_t N, uniform size_t i) { return *((varying float* uniform) &((float* uniform)ptr)[7*N+i]); }; //!< Barycentric v coordinate of hit
  135. inline varying float& RTCHitN_t (const RTCHitN* uniform ptr, uniform size_t N, uniform size_t i) { return *((varying float* uniform) &((float* uniform)ptr)[8*N+i]); }; //!< hit distance
  136. #endif
  137. /*! @} */
  138. #endif