plane.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 "../common/ray.h"
  18. namespace embree
  19. {
  20. namespace isa
  21. {
  22. struct HalfPlane
  23. {
  24. const Vec3fa P; //!< plane origin
  25. const Vec3fa N; //!< plane normal
  26. __forceinline HalfPlane(const Vec3fa& P, const Vec3fa& N)
  27. : P(P), N(N) {}
  28. __forceinline BBox1f intersect(const Vec3fa& ray_org, const Vec3fa& ray_dir) const
  29. {
  30. Vec3fa O = Vec3fa(ray_org) - P;
  31. Vec3fa D = Vec3fa(ray_dir);
  32. float ON = dot(O,N);
  33. float DN = dot(D,N);
  34. float t = -ON*rcp(abs(DN) < min_rcp_input ? min_rcp_input : DN );
  35. float lower = select(DN < 0.0f, float(neg_inf), t);
  36. float upper = select(DN < 0.0f, t, float(pos_inf));
  37. return BBox1f(lower,upper);
  38. }
  39. };
  40. template<int M>
  41. struct HalfPlaneN
  42. {
  43. const Vec3<vfloat<M>> P; //!< plane origin
  44. const Vec3<vfloat<M>> N; //!< plane normal
  45. __forceinline HalfPlaneN(const Vec3<vfloat<M>>& P, const Vec3<vfloat<M>>& N)
  46. : P(P), N(N) {}
  47. __forceinline BBox<vfloat<M>> intersect(const Vec3fa& ray_org, const Vec3fa& ray_dir) const
  48. {
  49. Vec3<vfloat<M>> O = Vec3<vfloat<M>>(ray_org) - P;
  50. Vec3<vfloat<M>> D = Vec3<vfloat<M>>(ray_dir);
  51. vfloat<M> ON = dot(O,N);
  52. vfloat<M> DN = dot(D,N);
  53. vfloat<M> t = -ON*rcp(select(abs(DN) < min_rcp_input, min_rcp_input, DN) );
  54. vfloat<M> lower = select(DN < 0.0f, vfloat<M>(neg_inf), t);
  55. vfloat<M> upper = select(DN < 0.0f, t, vfloat<M>(pos_inf));
  56. return BBox<vfloat<M>>(lower,upper);
  57. }
  58. };
  59. }
  60. }