quadi_intersector.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "quadi.h"
  5. #include "quad_intersector_moeller.h"
  6. #include "quad_intersector_pluecker.h"
  7. namespace embree
  8. {
  9. namespace isa
  10. {
  11. /*! Intersects M quads with 1 ray */
  12. template<int M, bool filter>
  13. struct QuadMiIntersector1Moeller
  14. {
  15. typedef QuadMi<M> Primitive;
  16. typedef QuadMIntersector1MoellerTrumbore<M,filter> Precalculations;
  17. /*! Intersect a ray with the M quads and updates the hit. */
  18. static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& quad)
  19. {
  20. STAT3(normal.trav_prims,1,1,1);
  21. Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene);
  22. pre.intersect(ray,context,v0,v1,v2,v3,quad.geomID(),quad.primID());
  23. }
  24. /*! Test if the ray is occluded by one of M quads. */
  25. static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& quad)
  26. {
  27. STAT3(shadow.trav_prims,1,1,1);
  28. Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene);
  29. return pre.occluded(ray,context,v0,v1,v2,v3,quad.geomID(),quad.primID());
  30. }
  31. static __forceinline bool pointQuery(PointQuery* query, PointQueryContext* context, const Primitive& quad)
  32. {
  33. return PrimitivePointQuery1<Primitive>::pointQuery(query, context, quad);
  34. }
  35. };
  36. /*! Intersects M triangles with K rays. */
  37. template<int M, int K, bool filter>
  38. struct QuadMiIntersectorKMoeller
  39. {
  40. typedef QuadMi<M> Primitive;
  41. typedef QuadMIntersectorKMoellerTrumbore<M,K,filter> Precalculations;
  42. /*! Intersects K rays with M triangles. */
  43. static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const QuadMi<M>& quad)
  44. {
  45. Scene* scene = context->scene;
  46. for (size_t i=0; i<QuadMi<M>::max_size(); i++)
  47. {
  48. if (!quad.valid(i)) break;
  49. STAT3(normal.trav_prims,1,popcnt(valid_i),K);
  50. const Vec3vf<K> p0 = quad.template getVertex<0>(i,scene);
  51. const Vec3vf<K> p1 = quad.template getVertex<1>(i,scene);
  52. const Vec3vf<K> p2 = quad.template getVertex<2>(i,scene);
  53. const Vec3vf<K> p3 = quad.template getVertex<3>(i,scene);
  54. pre.intersectK(valid_i,ray,p0,p1,p2,p3,IntersectKEpilogM<M,K,filter>(ray,context,quad.geomID(),quad.primID(),i));
  55. }
  56. }
  57. /*! Test for K rays if they are occluded by any of the M triangles. */
  58. static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const QuadMi<M>& quad)
  59. {
  60. Scene* scene = context->scene;
  61. vbool<K> valid0 = valid_i;
  62. for (size_t i=0; i<QuadMi<M>::max_size(); i++)
  63. {
  64. if (!quad.valid(i)) break;
  65. STAT3(shadow.trav_prims,1,popcnt(valid0),K);
  66. const Vec3vf<K> p0 = quad.template getVertex<0>(i,scene);
  67. const Vec3vf<K> p1 = quad.template getVertex<1>(i,scene);
  68. const Vec3vf<K> p2 = quad.template getVertex<2>(i,scene);
  69. const Vec3vf<K> p3 = quad.template getVertex<3>(i,scene);
  70. if (pre.intersectK(valid0,ray,p0,p1,p2,p3,OccludedKEpilogM<M,K,filter>(valid0,ray,context,quad.geomID(),quad.primID(),i)))
  71. break;
  72. }
  73. return !valid0;
  74. }
  75. /*! Intersect a ray with M triangles and updates the hit. */
  76. static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const QuadMi<M>& quad)
  77. {
  78. STAT3(normal.trav_prims,1,1,1);
  79. Vec3vf4 v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene);
  80. pre.intersect1(ray,k,context,v0,v1,v2,v3,quad.geomID(),quad.primID());
  81. }
  82. /*! Test if the ray is occluded by one of the M triangles. */
  83. static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const QuadMi<M>& quad)
  84. {
  85. STAT3(shadow.trav_prims,1,1,1);
  86. Vec3vf4 v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene);
  87. return pre.occluded1(ray,k,context,v0,v1,v2,v3,quad.geomID(),quad.primID());
  88. }
  89. };
  90. /*! Intersects M quads with 1 ray */
  91. template<int M, bool filter>
  92. struct QuadMiIntersector1Pluecker
  93. {
  94. typedef QuadMi<M> Primitive;
  95. typedef QuadMIntersector1Pluecker<M,filter> Precalculations;
  96. /*! Intersect a ray with the M quads and updates the hit. */
  97. static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& quad)
  98. {
  99. STAT3(normal.trav_prims,1,1,1);
  100. Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene);
  101. pre.intersect(ray,context,v0,v1,v2,v3,quad.geomID(),quad.primID());
  102. }
  103. /*! Test if the ray is occluded by one of M quads. */
  104. static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& quad)
  105. {
  106. STAT3(shadow.trav_prims,1,1,1);
  107. Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene);
  108. return pre.occluded(ray,context,v0,v1,v2,v3,quad.geomID(),quad.primID());
  109. }
  110. static __forceinline bool pointQuery(PointQuery* query, PointQueryContext* context, const Primitive& quad)
  111. {
  112. return PrimitivePointQuery1<Primitive>::pointQuery(query, context, quad);
  113. }
  114. };
  115. /*! Intersects M triangles with K rays. */
  116. template<int M, int K, bool filter>
  117. struct QuadMiIntersectorKPluecker
  118. {
  119. typedef QuadMi<M> Primitive;
  120. typedef QuadMIntersectorKPluecker<M,K,filter> Precalculations;
  121. /*! Intersects K rays with M triangles. */
  122. static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const QuadMi<M>& quad)
  123. {
  124. Scene* scene = context->scene;
  125. for (size_t i=0; i<QuadMi<M>::max_size(); i++)
  126. {
  127. if (!quad.valid(i)) break;
  128. STAT3(normal.trav_prims,1,popcnt(valid_i),K);
  129. const Vec3vf<K> p0 = quad.template getVertex<0>(i,scene);
  130. const Vec3vf<K> p1 = quad.template getVertex<1>(i,scene);
  131. const Vec3vf<K> p2 = quad.template getVertex<2>(i,scene);
  132. const Vec3vf<K> p3 = quad.template getVertex<3>(i,scene);
  133. pre.intersectK(valid_i,ray,p0,p1,p2,p3,IntersectKEpilogM<M,K,filter>(ray,context,quad.geomID(),quad.primID(),i));
  134. }
  135. }
  136. /*! Test for K rays if they are occluded by any of the M triangles. */
  137. static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const QuadMi<M>& quad)
  138. {
  139. Scene* scene = context->scene;
  140. vbool<K> valid0 = valid_i;
  141. for (size_t i=0; i<QuadMi<M>::max_size(); i++)
  142. {
  143. if (!quad.valid(i)) break;
  144. STAT3(shadow.trav_prims,1,popcnt(valid0),K);
  145. const Vec3vf<K> p0 = quad.template getVertex<0>(i,scene);
  146. const Vec3vf<K> p1 = quad.template getVertex<1>(i,scene);
  147. const Vec3vf<K> p2 = quad.template getVertex<2>(i,scene);
  148. const Vec3vf<K> p3 = quad.template getVertex<3>(i,scene);
  149. if (pre.intersectK(valid0,ray,p0,p1,p2,p3,OccludedKEpilogM<M,K,filter>(valid0,ray,context,quad.geomID(),quad.primID(),i)))
  150. break;
  151. }
  152. return !valid0;
  153. }
  154. /*! Intersect a ray with M triangles and updates the hit. */
  155. static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const QuadMi<M>& quad)
  156. {
  157. STAT3(normal.trav_prims,1,1,1);
  158. Vec3vf4 v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene);
  159. pre.intersect1(ray,k,context,v0,v1,v2,v3,quad.geomID(),quad.primID());
  160. }
  161. /*! Test if the ray is occluded by one of the M triangles. */
  162. static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const QuadMi<M>& quad)
  163. {
  164. STAT3(shadow.trav_prims,1,1,1);
  165. Vec3vf4 v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene);
  166. return pre.occluded1(ray,k,context,v0,v1,v2,v3,quad.geomID(),quad.primID());
  167. }
  168. };
  169. /*! Intersects M motion blur quads with 1 ray */
  170. template<int M, bool filter>
  171. struct QuadMiMBIntersector1Moeller
  172. {
  173. typedef QuadMi<M> Primitive;
  174. typedef QuadMIntersector1MoellerTrumbore<M,filter> Precalculations;
  175. /*! Intersect a ray with the M quads and updates the hit. */
  176. static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& quad)
  177. {
  178. STAT3(normal.trav_prims,1,1,1);
  179. Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time());
  180. pre.intersect(ray,context,v0,v1,v2,v3,quad.geomID(),quad.primID());
  181. }
  182. /*! Test if the ray is occluded by one of M quads. */
  183. static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& quad)
  184. {
  185. STAT3(shadow.trav_prims,1,1,1);
  186. Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time());
  187. return pre.occluded(ray,context,v0,v1,v2,v3,quad.geomID(),quad.primID());
  188. }
  189. static __forceinline bool pointQuery(PointQuery* query, PointQueryContext* context, const Primitive& quad)
  190. {
  191. return PrimitivePointQuery1<Primitive>::pointQuery(query, context, quad);
  192. }
  193. };
  194. /*! Intersects M motion blur quads with K rays. */
  195. template<int M, int K, bool filter>
  196. struct QuadMiMBIntersectorKMoeller
  197. {
  198. typedef QuadMi<M> Primitive;
  199. typedef QuadMIntersectorKMoellerTrumbore<M,K,filter> Precalculations;
  200. /*! Intersects K rays with M quads. */
  201. static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const QuadMi<M>& quad)
  202. {
  203. for (size_t i=0; i<QuadMi<M>::max_size(); i++)
  204. {
  205. if (!quad.valid(i)) break;
  206. STAT3(normal.trav_prims,1,popcnt(valid_i),K);
  207. Vec3vf<K> v0,v1,v2,v3; quad.template gather<K>(valid_i,v0,v1,v2,v3,i,context->scene,ray.time());
  208. pre.intersectK(valid_i,ray,v0,v1,v2,v3,IntersectKEpilogM<M,K,filter>(ray,context,quad.geomID(),quad.primID(),i));
  209. }
  210. }
  211. /*! Test for K rays if they are occluded by any of the M quads. */
  212. static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const QuadMi<M>& quad)
  213. {
  214. vbool<K> valid0 = valid_i;
  215. for (size_t i=0; i<QuadMi<M>::max_size(); i++)
  216. {
  217. if (!quad.valid(i)) break;
  218. STAT3(shadow.trav_prims,1,popcnt(valid0),K);
  219. Vec3vf<K> v0,v1,v2,v3; quad.template gather<K>(valid_i,v0,v1,v2,v3,i,context->scene,ray.time());
  220. if (pre.intersectK(valid0,ray,v0,v1,v2,v3,OccludedKEpilogM<M,K,filter>(valid0,ray,context,quad.geomID(),quad.primID(),i)))
  221. break;
  222. }
  223. return !valid0;
  224. }
  225. /*! Intersect a ray with M quads and updates the hit. */
  226. static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const QuadMi<M>& quad)
  227. {
  228. STAT3(normal.trav_prims,1,1,1);
  229. Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time()[k]);
  230. pre.intersect1(ray,k,context,v0,v1,v2,v3,quad.geomID(),quad.primID());
  231. }
  232. /*! Test if the ray is occluded by one of the M quads. */
  233. static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const QuadMi<M>& quad)
  234. {
  235. STAT3(shadow.trav_prims,1,1,1);
  236. Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time()[k]);
  237. return pre.occluded1(ray,k,context,v0,v1,v2,v3,quad.geomID(),quad.primID());
  238. }
  239. };
  240. /*! Intersects M motion blur quads with 1 ray */
  241. template<int M, bool filter>
  242. struct QuadMiMBIntersector1Pluecker
  243. {
  244. typedef QuadMi<M> Primitive;
  245. typedef QuadMIntersector1Pluecker<M,filter> Precalculations;
  246. /*! Intersect a ray with the M quads and updates the hit. */
  247. static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& quad)
  248. {
  249. STAT3(normal.trav_prims,1,1,1);
  250. Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time());
  251. pre.intersect(ray,context,v0,v1,v2,v3,quad.geomID(),quad.primID());
  252. }
  253. /*! Test if the ray is occluded by one of M quads. */
  254. static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& quad)
  255. {
  256. STAT3(shadow.trav_prims,1,1,1);
  257. Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time());
  258. return pre.occluded(ray,context,v0,v1,v2,v3,quad.geomID(),quad.primID());
  259. }
  260. static __forceinline bool pointQuery(PointQuery* query, PointQueryContext* context, const Primitive& quad)
  261. {
  262. return PrimitivePointQuery1<Primitive>::pointQuery(query, context, quad);
  263. }
  264. };
  265. /*! Intersects M motion blur quads with K rays. */
  266. template<int M, int K, bool filter>
  267. struct QuadMiMBIntersectorKPluecker
  268. {
  269. typedef QuadMi<M> Primitive;
  270. typedef QuadMIntersectorKPluecker<M,K,filter> Precalculations;
  271. /*! Intersects K rays with M quads. */
  272. static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const QuadMi<M>& quad)
  273. {
  274. for (size_t i=0; i<QuadMi<M>::max_size(); i++)
  275. {
  276. if (!quad.valid(i)) break;
  277. STAT3(normal.trav_prims,1,popcnt(valid_i),K);
  278. Vec3vf<K> v0,v1,v2,v3; quad.template gather<K>(valid_i,v0,v1,v2,v3,i,context->scene,ray.time());
  279. pre.intersectK(valid_i,ray,v0,v1,v2,v3,IntersectKEpilogM<M,K,filter>(ray,context,quad.geomID(),quad.primID(),i));
  280. }
  281. }
  282. /*! Test for K rays if they are occluded by any of the M quads. */
  283. static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const QuadMi<M>& quad)
  284. {
  285. vbool<K> valid0 = valid_i;
  286. for (size_t i=0; i<QuadMi<M>::max_size(); i++)
  287. {
  288. if (!quad.valid(i)) break;
  289. STAT3(shadow.trav_prims,1,popcnt(valid0),K);
  290. Vec3vf<K> v0,v1,v2,v3; quad.template gather<K>(valid_i,v0,v1,v2,v3,i,context->scene,ray.time());
  291. if (pre.intersectK(valid0,ray,v0,v1,v2,v3,OccludedKEpilogM<M,K,filter>(valid0,ray,context,quad.geomID(),quad.primID(),i)))
  292. break;
  293. }
  294. return !valid0;
  295. }
  296. /*! Intersect a ray with M quads and updates the hit. */
  297. static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const QuadMi<M>& quad)
  298. {
  299. STAT3(normal.trav_prims,1,1,1);
  300. Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time()[k]);
  301. pre.intersect1(ray,k,context,v0,v1,v2,v3,quad.geomID(),quad.primID());
  302. }
  303. /*! Test if the ray is occluded by one of the M quads. */
  304. static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const QuadMi<M>& quad)
  305. {
  306. STAT3(shadow.trav_prims,1,1,1);
  307. Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time()[k]);
  308. return pre.occluded1(ray,k,context,v0,v1,v2,v3,quad.geomID(),quad.primID());
  309. }
  310. };
  311. }
  312. }