trianglev_mb_intersector.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. #pragma once
  17. #include "triangle.h"
  18. #include "intersector_epilog.h"
  19. namespace embree
  20. {
  21. namespace isa
  22. {
  23. /*! Intersects M motion blur triangles with 1 ray */
  24. template<int M, int Mx, bool filter>
  25. struct TriangleMvMBIntersector1Moeller
  26. {
  27. typedef TriangleMvMB<M> Primitive;
  28. typedef Intersector1PrecalculationsMB<MoellerTrumboreIntersector1<Mx>> Precalculations;
  29. /*! Intersect a ray with the M triangles and updates the hit. */
  30. static __forceinline void intersect(const Precalculations& pre, Ray& ray, IntersectContext* context, const TriangleMvMB<M>& tri)
  31. {
  32. STAT3(normal.trav_prims,1,1,1);
  33. const Vec3<vfloat<Mx>> time(pre.ftime());
  34. const Vec3<vfloat<Mx>> v0 = madd(time,Vec3<vfloat<Mx>>(tri.dv0),Vec3<vfloat<Mx>>(tri.v0));
  35. const Vec3<vfloat<Mx>> v1 = madd(time,Vec3<vfloat<Mx>>(tri.dv1),Vec3<vfloat<Mx>>(tri.v1));
  36. const Vec3<vfloat<Mx>> v2 = madd(time,Vec3<vfloat<Mx>>(tri.dv2),Vec3<vfloat<Mx>>(tri.v2));
  37. pre.intersect(ray,v0,v1,v2,Intersect1EpilogM<M,Mx,filter>(ray,context,tri.geomIDs,tri.primIDs));
  38. }
  39. /*! Test if the ray is occluded by one of M triangles. */
  40. static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const TriangleMvMB<M>& tri)
  41. {
  42. STAT3(shadow.trav_prims,1,1,1);
  43. const Vec3<vfloat<Mx>> time(pre.ftime());
  44. const Vec3<vfloat<Mx>> v0 = madd(time,Vec3<vfloat<Mx>>(tri.dv0),Vec3<vfloat<Mx>>(tri.v0));
  45. const Vec3<vfloat<Mx>> v1 = madd(time,Vec3<vfloat<Mx>>(tri.dv1),Vec3<vfloat<Mx>>(tri.v1));
  46. const Vec3<vfloat<Mx>> v2 = madd(time,Vec3<vfloat<Mx>>(tri.dv2),Vec3<vfloat<Mx>>(tri.v2));
  47. return pre.intersect(ray,v0,v1,v2,Occluded1EpilogM<M,Mx,filter>(ray,context,tri.geomIDs,tri.primIDs));
  48. }
  49. };
  50. /*! Intersects M motion blur triangles with K rays. */
  51. template<int M, int Mx, int K, bool filter>
  52. struct TriangleMvMBIntersectorKMoeller
  53. {
  54. typedef TriangleMvMB<M> Primitive;
  55. typedef IntersectorKPrecalculationsMB<K,MoellerTrumboreIntersectorK<Mx,K>> Precalculations;
  56. /*! Intersects K rays with M triangles. */
  57. static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const TriangleMvMB<M>& tri)
  58. {
  59. for (size_t i=0; i<TriangleMvMB<M>::max_size(); i++)
  60. {
  61. if (!tri.valid(i)) break;
  62. STAT3(normal.trav_prims,1,popcnt(valid_i),K);
  63. const Vec3<vfloat<K>> time(pre.ftime());
  64. const Vec3<vfloat<K>> v0 = madd(time,broadcast<vfloat<K>>(tri.dv0,i),broadcast<vfloat<K>>(tri.v0,i));
  65. const Vec3<vfloat<K>> v1 = madd(time,broadcast<vfloat<K>>(tri.dv1,i),broadcast<vfloat<K>>(tri.v1,i));
  66. const Vec3<vfloat<K>> v2 = madd(time,broadcast<vfloat<K>>(tri.dv2,i),broadcast<vfloat<K>>(tri.v2,i));
  67. pre.intersectK(valid_i,ray,v0,v1,v2,IntersectKEpilogM<M,K,filter>(ray,context,tri.geomIDs,tri.primIDs,i));
  68. }
  69. }
  70. /*! Test for K rays if they are occluded by any of the M triangles. */
  71. static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const TriangleMvMB<M>& tri)
  72. {
  73. vbool<K> valid0 = valid_i;
  74. for (size_t i=0; i<TriangleMvMB<M>::max_size(); i++)
  75. {
  76. if (!tri.valid(i)) break;
  77. STAT3(shadow.trav_prims,1,popcnt(valid0),K);
  78. const Vec3<vfloat<K>> time(pre.ftime());
  79. const Vec3<vfloat<K>> v0 = madd(time,broadcast<vfloat<K>>(tri.dv0,i),broadcast<vfloat<K>>(tri.v0,i));
  80. const Vec3<vfloat<K>> v1 = madd(time,broadcast<vfloat<K>>(tri.dv1,i),broadcast<vfloat<K>>(tri.v1,i));
  81. const Vec3<vfloat<K>> v2 = madd(time,broadcast<vfloat<K>>(tri.dv2,i),broadcast<vfloat<K>>(tri.v2,i));
  82. pre.intersectK(valid0,ray,v0,v1,v2,OccludedKEpilogM<M,K,filter>(valid0,ray,context,tri.geomIDs,tri.primIDs,i));
  83. if (none(valid0)) break;
  84. }
  85. return !valid0;
  86. }
  87. /*! Intersect a ray with M triangles and updates the hit. */
  88. static __forceinline void intersect(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const TriangleMvMB<M>& tri)
  89. {
  90. STAT3(normal.trav_prims,1,1,1);
  91. const Vec3<vfloat<Mx>> time(pre.ftime(k));
  92. const Vec3<vfloat<Mx>> v0 = madd(time,Vec3<vfloat<Mx>>(tri.dv0),Vec3<vfloat<Mx>>(tri.v0));
  93. const Vec3<vfloat<Mx>> v1 = madd(time,Vec3<vfloat<Mx>>(tri.dv1),Vec3<vfloat<Mx>>(tri.v1));
  94. const Vec3<vfloat<Mx>> v2 = madd(time,Vec3<vfloat<Mx>>(tri.dv2),Vec3<vfloat<Mx>>(tri.v2));
  95. pre.intersect(ray,k,v0,v1,v2,Intersect1KEpilogM<M,Mx,K,filter>(ray,k,context,tri.geomIDs,tri.primIDs));
  96. }
  97. /*! Test if the ray is occluded by one of the M triangles. */
  98. static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const TriangleMvMB<M>& tri)
  99. {
  100. STAT3(shadow.trav_prims,1,1,1);
  101. const Vec3<vfloat<Mx>> time(pre.ftime(k));
  102. const Vec3<vfloat<Mx>> v0 = madd(time,Vec3<vfloat<Mx>>(tri.dv0),Vec3<vfloat<Mx>>(tri.v0));
  103. const Vec3<vfloat<Mx>> v1 = madd(time,Vec3<vfloat<Mx>>(tri.dv1),Vec3<vfloat<Mx>>(tri.v1));
  104. const Vec3<vfloat<Mx>> v2 = madd(time,Vec3<vfloat<Mx>>(tri.dv2),Vec3<vfloat<Mx>>(tri.v2));
  105. return pre.intersect(ray,k,v0,v1,v2,Occluded1KEpilogM<M,Mx,K,filter>(ray,k,context,tri.geomIDs,tri.primIDs));
  106. }
  107. };
  108. /*! Intersects M motion blur triangles with 1 ray */
  109. template<int M, int Mx, bool filter>
  110. struct TriangleMvMBIntersector1Pluecker
  111. {
  112. typedef TriangleMvMB<M> Primitive;
  113. typedef Intersector1PrecalculationsMB<PlueckerIntersector1<Mx>> Precalculations;
  114. /*! Intersect a ray with the M triangles and updates the hit. */
  115. static __forceinline void intersect(const Precalculations& pre, Ray& ray, IntersectContext* context, const TriangleMvMB<M>& tri)
  116. {
  117. STAT3(normal.trav_prims,1,1,1);
  118. const Vec3<vfloat<Mx>> time(pre.ftime());
  119. const Vec3<vfloat<Mx>> v0 = madd(time,Vec3<vfloat<Mx>>(tri.dv0),Vec3<vfloat<Mx>>(tri.v0));
  120. const Vec3<vfloat<Mx>> v1 = madd(time,Vec3<vfloat<Mx>>(tri.dv1),Vec3<vfloat<Mx>>(tri.v1));
  121. const Vec3<vfloat<Mx>> v2 = madd(time,Vec3<vfloat<Mx>>(tri.dv2),Vec3<vfloat<Mx>>(tri.v2));
  122. pre.intersect(ray,v0,v1,v2,UVIdentity<Mx>(),Intersect1EpilogM<M,Mx,filter>(ray,context,tri.geomIDs,tri.primIDs));
  123. }
  124. /*! Test if the ray is occluded by one of M triangles. */
  125. static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const TriangleMvMB<M>& tri)
  126. {
  127. STAT3(shadow.trav_prims,1,1,1);
  128. const Vec3<vfloat<Mx>> time(pre.ftime());
  129. const Vec3<vfloat<Mx>> v0 = madd(time,Vec3<vfloat<Mx>>(tri.dv0),Vec3<vfloat<Mx>>(tri.v0));
  130. const Vec3<vfloat<Mx>> v1 = madd(time,Vec3<vfloat<Mx>>(tri.dv1),Vec3<vfloat<Mx>>(tri.v1));
  131. const Vec3<vfloat<Mx>> v2 = madd(time,Vec3<vfloat<Mx>>(tri.dv2),Vec3<vfloat<Mx>>(tri.v2));
  132. return pre.intersect(ray,v0,v1,v2,UVIdentity<Mx>(),Occluded1EpilogM<M,Mx,filter>(ray,context,tri.geomIDs,tri.primIDs));
  133. }
  134. };
  135. /*! Intersects M motion blur triangles with K rays. */
  136. template<int M, int Mx, int K, bool filter>
  137. struct TriangleMvMBIntersectorKPluecker
  138. {
  139. typedef TriangleMvMB<M> Primitive;
  140. typedef IntersectorKPrecalculationsMB<K,PlueckerIntersectorK<Mx,K>> Precalculations;
  141. /*! Intersects K rays with M triangles. */
  142. static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const TriangleMvMB<M>& tri)
  143. {
  144. for (size_t i=0; i<TriangleMvMB<M>::max_size(); i++)
  145. {
  146. if (!tri.valid(i)) break;
  147. STAT3(normal.trav_prims,1,popcnt(valid_i),K);
  148. const Vec3<vfloat<K>> time(pre.ftime());
  149. const Vec3<vfloat<K>> v0 = madd(time,broadcast<vfloat<K>>(tri.dv0,i),broadcast<vfloat<K>>(tri.v0,i));
  150. const Vec3<vfloat<K>> v1 = madd(time,broadcast<vfloat<K>>(tri.dv1,i),broadcast<vfloat<K>>(tri.v1,i));
  151. const Vec3<vfloat<K>> v2 = madd(time,broadcast<vfloat<K>>(tri.dv2,i),broadcast<vfloat<K>>(tri.v2,i));
  152. pre.intersectK(valid_i,ray,v0,v1,v2,UVIdentity<K>(),IntersectKEpilogM<M,K,filter>(ray,context,tri.geomIDs,tri.primIDs,i));
  153. }
  154. }
  155. /*! Test for K rays if they are occluded by any of the M triangles. */
  156. static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const TriangleMvMB<M>& tri)
  157. {
  158. vbool<K> valid0 = valid_i;
  159. for (size_t i=0; i<TriangleMvMB<M>::max_size(); i++)
  160. {
  161. if (!tri.valid(i)) break;
  162. STAT3(shadow.trav_prims,1,popcnt(valid0),K);
  163. const Vec3<vfloat<K>> time(pre.ftime());
  164. const Vec3<vfloat<K>> v0 = madd(time,broadcast<vfloat<K>>(tri.dv0,i),broadcast<vfloat<K>>(tri.v0,i));
  165. const Vec3<vfloat<K>> v1 = madd(time,broadcast<vfloat<K>>(tri.dv1,i),broadcast<vfloat<K>>(tri.v1,i));
  166. const Vec3<vfloat<K>> v2 = madd(time,broadcast<vfloat<K>>(tri.dv2,i),broadcast<vfloat<K>>(tri.v2,i));
  167. pre.intersectK(valid0,ray,v0,v1,v2,UVIdentity<K>(),OccludedKEpilogM<M,K,filter>(valid0,ray,context,tri.geomIDs,tri.primIDs,i));
  168. if (none(valid0)) break;
  169. }
  170. return !valid0;
  171. }
  172. /*! Intersect a ray with M triangles and updates the hit. */
  173. static __forceinline void intersect(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const TriangleMvMB<M>& tri)
  174. {
  175. STAT3(normal.trav_prims,1,1,1);
  176. const Vec3<vfloat<Mx>> time(pre.ftime(k));
  177. const Vec3<vfloat<Mx>> v0 = madd(time,Vec3<vfloat<Mx>>(tri.dv0),Vec3<vfloat<Mx>>(tri.v0));
  178. const Vec3<vfloat<Mx>> v1 = madd(time,Vec3<vfloat<Mx>>(tri.dv1),Vec3<vfloat<Mx>>(tri.v1));
  179. const Vec3<vfloat<Mx>> v2 = madd(time,Vec3<vfloat<Mx>>(tri.dv2),Vec3<vfloat<Mx>>(tri.v2));
  180. pre.intersect(ray,k,v0,v1,v2,UVIdentity<Mx>(),Intersect1KEpilogM<M,Mx,K,filter>(ray,k,context,tri.geomIDs,tri.primIDs));
  181. }
  182. /*! Test if the ray is occluded by one of the M triangles. */
  183. static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const TriangleMvMB<M>& tri)
  184. {
  185. STAT3(shadow.trav_prims,1,1,1);
  186. const Vec3<vfloat<Mx>> time(pre.ftime(k));
  187. const Vec3<vfloat<Mx>> v0 = madd(time,Vec3<vfloat<Mx>>(tri.dv0),Vec3<vfloat<Mx>>(tri.v0));
  188. const Vec3<vfloat<Mx>> v1 = madd(time,Vec3<vfloat<Mx>>(tri.dv1),Vec3<vfloat<Mx>>(tri.v1));
  189. const Vec3<vfloat<Mx>> v2 = madd(time,Vec3<vfloat<Mx>>(tri.dv2),Vec3<vfloat<Mx>>(tri.v2));
  190. return pre.intersect(ray,k,v0,v1,v2,UVIdentity<Mx>(),Occluded1KEpilogM<M,Mx,K,filter>(ray,k,context,tri.geomIDs,tri.primIDs));
  191. }
  192. };
  193. }
  194. }