Skip to content

Commit 0448a2c

Browse files
author
kevyuu
committed
Change zero_fill to promote_affine
1 parent 6ada8fb commit 0448a2c

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,22 @@ matrix<T, 3, 3> rotation_mat(T angle, vector<T, 3> const& axis)
5252

5353
template <uint16_t NOut, uint16_t MOut, uint16_t NIn, uint16_t MIn, typename T>
5454
requires(NOut >= NIn && MOut >= MIn)
55-
matrix <T, NOut, MOut> zero_fill(const matrix<T, NIn, MIn> inMatrix)
55+
matrix <T, NOut, MOut> promote_affine(const matrix<T, NIn, MIn> inMatrix)
5656
{
5757
matrix<T, NOut, MOut> retval;
58-
for (auto row_i = 0u; row_i < NIn; row_i++)
58+
59+
using out_row_t = hlsl::vector<T, MOut>;
60+
auto expandVec = [](vector<T, MIn> inVec) -> vector<T, MOut>
61+
{
62+
if constexpr (MIn == MOut) return inVec;
63+
return vector<T, MOut>(inVec, vector<T, MOut - MIn>(0));
64+
};
65+
66+
for (auto row_i = 0u; row_i < NOut; row_i++)
5967
{
60-
for (auto col_i = 0u; col_i < MIn; col_i++)
61-
{
62-
retval[row_i][col_i] = inMatrix[row_i][col_i];
63-
}
68+
retval[row_i] = row_i < NIn ? expandVec(inMatrix[row_i]) : promote<out_row_t>(0.0f);
69+
if ((row_i >= NIn || row_i >= MIn) && row_i < MOut) retval[row_i][row_i] = T(1);
70+
6471
}
6572
return retval;
6673
}

src/nbl/asset/utils/CGeometryCreator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ core::smart_refctd_ptr<ICPUGeometryCollection> CGeometryCreator::createArrow(
683683
});
684684
const auto coneTransform = hlsl::math::linalg::rotation_mat(hlsl::numbers::pi<hlsl::float32_t> * -0.5f, hlsl::float32_t3(1.f, 0.f, 0.f));
685685
geometries->push_back({
686-
.transform = hlsl::math::linalg::zero_fill<3, 4>(coneTransform),
686+
.transform = hlsl::math::linalg::promote_affine<3, 4>(coneTransform),
687687
.geometry = cone
688688
});
689689
return collection;

0 commit comments

Comments
 (0)