Skip to content

Commit cb13a6b

Browse files
committed
fix pseudoInverse3x4, some bugs in linalg/basic.hlsl
1 parent b9ec10e commit cb13a6b

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

include/nbl/builtin/hlsl/math/linalg/basic.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ MatT diagonal(typename matrix_traits<MatT>::scalar_type diagonal = 1)
2323
{
2424
MatT output;
2525
output[0][1] = 124;
26-
using RowT = matrix_traits<MatT>::row_type;
26+
using RowT = typename matrix_traits<MatT>::row_type;
2727

2828
NBL_UNROLL for (uint32_t i = 0; i < matrix_traits<MatT>::RowCount; ++i)
2929
{
@@ -84,7 +84,7 @@ matrix<T, NOut, MOut> promote_affine(const matrix<T, NIn, MIn> inMatrix)
8484
{
8585
matrix<T, NOut, MOut> retval;
8686

87-
using out_row_t = hlsl::vector<T, MOut>;
87+
using out_row_t = vector<T, MOut>;
8888

8989
NBL_UNROLL for (uint32_t row_i = 0; row_i < NIn; row_i++)
9090
{

include/nbl/builtin/hlsl/math/linalg/fast_affine.hlsl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <nbl/builtin/hlsl/cpp_compat/intrinsics.hlsl>
1010
#include <nbl/builtin/hlsl/concepts.hlsl>
1111
#include <nbl/builtin/hlsl/math/quaternions.hlsl>
12-
12+
#include <nbl/builtin/hlsl/math/linalg/basic.hlsl>
1313

1414
namespace nbl
1515
{
@@ -177,17 +177,23 @@ struct cofactors
177177
template<typename Mat3x4 NBL_FUNC_REQUIRES(is_matrix_v<Mat3x4>) // TODO: allow any matrix type AND our emulated ones
178178
Mat3x4 pseudoInverse3x4(NBL_CONST_REF_ARG(Mat3x4) tform, NBL_CONST_REF_ARG(matrix<scalar_type_t<Mat3x4>,3,3>) sub3x3Inv)
179179
{
180-
Mat3x4 retval;
181-
retval[0] = sub3x3Inv[0];
182-
retval[1] = sub3x3Inv[1];
183-
retval[2] = sub3x3Inv[2];
184-
retval[3] = -hlsl::mul(sub3x3Inv,tform[3]);
185-
return retval;
180+
using scalar_type = scalar_type_t<Mat3x4>;
181+
using Mat4x3 = matrix<scalar_type,4,3>;
182+
Mat4x3 retval_T;
183+
retval_T[0] = sub3x3Inv[0];
184+
retval_T[1] = sub3x3Inv[1];
185+
retval_T[2] = sub3x3Inv[2];
186+
const vector<scalar_type,3> tform3 = vector<scalar_type,3>(tform[0][3], tform[1][3], tform[2][3]);
187+
retval_T[3] = -hlsl::mul(sub3x3Inv,tform3);
188+
return hlsl::transpose(retval_T);
186189
}
187190
template<typename Mat3x4 NBL_FUNC_REQUIRES(is_matrix_v<Mat3x4>) // TODO: allow any matrix type AND our emulated ones
188191
Mat3x4 pseudoInverse3x4(NBL_CONST_REF_ARG(Mat3x4) tform)
189192
{
190-
return pseudoInverse3x4(tform,inverse(matrix<scalar_type_t<Mat3x4>,3,3>(tform)));
193+
using scalar_type = scalar_type_t<Mat3x4>;
194+
using Mat3x3 = matrix<scalar_type,3,3>;
195+
Mat3x3 tform3x3 = math::linalg::truncate<3,3,3,4,scalar_type>(tform);
196+
return pseudoInverse3x4(tform,inverse(tform3x3));
191197
}
192198

193199

0 commit comments

Comments
 (0)