RavEngine
Loading...
Searching...
No Matches
GuBV4_AABBAABBSweepTest.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef GU_BV4_AABB_AABB_SWEEP_TEST_H
30#define GU_BV4_AABB_AABB_SWEEP_TEST_H
31
32#ifndef GU_BV4_USE_SLABS
33 PX_FORCE_INLINE PxIntBool BV4_SegmentAABBOverlap(const PxVec3& center, const PxVec3& extents, const PxVec3& extents2, const RayParams* PX_RESTRICT params)
34 {
35 const Vec4V fdirV = V4LoadA_Safe(&params->mFDir_PaddedAligned.x);
36 const Vec4V extentsV = V4Add(V4LoadU(&extents.x), V4LoadU(&extents2.x));
37 const Vec4V DV = V4Sub(V4LoadA_Safe(&params->mData2_PaddedAligned.x), V4LoadU(&center.x));
38 const Vec4V absDV = V4Abs(DV);
39 const BoolV resDV = V4IsGrtr(absDV, V4Add(extentsV, fdirV));
40 const PxU32 test = BGetBitMask(resDV);
41 if(test&7)
42 return 0;
43
44 if(1)
45 {
46 const Vec4V dataZYX_V = V4LoadA_Safe(&params->mData_PaddedAligned.x);
47 const Vec4V dataXZY_V = V4Perm<1, 2, 0, 3>(dataZYX_V);
48 const Vec4V DXZY_V = V4Perm<1, 2, 0, 3>(DV);
49 const Vec4V fV = V4Sub(V4Mul(dataZYX_V, DXZY_V), V4Mul(dataXZY_V, DV));
50
51 const Vec4V fdirZYX_V = V4LoadA_Safe(&params->mFDir_PaddedAligned.x);
52 const Vec4V fdirXZY_V = V4Perm<1, 2, 0, 3>(fdirZYX_V);
53 const Vec4V extentsXZY_V = V4Perm<1, 2, 0, 3>(extentsV);
54 // PT: TODO: use V4MulAdd here (TA34704)
55 const Vec4V fg = V4Add(V4Mul(extentsV, fdirXZY_V), V4Mul(extentsXZY_V, fdirZYX_V));
56
57 const Vec4V absfV = V4Abs(fV);
58 const BoolV resAbsfV = V4IsGrtr(absfV, fg);
59 const PxU32 test2 = BGetBitMask(resAbsfV);
60 if(test2&7)
61 return 0;
62 return 1;
63 }
64 }
65
66#ifdef GU_BV4_QUANTIZED_TREE
67 template<class T>
68 PX_FORCE_INLINE PxIntBool BV4_SegmentAABBOverlap(const T* PX_RESTRICT node, const PxVec3& extents2, const RayParams* PX_RESTRICT params)
69 {
70 const VecI32V testV = I4LoadA((PxI32*)node->mAABB.mData);
71 const VecI32V qextentsV = VecI32V_And(testV, I4Load(0x0000ffff));
72 const VecI32V qcenterV = VecI32V_RightShift(testV, 16);
73 const Vec4V centerV0 = V4Mul(Vec4V_From_VecI32V(qcenterV), V4LoadA_Safe(&params->mCenterOrMinCoeff_PaddedAligned.x));
74 const Vec4V extentsV0 = V4Mul(Vec4V_From_VecI32V(qextentsV), V4LoadA_Safe(&params->mExtentsOrMaxCoeff_PaddedAligned.x));
75
76 const Vec4V fdirV = V4LoadA_Safe(&params->mFDir_PaddedAligned.x);
77 const Vec4V extentsV = V4Add(extentsV0, V4LoadU(&extents2.x));
78 const Vec4V DV = V4Sub(V4LoadA_Safe(&params->mData2_PaddedAligned.x), centerV0);
79 const Vec4V absDV = V4Abs(DV);
80 const BoolV res = V4IsGrtr(absDV, V4Add(extentsV, fdirV));
81 const PxU32 test = BGetBitMask(res);
82 if(test&7)
83 return 0;
84
85 if(1)
86 {
87 const Vec4V dataZYX_V = V4LoadA_Safe(&params->mData_PaddedAligned.x);
88 const Vec4V dataXZY_V = V4Perm<1, 2, 0, 3>(dataZYX_V);
89 const Vec4V DXZY_V = V4Perm<1, 2, 0, 3>(DV);
90
91 const Vec4V fV = V4Sub(V4Mul(dataZYX_V, DXZY_V), V4Mul(dataXZY_V, DV));
92
93 const Vec4V fdirZYX_V = V4LoadA_Safe(&params->mFDir_PaddedAligned.x);
94 const Vec4V fdirXZY_V = V4Perm<1, 2, 0, 3>(fdirZYX_V);
95 const Vec4V extentsXZY_V = V4Perm<1, 2, 0, 3>(extentsV);
96 // PT: TODO: use V4MulAdd here (TA34704)
97 const Vec4V fg = V4Add(V4Mul(extentsV, fdirXZY_V), V4Mul(extentsXZY_V, fdirZYX_V));
98
99 const Vec4V absfV = V4Abs(fV);
100 const BoolV res2 = V4IsGrtr(absfV, fg);
101 const PxU32 test2 = BGetBitMask(res2);
102 if(test2&7)
103 return 0;
104 return 1;
105 }
106 }
107#endif
108#endif
109
110#endif // GU_BV4_AABB_AABB_SWEEP_TEST_H
#define PX_RESTRICT
Definition PxPreprocessor.h:355
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Definition GuBV4_BoxSweep_Internal.h:42