triangle_intersector.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "triangle.h"
  5. #include "triangle_intersector_moeller.h"
  6. namespace embree
  7. {
  8. namespace isa
  9. {
  10. /*! Intersects M triangles with 1 ray */
  11. template<int M, bool filter>
  12. struct TriangleMIntersector1Moeller
  13. {
  14. typedef TriangleM<M> Primitive;
  15. typedef MoellerTrumboreIntersector1<M> Precalculations;
  16. /*! Intersect a ray with the M triangles and updates the hit. */
  17. static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const TriangleM<M>& tri)
  18. {
  19. STAT3(normal.trav_prims,1,1,1);
  20. pre.intersectEdge(ray,tri.v0,tri.e1,tri.e2,UVIdentity<M>(),Intersect1EpilogM<M,filter>(ray,context,tri.geomID(),tri.primID()));
  21. }
  22. /*! Test if the ray is occluded by one of M triangles. */
  23. static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const TriangleM<M>& tri)
  24. {
  25. STAT3(shadow.trav_prims,1,1,1);
  26. return pre.intersectEdge(ray,tri.v0,tri.e1,tri.e2,UVIdentity<M>(),Occluded1EpilogM<M,filter>(ray,context,tri.geomID(),tri.primID()));
  27. }
  28. static __forceinline bool pointQuery(PointQuery* query, PointQueryContext* context, const Primitive& tri)
  29. {
  30. return PrimitivePointQuery1<Primitive>::pointQuery(query, context, tri);
  31. }
  32. };
  33. /*! Intersects M triangles with K rays. */
  34. template<int M, int K, bool filter>
  35. struct TriangleMIntersectorKMoeller
  36. {
  37. typedef TriangleM<M> Primitive;
  38. typedef MoellerTrumboreIntersectorK<M,K> Precalculations;
  39. /*! Intersects K rays with M triangles. */
  40. static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const TriangleM<M>& tri)
  41. {
  42. STAT_USER(0,TriangleM<M>::max_size());
  43. for (size_t i=0; i<TriangleM<M>::max_size(); i++)
  44. {
  45. if (!tri.valid(i)) break;
  46. STAT3(normal.trav_prims,1,popcnt(valid_i),K);
  47. const Vec3vf<K> p0 = broadcast<vfloat<K>>(tri.v0,i);
  48. const Vec3vf<K> e1 = broadcast<vfloat<K>>(tri.e1,i);
  49. const Vec3vf<K> e2 = broadcast<vfloat<K>>(tri.e2,i);
  50. pre.intersectEdgeK(valid_i,ray,p0,e1,e2,UVIdentity<K>(),IntersectKEpilogM<M,K,filter>(ray,context,tri.geomID(),tri.primID(),i));
  51. }
  52. }
  53. /*! Test for K rays if they are occluded by any of the M triangles. */
  54. static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const TriangleM<M>& tri)
  55. {
  56. vbool<K> valid0 = valid_i;
  57. for (size_t i=0; i<TriangleM<M>::max_size(); i++)
  58. {
  59. if (!tri.valid(i)) break;
  60. STAT3(shadow.trav_prims,1,popcnt(valid0),K);
  61. const Vec3vf<K> p0 = broadcast<vfloat<K>>(tri.v0,i);
  62. const Vec3vf<K> e1 = broadcast<vfloat<K>>(tri.e1,i);
  63. const Vec3vf<K> e2 = broadcast<vfloat<K>>(tri.e2,i);
  64. pre.intersectEdgeK(valid0,ray,p0,e1,e2,UVIdentity<K>(),OccludedKEpilogM<M,K,filter>(valid0,ray,context,tri.geomID(),tri.primID(),i));
  65. if (none(valid0)) break;
  66. }
  67. return !valid0;
  68. }
  69. /*! Intersect a ray with M triangles and updates the hit. */
  70. static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const TriangleM<M>& tri)
  71. {
  72. STAT3(normal.trav_prims,1,1,1);
  73. pre.intersectEdge(ray,k,tri.v0,tri.e1,tri.e2,UVIdentity<M>(),Intersect1KEpilogM<M,K,filter>(ray,k,context,tri.geomID(),tri.primID()));
  74. }
  75. /*! Test if the ray is occluded by one of the M triangles. */
  76. static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const TriangleM<M>& tri)
  77. {
  78. STAT3(shadow.trav_prims,1,1,1);
  79. return pre.intersectEdge(ray,k,tri.v0,tri.e1,tri.e2,UVIdentity<M>(),Occluded1KEpilogM<M,K,filter>(ray,k,context,tri.geomID(),tri.primID()));
  80. }
  81. };
  82. }
  83. }