hit.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "default.h"
  18. namespace embree
  19. {
  20. /* Hit structure for K hits */
  21. template<int K>
  22. struct HitK
  23. {
  24. /* Default construction does nothing */
  25. __forceinline HitK() {}
  26. /* Constructs a hit */
  27. __forceinline HitK(const vint<K>& instID, const vint<K>& geomID, const vint<K>& primID, const vfloat<K>& u, const vfloat<K>& v, const vfloat<K>& t, const Vec3<vfloat<K>>& Ng)
  28. : Ng(Ng), instID(instID), geomID(geomID), primID(primID), u(u), v(v), t(t) {}
  29. /* Returns the size of the hit */
  30. static __forceinline size_t size() { return K; }
  31. public:
  32. Vec3<vfloat<K>> Ng; // geometry normal
  33. vint<K> instID; // instance ID
  34. vint<K> geomID; // geometry ID
  35. vint<K> primID; // primitive ID
  36. vfloat<K> u; // barycentric u coordinate of hit
  37. vfloat<K> v; // barycentric v coordinate of hit
  38. vfloat<K> t; // hit distance
  39. };
  40. /* Specialization for a single hit */
  41. template<>
  42. struct HitK<1>
  43. {
  44. /* Default construction does nothing */
  45. __forceinline HitK() {}
  46. /* Constructs a hit */
  47. __forceinline HitK(int instID, int geomID, int primID, float u, float v, float t, const Vec3fa& Ng)
  48. : Ng(Ng.x,Ng.y,Ng.z), instID(instID), geomID(geomID), primID(primID), u(u), v(v), t(t) {}
  49. /* Returns the size of the hit */
  50. static __forceinline size_t size() { return 1; }
  51. public:
  52. Vec3<float> Ng; // geometry normal
  53. int instID; // instance ID
  54. int geomID; // geometry ID
  55. int primID; // primitive ID
  56. float u; // barycentric u coordinate of hit
  57. float v; // barycentric v coordinate of hit
  58. float t; // hit distance
  59. };
  60. /* Shortcuts */
  61. typedef HitK<1> Hit;
  62. typedef HitK<4> Hit4;
  63. typedef HitK<8> Hit8;
  64. typedef HitK<16> Hit16;
  65. /* Outputs hit to stream */
  66. template<int K>
  67. inline std::ostream& operator<<(std::ostream& cout, const HitK<K>& ray)
  68. {
  69. return cout << "{ " << std::endl
  70. << " instID = " << ray.instID << std::endl
  71. << " geomID = " << ray.geomID << std::endl
  72. << " primID = " << ray.primID << std::endl
  73. << " u = " << ray.u << std::endl
  74. << " v = " << ray.v << std::endl
  75. << " t = " << ray.v << std::endl
  76. << " Ng = " << ray.Ng
  77. << "}";
  78. }
  79. }