instance_intersector.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #include "instance_intersector.h"
  17. #include "../common/scene.h"
  18. namespace embree
  19. {
  20. namespace isa
  21. {
  22. template<int K>
  23. __forceinline void intersectObject(vint<K>* valid, Scene* object, IntersectContext* context, RayK<K>& ray);
  24. template<int K>
  25. __forceinline void occludedObject(vint<K>* valid, Scene* object, IntersectContext* context, RayK<K>& ray);
  26. #if defined (__SSE__)
  27. template<> __forceinline void intersectObject<4>(vint4* valid, Scene* object, IntersectContext* context, Ray4& ray) { object->intersect4(valid,(RTCRay4&)ray,context); }
  28. template<> __forceinline void occludedObject <4>(vint4* valid, Scene* object, IntersectContext* context, Ray4& ray) { object->occluded4 (valid,(RTCRay4&)ray,context); }
  29. #endif
  30. #if defined (__AVX__)
  31. template<> __forceinline void intersectObject<8>(vint8* valid, Scene* object, IntersectContext* context, Ray8& ray) { object->intersect8(valid,(RTCRay8&)ray,context); }
  32. template<> __forceinline void occludedObject <8>(vint8* valid, Scene* object, IntersectContext* context, Ray8& ray) { object->occluded8 (valid,(RTCRay8&)ray,context); }
  33. #endif
  34. #if defined (__AVX512F__)
  35. template<> __forceinline void intersectObject<16>(vint16* valid, Scene* object, IntersectContext* context, Ray16& ray) { object->intersect16(valid,(RTCRay16&)ray,context); }
  36. template<> __forceinline void occludedObject <16>(vint16* valid, Scene* object, IntersectContext* context, Ray16& ray) { object->occluded16 (valid,(RTCRay16&)ray,context); }
  37. #endif
  38. template<int K>
  39. void FastInstanceIntersectorK<K>::intersect(vint<K>* validi, const Instance* instance, RayK<K>& ray, size_t item)
  40. {
  41. typedef Vec3<vfloat<K>> Vec3vfK;
  42. typedef AffineSpaceT<LinearSpace3<Vec3vfK>> AffineSpace3vfK;
  43. AffineSpace3vfK world2local;
  44. const vbool<K> valid = *validi == vint<K>(-1);
  45. if (likely(instance->numTimeSteps == 1)) world2local = instance->getWorld2Local();
  46. else world2local = instance->getWorld2Local<K>(valid,ray.time);
  47. const Vec3vfK ray_org = ray.org;
  48. const Vec3vfK ray_dir = ray.dir;
  49. const vint<K> ray_geomID = ray.geomID;
  50. const vint<K> ray_instID = ray.instID;
  51. ray.org = xfmPoint (world2local,ray_org);
  52. ray.dir = xfmVector(world2local,ray_dir);
  53. ray.geomID = RTC_INVALID_GEOMETRY_ID;
  54. ray.instID = instance->id;
  55. IntersectContext context(instance->object,nullptr);
  56. intersectObject(validi,instance->object,&context,ray);
  57. ray.org = ray_org;
  58. ray.dir = ray_dir;
  59. vbool<K> nohit = ray.geomID == vint<K>(RTC_INVALID_GEOMETRY_ID);
  60. ray.geomID = select(nohit,ray_geomID,ray.geomID);
  61. ray.instID = select(nohit,ray_instID,ray.instID);
  62. }
  63. template<int K>
  64. void FastInstanceIntersectorK<K>::occluded(vint<K>* validi, const Instance* instance, RayK<K>& ray, size_t item)
  65. {
  66. typedef Vec3<vfloat<K>> Vec3vfK;
  67. typedef AffineSpaceT<LinearSpace3<Vec3vfK>> AffineSpace3vfK;
  68. AffineSpace3vfK world2local;
  69. const vbool<K> valid = *validi == vint<K>(-1);
  70. if (likely(instance->numTimeSteps == 1)) world2local = instance->getWorld2Local();
  71. else world2local = instance->getWorld2Local<K>(valid,ray.time);
  72. const Vec3vfK ray_org = ray.org;
  73. const Vec3vfK ray_dir = ray.dir;
  74. ray.org = xfmPoint (world2local,ray_org);
  75. ray.dir = xfmVector(world2local,ray_dir);
  76. ray.instID = instance->id;
  77. IntersectContext context(instance->object,nullptr);
  78. occludedObject(validi,instance->object,&context,ray);
  79. ray.org = ray_org;
  80. ray.dir = ray_dir;
  81. }
  82. DEFINE_SET_INTERSECTOR4(InstanceIntersector4,FastInstanceIntersector4);
  83. #if defined(__AVX__)
  84. DEFINE_SET_INTERSECTOR8(InstanceIntersector8,FastInstanceIntersector8);
  85. #endif
  86. #if defined(__AVX512F__)
  87. DEFINE_SET_INTERSECTOR16(InstanceIntersector16,FastInstanceIntersector16);
  88. #endif
  89. }
  90. }