Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
aabb_sse.h
Go to the documentation of this file.
1 /*
2  This file is part of Mitsuba, a physically based rendering system.
3 
4  Copyright (c) 2007-2014 by Wenzel Jakob and others.
5 
6  Mitsuba is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Mitsuba is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #if !defined(__MITSUBA_CORE_AABB_SSE_H_)
21 #define __MITSUBA_CORE_AABB_SSE_H_
22 
23 #include <mitsuba/core/platform.h>
24 #include <mitsuba/core/sse.h>
25 #include <mitsuba/core/aabb.h>
26 #include <mitsuba/core/ray_sse.h>
27 
29 
30 /**
31  * NaN-aware slab test using SSE by Thierry Berger-Perrin (Intersects
32  * against 4 rays simultaneously). Returns false if none of the rays
33  * intersect.
34  */
35 FINLINE bool AABB::rayIntersectPacket(const RayPacket4 &ray,
36  RayInterval4 &interval) const {
37  const __m128
38  xl1 = _mm_mul_ps(ray.dRcp[0].ps,
39  _mm_sub_ps(_mm_set1_ps(min.x), ray.o[0].ps)),
40  xl2 = _mm_mul_ps(ray.dRcp[0].ps,
41  _mm_sub_ps(_mm_set1_ps(max.x), ray.o[0].ps)),
42  xl1a = _mm_min_ps(xl1, SSEConstants::p_inf.ps),
43  xl2a = _mm_min_ps(xl2, SSEConstants::p_inf.ps),
44  xl1b = _mm_max_ps(xl1, SSEConstants::n_inf.ps),
45  xl2b = _mm_max_ps(xl2, SSEConstants::n_inf.ps);
46 
47  __m128
48  lmax = _mm_max_ps(xl1a, xl2a),
49  lmin = _mm_min_ps(xl1b, xl2b);
50 
51  const __m128
52  yl1 = _mm_mul_ps(ray.dRcp[1].ps,
53  _mm_sub_ps(_mm_set1_ps(min.y), ray.o[1].ps)),
54  yl2 = _mm_mul_ps(ray.dRcp[1].ps,
55  _mm_sub_ps(_mm_set1_ps(max.y), ray.o[1].ps)),
56  yl1a = _mm_min_ps(yl1, SSEConstants::p_inf.ps),
57  yl2a = _mm_min_ps(yl2, SSEConstants::p_inf.ps),
58  yl1b = _mm_max_ps(yl1, SSEConstants::n_inf.ps),
59  yl2b = _mm_max_ps(yl2, SSEConstants::n_inf.ps);
60 
61  lmax = _mm_min_ps(_mm_max_ps(yl1a,yl2a), lmax);
62  lmin = _mm_max_ps(_mm_min_ps(yl1b,yl2b), lmin);
63 
64  const __m128
65  zl1 = _mm_mul_ps(ray.dRcp[2].ps,
66  _mm_sub_ps(_mm_set1_ps(min.z), ray.o[2].ps)),
67  zl2 = _mm_mul_ps(ray.dRcp[2].ps,
68  _mm_sub_ps(_mm_set1_ps(max.z), ray.o[2].ps)),
69  zl1a = _mm_min_ps(zl1, SSEConstants::p_inf.ps),
70  zl2a = _mm_min_ps(zl2, SSEConstants::p_inf.ps),
71  zl1b = _mm_max_ps(zl1, SSEConstants::n_inf.ps),
72  zl2b = _mm_max_ps(zl2, SSEConstants::n_inf.ps);
73 
74  lmax = _mm_min_ps(_mm_max_ps(zl1a,zl2a), lmax);
75  lmin = _mm_max_ps(_mm_min_ps(zl1b,zl2b), lmin);
76 
77  const bool hasIntersection = _mm_movemask_ps(
78  _mm_and_ps(
79  _mm_cmpge_ps(lmax, _mm_setzero_ps()),
80  _mm_cmple_ps(lmin, lmax))) != 0;
81 
82  interval.mint.ps = lmin;
83  interval.maxt.ps = lmax;
84  return hasIntersection;
85 }
86 
88 
89 #endif /* __MITSUBA_CORE_AABB_SSE_H_ */
FINLINE __m128 rayIntersectPacket(const TriAccel &tri, const RayPacket4 &packet, __m128 mint, __m128 maxt, __m128 inactive, Intersection4 &its)
Definition: triaccel_sse.h:27
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
#define MTS_NAMESPACE_END
Definition: platform.h:138