bezier1v_intersector.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 "bezier1v.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. /*! Intersector for a single ray with a bezier curve. */
  26. struct Bezier1vIntersector1
  27. {
  28. typedef Bezier1v Primitive;
  29. struct PrecalculationsBase
  30. {
  31. __forceinline PrecalculationsBase() {}
  32. __forceinline PrecalculationsBase(const Ray& ray, const void* ptr)
  33. : intersectorHair(ray,ptr), intersectorCurve(ray,ptr) {}
  34. Bezier1Intersector1<Curve3fa> intersectorHair;
  35. BezierCurve1Intersector1<Curve3fa> intersectorCurve;
  36. };
  37. typedef Intersector1Precalculations<PrecalculationsBase> Precalculations;
  38. static __forceinline void intersect(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim)
  39. {
  40. STAT3(normal.trav_prims,1,1,1);
  41. const NativeCurves* geom = (NativeCurves*)context->scene->get(prim.geomID());
  42. if (likely(geom->subtype == NativeCurves::HAIR))
  43. pre.intersectorHair.intersect(ray,prim.p0,prim.p1,prim.p2,prim.p3,geom->tessellationRate,Intersect1EpilogMU<VSIZEX,true>(ray,context,prim.geomID(),prim.primID()));
  44. else
  45. pre.intersectorCurve.intersect(ray,prim.p0,prim.p1,prim.p2,prim.p3,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. if (likely(geom->subtype == NativeCurves::HAIR))
  52. return pre.intersectorHair.intersect(ray,prim.p0,prim.p1,prim.p2,prim.p3,geom->tessellationRate,Occluded1EpilogMU<VSIZEX,true>(ray,context,prim.geomID(),prim.primID()));
  53. else
  54. return pre.intersectorCurve.intersect(ray,prim.p0,prim.p1,prim.p2,prim.p3,Occluded1Epilog1<true>(ray,context,prim.geomID(),prim.primID()));
  55. }
  56. /*! Intersect an array of rays with an array of M primitives. */
  57. static __forceinline size_t intersect(Precalculations* pre, size_t valid, Ray** rays, IntersectContext* context, size_t ty, const Primitive* prim, size_t num)
  58. {
  59. size_t valid_isec = 0;
  60. do {
  61. const size_t i = __bscf(valid);
  62. const float old_far = rays[i]->tfar;
  63. for (size_t n=0; n<num; n++)
  64. intersect(pre[i],*rays[i],context,prim[n]);
  65. valid_isec |= (rays[i]->tfar < old_far) ? ((size_t)1 << i) : 0;
  66. } while(unlikely(valid));
  67. return valid_isec;
  68. }
  69. };
  70. /*! Intersector for a single ray from a ray packet with a bezier curve. */
  71. template<int K>
  72. struct Bezier1vIntersectorK
  73. {
  74. typedef Bezier1v 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. if (likely(geom->subtype == NativeCurves::HAIR))
  91. pre.intersectorHair.intersect(ray,k,prim.p0,prim.p1,prim.p2,prim.p3,geom->tessellationRate,Intersect1KEpilogMU<VSIZEX,K,true>(ray,k,context,prim.geomID(),prim.primID()));
  92. else
  93. pre.intersectorCurve.intersect(ray,k,prim.p0,prim.p1,prim.p2,prim.p3,Intersect1KEpilog1<K,true>(ray,k,context,prim.geomID(),prim.primID()));
  94. }
  95. static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive& prim)
  96. {
  97. int mask = movemask(valid_i);
  98. while (mask) intersect(pre,ray,__bscf(mask),context,prim);
  99. }
  100. static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim)
  101. {
  102. STAT3(shadow.trav_prims,1,1,1);
  103. const NativeCurves* geom = (NativeCurves*)context->scene->get(prim.geomID());
  104. if (likely(geom->subtype == NativeCurves::HAIR))
  105. return pre.intersectorHair.intersect(ray,k,prim.p0,prim.p1,prim.p2,prim.p3,geom->tessellationRate,Occluded1KEpilogMU<VSIZEX,K,true>(ray,k,context,prim.geomID(),prim.primID()));
  106. else
  107. return pre.intersectorCurve.intersect(ray,k,prim.p0,prim.p1,prim.p2,prim.p3,Occluded1KEpilog1<K,true>(ray,k,context,prim.geomID(),prim.primID()));
  108. }
  109. static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive& prim)
  110. {
  111. vbool<K> valid_o = false;
  112. int mask = movemask(valid_i);
  113. while (mask) {
  114. size_t k = __bscf(mask);
  115. if (occluded(pre,ray,k,context,prim))
  116. set(valid_o, k);
  117. }
  118. return valid_o;
  119. }
  120. };
  121. }
  122. }