object_intersector.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "object.h"
  5. #include "../common/ray.h"
  6. namespace embree
  7. {
  8. namespace isa
  9. {
  10. template<bool mblur>
  11. struct ObjectIntersector1
  12. {
  13. typedef Object Primitive;
  14. static const bool validIntersectorK = false;
  15. struct Precalculations {
  16. __forceinline Precalculations() {}
  17. __forceinline Precalculations (const Ray& ray, const void *ptr) {}
  18. };
  19. static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim)
  20. {
  21. AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID());
  22. /* perform ray mask test */
  23. #if defined(EMBREE_RAY_MASK)
  24. if ((ray.mask & accel->mask) == 0)
  25. return;
  26. #endif
  27. accel->intersect(ray,prim.geomID(),prim.primID(),context);
  28. }
  29. static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim)
  30. {
  31. AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID());
  32. /* perform ray mask test */
  33. #if defined(EMBREE_RAY_MASK)
  34. if ((ray.mask & accel->mask) == 0)
  35. return false;
  36. #endif
  37. accel->occluded(ray,prim.geomID(),prim.primID(),context);
  38. return ray.tfar < 0.0f;
  39. }
  40. static __forceinline bool pointQuery(PointQuery* query, PointQueryContext* context, const Primitive& prim)
  41. {
  42. AccelSet* accel = (AccelSet*)context->scene->get(prim.geomID());
  43. context->geomID = prim.geomID();
  44. context->primID = prim.primID();
  45. return accel->pointQuery(query, context);
  46. }
  47. template<int K>
  48. static __forceinline void intersectK(const vbool<K>& valid, /* PrecalculationsK& pre, */ RayHitK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, size_t& lazy_node)
  49. {
  50. assert(false);
  51. }
  52. template<int K>
  53. static __forceinline vbool<K> occludedK(const vbool<K>& valid, /* PrecalculationsK& pre, */ RayK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, size_t& lazy_node)
  54. {
  55. assert(false);
  56. return valid;
  57. }
  58. };
  59. template<int K, bool mblur>
  60. struct ObjectIntersectorK
  61. {
  62. typedef Object Primitive;
  63. struct Precalculations {
  64. __forceinline Precalculations (const vbool<K>& valid, const RayK<K>& ray) {}
  65. };
  66. static __forceinline void intersect(const vbool<K>& valid_i, const Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const Primitive& prim)
  67. {
  68. vbool<K> valid = valid_i;
  69. AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID());
  70. /* perform ray mask test */
  71. #if defined(EMBREE_RAY_MASK)
  72. valid &= (ray.mask & accel->mask) != 0;
  73. if (none(valid)) return;
  74. #endif
  75. accel->intersect(valid,ray,prim.geomID(),prim.primID(),context);
  76. }
  77. static __forceinline vbool<K> occluded(const vbool<K>& valid_i, const Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive& prim)
  78. {
  79. vbool<K> valid = valid_i;
  80. AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID());
  81. /* perform ray mask test */
  82. #if defined(EMBREE_RAY_MASK)
  83. valid &= (ray.mask & accel->mask) != 0;
  84. if (none(valid)) return false;
  85. #endif
  86. accel->occluded(valid,ray,prim.geomID(),prim.primID(),context);
  87. return ray.tfar < 0.0f;
  88. }
  89. static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive& prim) {
  90. intersect(vbool<K>(1<<int(k)),pre,ray,context,prim);
  91. }
  92. static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive& prim) {
  93. occluded(vbool<K>(1<<int(k)),pre,ray,context,prim);
  94. return ray.tfar[k] < 0.0f;
  95. }
  96. };
  97. typedef ObjectIntersectorK<4,false> ObjectIntersector4;
  98. typedef ObjectIntersectorK<8,false> ObjectIntersector8;
  99. typedef ObjectIntersectorK<16,false> ObjectIntersector16;
  100. typedef ObjectIntersectorK<4,true> ObjectIntersector4MB;
  101. typedef ObjectIntersectorK<8,true> ObjectIntersector8MB;
  102. typedef ObjectIntersectorK<16,true> ObjectIntersector16MB;
  103. }
  104. }