trianglei_mb_intersector.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 "trianglei_mb.h"
  18. #include "triangle_intersector_moeller.h"
  19. #include "triangle_intersector_pluecker.h"
  20. namespace embree
  21. {
  22. namespace isa
  23. {
  24. /*! Intersects M motion blur triangles with 1 ray */
  25. template<int M, int Mx, bool filter>
  26. struct TriangleMiMBIntersector1Moeller
  27. {
  28. typedef TriangleMiMB<M> Primitive;
  29. typedef Intersector1PrecalculationsMB<MoellerTrumboreIntersector1<Mx>> Precalculations;
  30. /*! Intersect a ray with the M triangles and updates the hit. */
  31. static __forceinline void intersect(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& tri)
  32. {
  33. STAT3(normal.trav_prims,1,1,1);
  34. Vec3<vfloat<M>> v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time);
  35. pre.intersect(ray,v0,v1,v2,/*UVIdentity<Mx>(),*/Intersect1EpilogM<M,Mx,filter>(ray,context,tri.geomIDs,tri.primIDs));
  36. }
  37. /*! Test if the ray is occluded by one of M triangles. */
  38. static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& tri)
  39. {
  40. STAT3(shadow.trav_prims,1,1,1);
  41. Vec3<vfloat<M>> v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time);
  42. return pre.intersect(ray,v0,v1,v2,/*UVIdentity<Mx>(),*/Occluded1EpilogM<M,Mx,filter>(ray,context,tri.geomIDs,tri.primIDs));
  43. }
  44. };
  45. /*! Intersects M motion blur triangles with K rays. */
  46. template<int M, int Mx, int K, bool filter>
  47. struct TriangleMiMBIntersectorKMoeller
  48. {
  49. typedef TriangleMiMB<M> Primitive;
  50. typedef IntersectorKPrecalculationsMB<K,MoellerTrumboreIntersectorK<Mx,K>> Precalculations;
  51. /*! Intersects K rays with M triangles. */
  52. static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const TriangleMiMB<M>& tri)
  53. {
  54. for (size_t i=0; i<TriangleMiMB<M>::max_size(); i++)
  55. {
  56. if (!tri.valid(i)) break;
  57. STAT3(normal.trav_prims,1,popcnt(valid_i),K);
  58. Vec3<vfloat<K>> v0,v1,v2; tri.gather(valid_i,v0,v1,v2,i,context->scene,ray.time);
  59. pre.intersectK(valid_i,ray,v0,v1,v2,/*UVIdentity<K>(),*/IntersectKEpilogM<M,K,filter>(ray,context,tri.geomIDs,tri.primIDs,i));
  60. }
  61. }
  62. /*! Test for K rays if they are occluded by any of the M triangles. */
  63. static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const TriangleMiMB<M>& tri)
  64. {
  65. vbool<K> valid0 = valid_i;
  66. for (size_t i=0; i<TriangleMiMB<M>::max_size(); i++)
  67. {
  68. if (!tri.valid(i)) break;
  69. STAT3(shadow.trav_prims,1,popcnt(valid0),K);
  70. Vec3<vfloat<K>> v0,v1,v2; tri.gather(valid_i,v0,v1,v2,i,context->scene,ray.time);
  71. pre.intersectK(valid0,ray,v0,v1,v2,/*UVIdentity<K>(),*/OccludedKEpilogM<M,K,filter>(valid0,ray,context,tri.geomIDs,tri.primIDs,i));
  72. if (none(valid0)) break;
  73. }
  74. return !valid0;
  75. }
  76. /*! Intersect a ray with M triangles and updates the hit. */
  77. static __forceinline void intersect(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const TriangleMiMB<M>& tri)
  78. {
  79. STAT3(normal.trav_prims,1,1,1);
  80. Vec3<vfloat<M>> v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time[k]);
  81. pre.intersect(ray,k,v0,v1,v2,/*UVIdentity<Mx>(),*/Intersect1KEpilogM<M,Mx,K,filter>(ray,k,context,tri.geomIDs,tri.primIDs));
  82. }
  83. /*! Test if the ray is occluded by one of the M triangles. */
  84. static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const TriangleMiMB<M>& tri)
  85. {
  86. STAT3(shadow.trav_prims,1,1,1);
  87. Vec3<vfloat<M>> v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time[k]);
  88. return pre.intersect(ray,k,v0,v1,v2,/*UVIdentity<Mx>(),*/Occluded1KEpilogM<M,Mx,K,filter>(ray,k,context,tri.geomIDs,tri.primIDs));
  89. }
  90. };
  91. /*! Intersects M motion blur triangles with 1 ray */
  92. template<int M, int Mx, bool filter>
  93. struct TriangleMiMBIntersector1Pluecker
  94. {
  95. typedef TriangleMiMB<M> Primitive;
  96. typedef Intersector1PrecalculationsMB<PlueckerIntersector1<Mx>> Precalculations;
  97. /*! Intersect a ray with the M triangles and updates the hit. */
  98. static __forceinline void intersect(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& tri)
  99. {
  100. STAT3(normal.trav_prims,1,1,1);
  101. Vec3<vfloat<M>> v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time);
  102. pre.intersect(ray,v0,v1,v2,UVIdentity<Mx>(),Intersect1EpilogM<M,Mx,filter>(ray,context,tri.geomIDs,tri.primIDs));
  103. }
  104. /*! Test if the ray is occluded by one of M triangles. */
  105. static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& tri)
  106. {
  107. STAT3(shadow.trav_prims,1,1,1);
  108. Vec3<vfloat<M>> v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time);
  109. return pre.intersect(ray,v0,v1,v2,UVIdentity<Mx>(),Occluded1EpilogM<M,Mx,filter>(ray,context,tri.geomIDs,tri.primIDs));
  110. }
  111. };
  112. /*! Intersects M motion blur triangles with K rays. */
  113. template<int M, int Mx, int K, bool filter>
  114. struct TriangleMiMBIntersectorKPluecker
  115. {
  116. typedef TriangleMiMB<M> Primitive;
  117. typedef IntersectorKPrecalculationsMB<K,PlueckerIntersectorK<Mx,K>> Precalculations;
  118. /*! Intersects K rays with M triangles. */
  119. static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const TriangleMiMB<M>& tri)
  120. {
  121. for (size_t i=0; i<TriangleMiMB<M>::max_size(); i++)
  122. {
  123. if (!tri.valid(i)) break;
  124. STAT3(normal.trav_prims,1,popcnt(valid_i),K);
  125. Vec3<vfloat<K>> v0,v1,v2; tri.gather(valid_i,v0,v1,v2,i,context->scene,ray.time);
  126. pre.intersectK(valid_i,ray,v0,v1,v2,UVIdentity<K>(),IntersectKEpilogM<M,K,filter>(ray,context,tri.geomIDs,tri.primIDs,i));
  127. }
  128. }
  129. /*! Test for K rays if they are occluded by any of the M triangles. */
  130. static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const TriangleMiMB<M>& tri)
  131. {
  132. vbool<K> valid0 = valid_i;
  133. for (size_t i=0; i<TriangleMiMB<M>::max_size(); i++)
  134. {
  135. if (!tri.valid(i)) break;
  136. STAT3(shadow.trav_prims,1,popcnt(valid0),K);
  137. Vec3<vfloat<K>> v0,v1,v2; tri.gather(valid_i,v0,v1,v2,i,context->scene,ray.time);
  138. pre.intersectK(valid0,ray,v0,v1,v2,UVIdentity<K>(),OccludedKEpilogM<M,K,filter>(valid0,ray,context,tri.geomIDs,tri.primIDs,i));
  139. if (none(valid0)) break;
  140. }
  141. return !valid0;
  142. }
  143. /*! Intersect a ray with M triangles and updates the hit. */
  144. static __forceinline void intersect(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const TriangleMiMB<M>& tri)
  145. {
  146. STAT3(normal.trav_prims,1,1,1);
  147. Vec3<vfloat<M>> v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time[k]);
  148. pre.intersect(ray,k,v0,v1,v2,UVIdentity<Mx>(),Intersect1KEpilogM<M,Mx,K,filter>(ray,k,context,tri.geomIDs,tri.primIDs));
  149. }
  150. /*! Test if the ray is occluded by one of the M triangles. */
  151. static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const TriangleMiMB<M>& tri)
  152. {
  153. STAT3(shadow.trav_prims,1,1,1);
  154. Vec3<vfloat<M>> v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time[k]);
  155. return pre.intersect(ray,k,v0,v1,v2,UVIdentity<Mx>(),Occluded1KEpilogM<M,Mx,K,filter>(ray,k,context,tri.geomIDs,tri.primIDs));
  156. }
  157. };
  158. }
  159. }