rtcore_ray.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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_H__
  17. #define __RTCORE_RAY_H__
  18. #include "rtcore.h"
  19. /*! \ingroup embree_kernel_api */
  20. /*! \{ */
  21. /*! \brief Ray structure for an individual ray */
  22. #ifndef __RTCRay__
  23. #define __RTCRay__
  24. struct RTCORE_ALIGN(16) RTCRay
  25. {
  26. /* ray data */
  27. public:
  28. float org[3]; //!< Ray origin
  29. float align0;
  30. float dir[3]; //!< Ray direction
  31. float align1;
  32. float tnear; //!< Start of ray segment
  33. float tfar; //!< End of ray segment (set to hit distance)
  34. float time; //!< Time of this ray for motion blur
  35. unsigned mask; //!< Used to mask out objects during traversal
  36. /* hit data */
  37. public:
  38. float Ng[3]; //!< Unnormalized geometry normal
  39. float align2;
  40. float u; //!< Barycentric u coordinate of hit
  41. float v; //!< Barycentric v coordinate of hit
  42. unsigned geomID; //!< geometry ID
  43. unsigned primID; //!< primitive ID
  44. unsigned instID; //!< instance ID
  45. };
  46. #endif
  47. /*! Ray structure for packets of 4 rays. */
  48. #ifndef __RTCRay4__
  49. #define __RTCRay4__
  50. struct RTCORE_ALIGN(16) RTCRay4
  51. {
  52. /* ray data */
  53. public:
  54. float orgx[4]; //!< x coordinate of ray origin
  55. float orgy[4]; //!< y coordinate of ray origin
  56. float orgz[4]; //!< z coordinate of ray origin
  57. float dirx[4]; //!< x coordinate of ray direction
  58. float diry[4]; //!< y coordinate of ray direction
  59. float dirz[4]; //!< z coordinate of ray direction
  60. float tnear[4]; //!< Start of ray segment
  61. float tfar[4]; //!< End of ray segment (set to hit distance)
  62. float time[4]; //!< Time of this ray for motion blur
  63. unsigned mask[4]; //!< Used to mask out objects during traversal
  64. /* hit data */
  65. public:
  66. float Ngx[4]; //!< x coordinate of geometry normal
  67. float Ngy[4]; //!< y coordinate of geometry normal
  68. float Ngz[4]; //!< z coordinate of geometry normal
  69. float u[4]; //!< Barycentric u coordinate of hit
  70. float v[4]; //!< Barycentric v coordinate of hit
  71. unsigned geomID[4]; //!< geometry ID
  72. unsigned primID[4]; //!< primitive ID
  73. unsigned instID[4]; //!< instance ID
  74. };
  75. #endif
  76. /*! Ray structure for packets of 8 rays. */
  77. #ifndef __RTCRay8__
  78. #define __RTCRay8__
  79. struct RTCORE_ALIGN(32) RTCRay8
  80. {
  81. /* ray data */
  82. public:
  83. float orgx[8]; //!< x coordinate of ray origin
  84. float orgy[8]; //!< y coordinate of ray origin
  85. float orgz[8]; //!< z coordinate of ray origin
  86. float dirx[8]; //!< x coordinate of ray direction
  87. float diry[8]; //!< y coordinate of ray direction
  88. float dirz[8]; //!< z coordinate of ray direction
  89. float tnear[8]; //!< Start of ray segment
  90. float tfar[8]; //!< End of ray segment (set to hit distance)
  91. float time[8]; //!< Time of this ray for motion blur
  92. unsigned mask[8]; //!< Used to mask out objects during traversal
  93. /* hit data */
  94. public:
  95. float Ngx[8]; //!< x coordinate of geometry normal
  96. float Ngy[8]; //!< y coordinate of geometry normal
  97. float Ngz[8]; //!< z coordinate of geometry normal
  98. float u[8]; //!< Barycentric u coordinate of hit
  99. float v[8]; //!< Barycentric v coordinate of hit
  100. unsigned geomID[8]; //!< geometry ID
  101. unsigned primID[8]; //!< primitive ID
  102. unsigned instID[8]; //!< instance ID
  103. };
  104. #endif
  105. /*! \brief Ray structure for packets of 16 rays. */
  106. #ifndef __RTCRay16__
  107. #define __RTCRay16__
  108. struct RTCORE_ALIGN(64) RTCRay16
  109. {
  110. /* ray data */
  111. public:
  112. float orgx[16]; //!< x coordinate of ray origin
  113. float orgy[16]; //!< y coordinate of ray origin
  114. float orgz[16]; //!< z coordinate of ray origin
  115. float dirx[16]; //!< x coordinate of ray direction
  116. float diry[16]; //!< y coordinate of ray direction
  117. float dirz[16]; //!< z coordinate of ray direction
  118. float tnear[16]; //!< Start of ray segment
  119. float tfar[16]; //!< End of ray segment (set to hit distance)
  120. float time[16]; //!< Time of this ray for motion blur
  121. unsigned mask[16]; //!< Used to mask out objects during traversal
  122. /* hit data */
  123. public:
  124. float Ngx[16]; //!< x coordinate of geometry normal
  125. float Ngy[16]; //!< y coordinate of geometry normal
  126. float Ngz[16]; //!< z coordinate of geometry normal
  127. float u[16]; //!< Barycentric u coordinate of hit
  128. float v[16]; //!< Barycentric v coordinate of hit
  129. unsigned geomID[16]; //!< geometry ID
  130. unsigned primID[16]; //!< primitive ID
  131. unsigned instID[16]; //!< instance ID
  132. };
  133. #endif
  134. /* Helper functions to access ray packets of runtime size N */
  135. #ifndef __RTCRayN__
  136. #define __RTCRayN__
  137. struct RTCRayN {};
  138. RTCORE_FORCEINLINE float& RTCRayN_org_x(RTCRayN* ptr, size_t N, size_t i) { const size_t N1 = (size_t)(N == 1); return ((float*)ptr)[0*N+0*N1+i]; } //!< x coordinate of ray origin
  139. RTCORE_FORCEINLINE float& RTCRayN_org_y(RTCRayN* ptr, size_t N, size_t i) { const size_t N1 = (size_t)(N == 1); return ((float*)ptr)[1*N+0*N1+i]; } //!< y coordinate of ray origin
  140. RTCORE_FORCEINLINE float& RTCRayN_org_z(RTCRayN* ptr, size_t N, size_t i) { const size_t N1 = (size_t)(N == 1); return ((float*)ptr)[2*N+0*N1+i]; }; //!< z coordinate of ray origin
  141. RTCORE_FORCEINLINE float& RTCRayN_dir_x(RTCRayN* ptr, size_t N, size_t i) { const size_t N1 = (size_t)(N == 1); return ((float*)ptr)[3*N+1*N1+i]; }; //!< x coordinate of ray direction
  142. RTCORE_FORCEINLINE float& RTCRayN_dir_y(RTCRayN* ptr, size_t N, size_t i) { const size_t N1 = (size_t)(N == 1); return ((float*)ptr)[4*N+1*N1+i]; }; //!< y coordinate of ray direction
  143. RTCORE_FORCEINLINE float& RTCRayN_dir_z(RTCRayN* ptr, size_t N, size_t i) { const size_t N1 = (size_t)(N == 1); return ((float*)ptr)[5*N+1*N1+i]; }; //!< z coordinate of ray direction
  144. RTCORE_FORCEINLINE float& RTCRayN_tnear(RTCRayN* ptr, size_t N, size_t i) { const size_t N1 = (size_t)(N == 1); return ((float*)ptr)[6*N+2*N1+i]; }; //!< Start of ray segment
  145. RTCORE_FORCEINLINE float& RTCRayN_tfar (RTCRayN* ptr, size_t N, size_t i) { const size_t N1 = (size_t)(N == 1); return ((float*)ptr)[7*N+2*N1+i]; }; //!< End of ray segment (set to hit distance)
  146. RTCORE_FORCEINLINE float& RTCRayN_time(RTCRayN* ptr, size_t N, size_t i) { const size_t N1 = (size_t)(N == 1); return ((float*) ptr)[8*N+2*N1+i]; }; //!< Time of this ray for motion blur
  147. RTCORE_FORCEINLINE unsigned& RTCRayN_mask(RTCRayN* ptr, size_t N, size_t i) { const size_t N1 = (size_t)(N == 1); return ((unsigned*)ptr)[9*N+2*N1+i]; }; //!< Used to mask out objects during traversal
  148. RTCORE_FORCEINLINE float& RTCRayN_Ng_x(RTCRayN* ptr, size_t N, size_t i) { const size_t N1 = (size_t)(N == 1); return ((float*)ptr)[10*N+2*N1+i]; }; //!< x coordinate of geometry normal
  149. RTCORE_FORCEINLINE float& RTCRayN_Ng_y(RTCRayN* ptr, size_t N, size_t i) { const size_t N1 = (size_t)(N == 1); return ((float*)ptr)[11*N+2*N1+i]; }; //!< y coordinate of geometry normal
  150. RTCORE_FORCEINLINE float& RTCRayN_Ng_z(RTCRayN* ptr, size_t N, size_t i) { const size_t N1 = (size_t)(N == 1); return ((float*)ptr)[12*N+2*N1+i]; }; //!< z coordinate of geometry normal
  151. RTCORE_FORCEINLINE float& RTCRayN_u (RTCRayN* ptr, size_t N, size_t i) { const size_t N1 = (size_t)(N == 1); return ((float*)ptr)[13*N+3*N1+i]; }; //!< Barycentric u coordinate of hit
  152. RTCORE_FORCEINLINE float& RTCRayN_v (RTCRayN* ptr, size_t N, size_t i) { const size_t N1 = (size_t)(N == 1); return ((float*)ptr)[14*N+3*N1+i]; }; //!< Barycentric v coordinate of hit
  153. RTCORE_FORCEINLINE unsigned& RTCRayN_geomID(RTCRayN* ptr, size_t N, size_t i) { const size_t N1 = (size_t)(N == 1); return ((unsigned*)ptr)[15*N+3*N1+i]; }; //!< geometry ID
  154. RTCORE_FORCEINLINE unsigned& RTCRayN_primID(RTCRayN* ptr, size_t N, size_t i) { const size_t N1 = (size_t)(N == 1); return ((unsigned*)ptr)[16*N+3*N1+i]; }; //!< primitive ID
  155. RTCORE_FORCEINLINE unsigned& RTCRayN_instID(RTCRayN* ptr, size_t N, size_t i) { const size_t N1 = (size_t)(N == 1); return ((unsigned*)ptr)[17*N+3*N1+i]; }; //!< instance ID
  156. #endif
  157. /* Helper structure to create a ray packet of compile time size N */
  158. #ifndef __RTCRayNt__
  159. #define __RTCRayNt__
  160. template<int N>
  161. struct RTCRayNt : public RTCRayN
  162. {
  163. /* ray data */
  164. public:
  165. float orgx[N]; //!< x coordinate of ray origin
  166. float orgy[N]; //!< y coordinate of ray origin
  167. float orgz[N]; //!< z coordinate of ray origin
  168. float dirx[N]; //!< x coordinate of ray direction
  169. float diry[N]; //!< y coordinate of ray direction
  170. float dirz[N]; //!< z coordinate of ray direction
  171. float tnear[N]; //!< Start of ray segment
  172. float tfar[N]; //!< End of ray segment (set to hit distance)
  173. float time[N]; //!< Time of this ray for motion blur
  174. unsigned mask[N]; //!< Used to mask out objects during traversal
  175. /* hit data */
  176. public:
  177. float Ngx[N]; //!< x coordinate of geometry normal
  178. float Ngy[N]; //!< y coordinate of geometry normal
  179. float Ngz[N]; //!< z coordinate of geometry normal
  180. float u[N]; //!< Barycentric u coordinate of hit
  181. float v[N]; //!< Barycentric v coordinate of hit
  182. unsigned geomID[N]; //!< geometry ID
  183. unsigned primID[N]; //!< primitive ID
  184. unsigned instID[N]; //!< instance ID
  185. };
  186. #endif
  187. /*! \brief Ray structure template for packets of N rays in pointer SOA layout. */
  188. #ifndef __RTCRayNp__
  189. #define __RTCRayNp__
  190. struct RTCRayNp
  191. {
  192. /* ray data */
  193. public:
  194. float* orgx; //!< x coordinate of ray origin
  195. float* orgy; //!< y coordinate of ray origin
  196. float* orgz; //!< z coordinate of ray origin
  197. float* dirx; //!< x coordinate of ray direction
  198. float* diry; //!< y coordinate of ray direction
  199. float* dirz; //!< z coordinate of ray direction
  200. float* tnear; //!< Start of ray segment (optional)
  201. float* tfar; //!< End of ray segment (set to hit distance)
  202. float* time; //!< Time of this ray for motion blur (optional)
  203. unsigned* mask; //!< Used to mask out objects during traversal (optional)
  204. /* hit data */
  205. public:
  206. float* Ngx; //!< x coordinate of geometry normal (optional)
  207. float* Ngy; //!< y coordinate of geometry normal (optional)
  208. float* Ngz; //!< z coordinate of geometry normal (optional)
  209. float* u; //!< Barycentric u coordinate of hit
  210. float* v; //!< Barycentric v coordinate of hit
  211. unsigned* geomID; //!< geometry ID
  212. unsigned* primID; //!< primitive ID
  213. unsigned* instID; //!< instance ID (optional)
  214. };
  215. #endif
  216. /* Helper functions to access hit packets of size N */
  217. #ifndef __RTCHitN__
  218. #define __RTCHitN__
  219. struct RTCHitN {};
  220. RTCORE_FORCEINLINE float& RTCHitN_Ng_x(const RTCHitN* ptr, size_t N, size_t i) { return ((float*)ptr)[0*N+i]; }; //!< x coordinate of geometry normal
  221. RTCORE_FORCEINLINE float& RTCHitN_Ng_y(const RTCHitN* ptr, size_t N, size_t i) { return ((float*)ptr)[1*N+i]; }; //!< y coordinate of geometry normal
  222. RTCORE_FORCEINLINE float& RTCHitN_Ng_z(const RTCHitN* ptr, size_t N, size_t i) { return ((float*)ptr)[2*N+i]; }; //!< z coordinate of geometry normal
  223. RTCORE_FORCEINLINE unsigned& RTCHitN_instID(const RTCHitN* ptr, size_t N, size_t i) { return ((unsigned*)ptr)[3*N+i]; }; //!< instance ID
  224. RTCORE_FORCEINLINE unsigned& RTCHitN_geomID(const RTCHitN* ptr, size_t N, size_t i) { return ((unsigned*)ptr)[4*N+i]; }; //!< geometry ID
  225. RTCORE_FORCEINLINE unsigned& RTCHitN_primID(const RTCHitN* ptr, size_t N, size_t i) { return ((unsigned*)ptr)[5*N+i]; }; //!< primitive ID
  226. RTCORE_FORCEINLINE float& RTCHitN_u (const RTCHitN* ptr, size_t N, size_t i) { return ((float*)ptr)[6*N+i]; }; //!< Barycentric u coordinate of hit
  227. RTCORE_FORCEINLINE float& RTCHitN_v (const RTCHitN* ptr, size_t N, size_t i) { return ((float*)ptr)[7*N+i]; }; //!< Barycentric v coordinate of hit
  228. RTCORE_FORCEINLINE float& RTCHitN_t (const RTCHitN* ptr, size_t N, size_t i) { return ((float*)ptr)[8*N+i]; }; //!< hit distance
  229. #endif
  230. /* Helper structure to create a hit packet of compile time size N */
  231. #ifndef __RTCHitNt__
  232. #define __RTCHitNt__
  233. template<int N>
  234. struct RTCHitNt : public RTCHitN
  235. {
  236. float Ngx[N]; //!< x coordinate of geometry normal
  237. float Ngy[N]; //!< y coordinate of geometry normal
  238. float Ngz[N]; //!< z coordinate of geometry normal
  239. unsigned instID[N]; //!< instance ID
  240. unsigned geomID[N]; //!< geometry ID
  241. unsigned primID[N]; //!< primitive ID
  242. float u[N]; //!< Barycentric u coordinate of hit
  243. float v[N]; //!< Barycentric v coordinate of hit
  244. float t[N]; //!< hit distance
  245. };
  246. #endif
  247. /*! @} */
  248. #endif