|
4 | 4 | #ifndef _NBL_BUILTIN_HLSL_SHAPES_AABB_INCLUDED_
|
5 | 5 | #define _NBL_BUILTIN_HLSL_SHAPES_AABB_INCLUDED_
|
6 | 6 |
|
| 7 | + |
7 | 8 | #include "nbl/builtin/hlsl/concepts.hlsl"
|
8 | 9 | #include "nbl/builtin/hlsl/limits.hlsl"
|
9 | 10 | #include "nbl/builtin/hlsl/shapes/util.hlsl"
|
10 | 11 |
|
| 12 | + |
11 | 13 | namespace nbl
|
12 | 14 | {
|
13 | 15 | namespace hlsl
|
@@ -88,6 +90,48 @@ struct union_helper<AABB<D,Scalar>>
|
88 | 90 | return retval;
|
89 | 91 | }
|
90 | 92 | };
|
| 93 | +#define NBL_UNROLL [[unroll]] |
| 94 | +// without a translation component |
| 95 | +template<int16_t D, typename Scalar> |
| 96 | +struct transform_helper<AABB<D,Scalar>,matrix<Scalar,D,D> > |
| 97 | +{ |
| 98 | + using type = AABB<D,Scalar>; |
| 99 | + using matrix_t = matrix<Scalar,D,D>; |
| 100 | + using vector_t = vector<Scalar,D>; |
| 101 | + |
| 102 | + static inline type __call(NBL_CONST_REF_ARG(matrix_t) lhs, NBL_CONST_REF_ARG(type) rhs) |
| 103 | + { |
| 104 | + // take each column and tweak to get minimum and max |
| 105 | + const matrix_t M_T = hlsl::transpose(lhs); |
| 106 | + vector<bool,D> signM_T[D]; |
| 107 | + NBL_UNROLL for (int16_t j=0; j<D; j++) |
| 108 | + NBL_UNROLL for (int16_t i=0; i<D; i++) |
| 109 | + signM_T[j][i] = M_T[j][i]<Scalar(0); |
| 110 | + |
| 111 | + type retval; |
| 112 | + retval.minVx = M_T[0] * hlsl::mix<vector_t>(rhs.minVx.xxx, rhs.maxVx.xxx, signM_T[0]) + M_T[1] * hlsl::mix<vector_t>(rhs.minVx.yyy, rhs.maxVx.yyy, signM_T[1]) + M_T[2] * hlsl::mix<vector_t>(rhs.minVx.zzz, rhs.maxVx.zzz, signM_T[2]); |
| 113 | + retval.maxVx = M_T[0] * hlsl::mix<vector_t>(rhs.maxVx.xxx, rhs.minVx.xxx, signM_T[0]) + M_T[1] * hlsl::mix<vector_t>(rhs.maxVx.yyy, rhs.minVx.yyy, signM_T[1]) + M_T[2] * hlsl::mix<vector_t>(rhs.maxVx.zzz, rhs.minVx.zzz, signM_T[2]); |
| 114 | + return retval; |
| 115 | + } |
| 116 | +}; |
| 117 | +// affine weird matrix |
| 118 | +template<int16_t D, typename Scalar> |
| 119 | +struct transform_helper<AABB<D,Scalar>,matrix<Scalar,D,D+1> > |
| 120 | +{ |
| 121 | + using type = AABB<D,Scalar>; |
| 122 | + using matrix_t = matrix<Scalar,D,D+1>; |
| 123 | + using sub_matrix_t = matrix<Scalar,D,D>; |
| 124 | + |
| 125 | + static inline type __call(NBL_CONST_REF_ARG(matrix_t) lhs, NBL_CONST_REF_ARG(type) rhs) |
| 126 | + { |
| 127 | + const vector<Scalar,D> translation = hlsl::transpose(lhs)[D]; |
| 128 | + type retval = transform_helper<type,sub_matrix_t>::__call(sub_matrix_t(lhs),rhs); |
| 129 | +// retval.minVx += translation; |
| 130 | +// retval.maxVx += translation; |
| 131 | + return retval; |
| 132 | + } |
| 133 | +}; |
| 134 | +#undef NBL_UNROLL |
91 | 135 | }
|
92 | 136 | }
|
93 | 137 |
|
|
0 commit comments