1// Copyright 2009-2021 Intel Corporation
2// SPDX-License-Identifier: Apache-2.0
3
4#pragma once
5
6#include "../common/ray.h"
7
8namespace embree
9{
10 namespace isa
11 {
12 struct HalfPlane
13 {
14 const Vec3fa P; //!< plane origin
15 const Vec3fa N; //!< plane normal
16
17 __forceinline HalfPlane(const Vec3fa& P, const Vec3fa& N)
18 : P(P), N(N) {}
19
20 __forceinline BBox1f intersect(const Vec3fa& ray_org, const Vec3fa& ray_dir) const
21 {
22 Vec3fa O = Vec3fa(ray_org) - P;
23 Vec3fa D = Vec3fa(ray_dir);
24 float ON = dot(O,N);
25 float DN = dot(D,N);
26 bool eps = abs(DN) < min_rcp_input;
27 float t = -ON*rcp(DN);
28 float lower = select(eps || DN < 0.0f, float(neg_inf), t);
29 float upper = select(eps || DN > 0.0f, float(pos_inf), t);
30 return BBox1f(lower,upper);
31 }
32 };
33
34 template<int M>
35 struct HalfPlaneN
36 {
37 const Vec3vf<M> P; //!< plane origin
38 const Vec3vf<M> N; //!< plane normal
39
40 __forceinline HalfPlaneN(const Vec3vf<M>& P, const Vec3vf<M>& N)
41 : P(P), N(N) {}
42
43 __forceinline BBox<vfloat<M>> intersect(const Vec3fa& ray_org, const Vec3fa& ray_dir) const
44 {
45 Vec3vf<M> O = Vec3vf<M>((Vec3fa)ray_org) - P;
46 Vec3vf<M> D = Vec3vf<M>((Vec3fa)ray_dir);
47 vfloat<M> ON = dot(O,N);
48 vfloat<M> DN = dot(D,N);
49 vbool<M> eps = abs(DN) < min_rcp_input;
50 vfloat<M> t = -ON*rcp(DN);
51 vfloat<M> lower = select(eps | DN < 0.0f, vfloat<M>(neg_inf), t);
52 vfloat<M> upper = select(eps | DN > 0.0f, vfloat<M>(pos_inf), t);
53 return BBox<vfloat<M>>(lower,upper);
54 }
55 };
56 }
57}
58