4#include "MRPch/MRBindingMacros.h"
21#if defined(__x86_64__) || defined(_M_X64)
23struct RayOrigin<float>
25 MR_BIND_IGNORE __m128
p;
26 RayOrigin(
const Vector3f & ro ) {
p = _mm_set_ps( ro.x, ro.y, ro.z, 0 ); }
32inline bool rayBoxIntersect(
const Box3f& box,
const RayOrigin<float> & rayOrigin,
float & t0,
float & t1,
const IntersectionPrecomputes<float>& prec )
34 __m128 l = _mm_set_ps( box.min.x, box.min.y, box.min.z, t0 );
35 __m128 r = _mm_set_ps( box.max.x, box.max.y, box.max.z, t1 );
36 l = _mm_sub_ps( l, rayOrigin.p );
37 r = _mm_sub_ps( r, rayOrigin.p );
38 l = _mm_mul_ps( l, prec.invDir );
39 r = _mm_mul_ps( r, prec.invDir );
41 __m128 a = _mm_min_ps( l, r );
42 __m128 b = _mm_max_ps( l, r );
44 __m128 aa = _mm_movehl_ps( a, a );
45 aa = _mm_max_ps( aa, a );
46 __m128 aaa = _mm_shuffle_ps( aa, aa, 1 );
47 aaa = _mm_max_ss( aaa, aa );
48 t0 = _mm_cvtss_f32( aaa );
50 __m128 bb = _mm_movehl_ps( b, b );
51 bb = _mm_min_ps( bb, b );
52 __m128 bbb = _mm_shuffle_ps( bb, bb, 1 );
53 bbb = _mm_min_ss( bbb, bb );
54 t1 = _mm_cvtss_f32( bbb );
59 #pragma message("rayBoxIntersect: no hardware optimized instructions")
65 const Vector3i& sign = prec.
sign;
68 t1 = std::min( (box[sign.x].x - rayOrigin.p.x) * prec.
invDir.x, t1 );
69 t0 = std::max( (box[1 - sign.x].x - rayOrigin.p.x) * prec.
invDir.x, t0 );
72 t1 = std::min( (box[sign.y].y - rayOrigin.p.y) * prec.
invDir.y, t1 );
73 t0 = std::max( (box[1 - sign.y].y - rayOrigin.p.y) * prec.
invDir.y, t0 );
76 t1 = std::min( (box[sign.z].z - rayOrigin.p.z) * prec.
invDir.z, t1 );
77 t0 = std::max( (box[1 - sign.z].z - rayOrigin.p.z) * prec.
invDir.z, t0 );
81template <
typename T =
float>
Vector3i sign
stores signs of direction vector;
Definition MRIntersectionPrecomputes.h:127
Vector3< T > invDir
Definition MRIntersectionPrecomputes.h:119
bool rayBoxIntersect(const Box3< T > &box, const RayOrigin< T > &rayOrigin, T &t0, T &t1, const IntersectionPrecomputes< T > &prec)
Definition MRRayBoxIntersection.h:63
Definition MRCameraOrientationPlugin.h:8
Box given by its min- and max- corners.
Definition MRMesh/MRBox.h:25
Definition MRMesh/MRMeshFwd.h:374
Definition MRRayBoxIntersection.h:15
RayOrigin(const Vector3< T > &ro)
Definition MRRayBoxIntersection.h:17
Vector3< T > p
Definition MRRayBoxIntersection.h:16
Definition MRMesh/MRVector3.h:19