quadi_mb_intersector.h 8.6 KB

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