bezier1i_intersector.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 "bezier1i.h"
  18. #include "bezier_hair_intersector.h"
  19. #include "bezier_ribbon_intersector.h"
  20. #include "bezier_curve_intersector.h"
  21. namespace embree
  22. {
  23. namespace isa
  24. {
  25. struct Bezier1iIntersector1
  26. {
  27. typedef Bezier1i Primitive;
  28. struct PrecalculationsBase
  29. {
  30. __forceinline PrecalculationsBase() {}
  31. __forceinline PrecalculationsBase(const Ray& ray, const void* ptr)
  32. : intersectorHair(ray,ptr), intersectorCurve(ray,ptr) {}
  33. Bezier1Intersector1<Curve3fa> intersectorHair;
  34. BezierCurve1Intersector1<Curve3fa> intersectorCurve;
  35. };
  36. typedef Intersector1Precalculations<PrecalculationsBase> Precalculations;
  37. static __forceinline void intersect(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim)
  38. {
  39. STAT3(normal.trav_prims,1,1,1);
  40. const NativeCurves* geom = (NativeCurves*) context->scene->get(prim.geomID());
  41. Vec3fa a0,a1,a2,a3; geom->gather(a0,a1,a2,a3,prim.vertexID);
  42. if (likely(geom->subtype == NativeCurves::HAIR))
  43. pre.intersectorHair.intersect(ray,a0,a1,a2,a3,geom->tessellationRate,Intersect1EpilogMU<VSIZEX,true>(ray,context,prim.geomID(),prim.primID()));
  44. else
  45. pre.intersectorCurve.intersect(ray,a0,a1,a2,a3,Intersect1Epilog1<true>(ray,context,prim.geomID(),prim.primID()));
  46. }
  47. static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim)
  48. {
  49. STAT3(shadow.trav_prims,1,1,1);
  50. const NativeCurves* geom = (NativeCurves*) context->scene->get(prim.geomID());
  51. Vec3fa a0,a1,a2,a3; geom->gather(a0,a1,a2,a3,prim.vertexID);
  52. if (likely(geom->subtype == NativeCurves::HAIR))
  53. return pre.intersectorHair.intersect(ray,a0,a1,a2,a3,geom->tessellationRate,Occluded1EpilogMU<VSIZEX,true>(ray,context,prim.geomID(),prim.primID()));
  54. else
  55. return pre.intersectorCurve.intersect(ray,a0,a1,a2,a3,Occluded1Epilog1<true>(ray,context,prim.geomID(),prim.primID()));
  56. }
  57. /*! Intersect an array of rays with an array of M primitives. */
  58. static __forceinline size_t intersect(Precalculations* pre, size_t valid, Ray** rays, IntersectContext* context, size_t ty, const Primitive* prim, size_t num)
  59. {
  60. size_t valid_isec = 0;
  61. do {
  62. const size_t i = __bscf(valid);
  63. const float old_far = rays[i]->tfar;
  64. for (size_t n=0; n<num; n++)
  65. intersect(pre[i],*rays[i],context,prim[n]);
  66. valid_isec |= (rays[i]->tfar < old_far) ? ((size_t)1 << i) : 0;
  67. } while(unlikely(valid));
  68. return valid_isec;
  69. }
  70. };
  71. template<int K>
  72. struct Bezier1iIntersectorK
  73. {
  74. typedef Bezier1i Primitive;
  75. struct PrecalculationsBase
  76. {
  77. __forceinline PrecalculationsBase() {}
  78. __forceinline PrecalculationsBase(const vbool<K>& valid, const RayK<K>& ray)
  79. : intersectorHair(valid,ray), intersectorCurve(valid,ray) {}
  80. __forceinline PrecalculationsBase(const RayK<K>& ray, size_t k)
  81. : intersectorHair(ray,k), intersectorCurve(ray,k) {}
  82. Bezier1IntersectorK<Curve3fa,K> intersectorHair;
  83. BezierCurve1IntersectorK<Curve3fa,K> intersectorCurve;
  84. };
  85. typedef IntersectorKPrecalculations<K,PrecalculationsBase> Precalculations;
  86. static __forceinline void intersect(Precalculations& pre, RayK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim)
  87. {
  88. STAT3(normal.trav_prims,1,1,1);
  89. const NativeCurves* geom = (NativeCurves*) context->scene->get(prim.geomID());
  90. Vec3fa a0,a1,a2,a3; geom->gather(a0,a1,a2,a3,prim.vertexID);
  91. if (likely(geom->subtype == NativeCurves::HAIR))
  92. pre.intersectorHair.intersect(ray,k,a0,a1,a2,a3,geom->tessellationRate,Intersect1KEpilogMU<VSIZEX,K,true>(ray,k,context,prim.geomID(),prim.primID()));
  93. else
  94. pre.intersectorCurve.intersect(ray,k,a0,a1,a2,a3,Intersect1KEpilog1<K,true>(ray,k,context,prim.geomID(),prim.primID()));
  95. }
  96. static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive& prim)
  97. {
  98. int mask = movemask(valid_i);
  99. while (mask) intersect(pre,ray,__bscf(mask),context,prim);
  100. }
  101. static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim)
  102. {
  103. STAT3(shadow.trav_prims,1,1,1);
  104. const NativeCurves* geom = (NativeCurves*) context->scene->get(prim.geomID());
  105. Vec3fa a0,a1,a2,a3; geom->gather(a0,a1,a2,a3,prim.vertexID);
  106. if (likely(geom->subtype == NativeCurves::HAIR))
  107. return pre.intersectorHair.intersect(ray,k,a0,a1,a2,a3,geom->tessellationRate,Occluded1KEpilogMU<VSIZEX,K,true>(ray,k,context,prim.geomID(),prim.primID()));
  108. else
  109. return pre.intersectorCurve.intersect(ray,k,a0,a1,a2,a3,Occluded1KEpilog1<K,true>(ray,k,context,prim.geomID(),prim.primID()));
  110. }
  111. static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive& prim)
  112. {
  113. vbool<K> valid_o = false;
  114. int mask = movemask(valid_i);
  115. while (mask) {
  116. size_t k = __bscf(mask);
  117. if (occluded(pre,ray,k,context,prim))
  118. set(valid_o, k);
  119. }
  120. return valid_o;
  121. }
  122. };
  123. struct Bezier1iIntersector1MB
  124. {
  125. typedef Bezier1i Primitive;
  126. struct PrecalculationsBase
  127. {
  128. __forceinline PrecalculationsBase() {}
  129. __forceinline PrecalculationsBase(const Ray& ray, const void* ptr)
  130. : intersectorHair(ray,ptr), intersectorCurve(ray,ptr) {}
  131. Bezier1Intersector1<Curve3fa> intersectorHair;
  132. BezierCurve1Intersector1<Curve3fa> intersectorCurve;
  133. };
  134. typedef Intersector1PrecalculationsMB<PrecalculationsBase> Precalculations;
  135. static __forceinline void intersect(Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim)
  136. {
  137. STAT3(normal.trav_prims,1,1,1);
  138. const NativeCurves* geom = (NativeCurves*) context->scene->get(prim.geomID());
  139. Vec3fa p0,p1,p2,p3; geom->gather(p0,p1,p2,p3,prim.vertexID,ray.time);
  140. if (likely(geom->subtype == NativeCurves::HAIR))
  141. pre.intersectorHair.intersect(ray,p0,p1,p2,p3,geom->tessellationRate,Intersect1EpilogMU<VSIZEX,true>(ray,context,prim.geomID(),prim.primID()));
  142. else
  143. pre.intersectorCurve.intersect(ray,p0,p1,p2,p3,Intersect1Epilog1<true>(ray,context,prim.geomID(),prim.primID()));
  144. }
  145. static __forceinline bool occluded(Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim)
  146. {
  147. STAT3(shadow.trav_prims,1,1,1);
  148. const NativeCurves* geom = (NativeCurves*) context->scene->get(prim.geomID());
  149. Vec3fa p0,p1,p2,p3; geom->gather(p0,p1,p2,p3,prim.vertexID,ray.time);
  150. if (likely(geom->subtype == NativeCurves::HAIR))
  151. return pre.intersectorHair.intersect(ray,p0,p1,p2,p3,geom->tessellationRate,Occluded1EpilogMU<VSIZEX,true>(ray,context,prim.geomID(),prim.primID()));
  152. else
  153. return pre.intersectorCurve.intersect(ray,p0,p1,p2,p3,Occluded1Epilog1<true>(ray,context,prim.geomID(),prim.primID()));
  154. }
  155. };
  156. template<int K>
  157. struct Bezier1iIntersectorKMB
  158. {
  159. typedef Bezier1i Primitive;
  160. struct PrecalculationsBase
  161. {
  162. __forceinline PrecalculationsBase() {}
  163. __forceinline PrecalculationsBase(const vbool<K>& valid, const RayK<K>& ray)
  164. : intersectorHair(valid,ray), intersectorCurve(valid,ray) {}
  165. __forceinline PrecalculationsBase(const RayK<K>& ray, size_t k)
  166. : intersectorHair(ray,k), intersectorCurve(ray,k) {}
  167. Bezier1IntersectorK<Curve3fa,K> intersectorHair;
  168. BezierCurve1IntersectorK<Curve3fa,K> intersectorCurve;
  169. };
  170. typedef IntersectorKPrecalculationsMB<K,PrecalculationsBase> Precalculations;
  171. static __forceinline void intersect(Precalculations& pre, RayK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim)
  172. {
  173. STAT3(normal.trav_prims,1,1,1);
  174. const NativeCurves* geom = (NativeCurves*) context->scene->get(prim.geomID());
  175. Vec3fa p0,p1,p2,p3; geom->gather(p0,p1,p2,p3,prim.vertexID,ray.time[k]);
  176. if (likely(geom->subtype == NativeCurves::HAIR))
  177. pre.intersectorHair.intersect(ray,k,p0,p1,p2,p3,geom->tessellationRate,Intersect1KEpilogMU<VSIZEX,K,true>(ray,k,context,prim.geomID(),prim.primID()));
  178. else
  179. pre.intersectorCurve.intersect(ray,k,p0,p1,p2,p3,Intersect1KEpilog1<K,true>(ray,k,context,prim.geomID(),prim.primID()));
  180. }
  181. static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive& prim)
  182. {
  183. int mask = movemask(valid_i);
  184. while (mask) intersect(pre,ray,__bscf(mask),context,prim);
  185. }
  186. static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim)
  187. {
  188. STAT3(shadow.trav_prims,1,1,1);
  189. const NativeCurves* geom = (NativeCurves*) context->scene->get(prim.geomID());
  190. Vec3fa p0,p1,p2,p3; geom->gather(p0,p1,p2,p3,prim.vertexID,ray.time[k]);
  191. if (likely(geom->subtype == NativeCurves::HAIR))
  192. return pre.intersectorHair.intersect(ray,k,p0,p1,p2,p3,geom->tessellationRate,Occluded1KEpilogMU<VSIZEX,K,true>(ray,k,context,prim.geomID(),prim.primID()));
  193. else
  194. return pre.intersectorCurve.intersect(ray,k,p0,p1,p2,p3,Occluded1KEpilog1<K,true>(ray,k,context,prim.geomID(),prim.primID()));
  195. }
  196. static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive& prim)
  197. {
  198. vbool<K> valid_o = false;
  199. int mask = movemask(valid_i);
  200. while (mask) {
  201. size_t k = __bscf(mask);
  202. if (occluded(pre,ray,k,context,prim))
  203. set(valid_o, k);
  204. }
  205. return valid_o;
  206. }
  207. };
  208. }
  209. }