- Notifications
You must be signed in to change notification settings - Fork67
Remove core::matrixSIMD#950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
include/ICameraSceneNode.h Outdated
| #include<vectorSIMD.h> | ||
| #include<nbl/builtin/hlsl/cpp_compat/matrix.hlsl> | ||
| #include"ISceneNode.h" | ||
| #include"matrixutil.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
no need to touch this file, its dead code
include/nabla.h Outdated
| #include"line3d.h" | ||
| #include"matrix4SIMD.h" | ||
| #include"position2d.h" | ||
| #include"quaternion.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
merge#960 into your branch and nuke thequaternion.h as well
| core::matrix3x4SIMDtransform =core::matrix3x4SIMD(); | ||
| hlsl::float32_t3x4transform =hlsl::float32_t3x4(); | ||
| Instance<blas_ref_t> base = {}; | ||
| }; | ||
| template<typenameblas_ref_t> | ||
| structMatrixMotionInstancefinal | ||
| { | ||
| core::matrix3x4SIMD transform[2] = {core::matrix3x4SIMD(),core::matrix3x4SIMD()}; | ||
| hlsl::float32_t3x4 transform[2] = {hlsl::float32_t3x4(),hlsl::float32_t3x4()}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
did you test the acceleration structure examples ? 67 and 71 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
no, need to fix them since they still use core::matrix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
example 67 works no problem but example 71 fails to compile the shader on master, not touching it untill it's fixed
| #ifndef _NBL_BUILTIN_HLSL_CAMERA_VIEW_MATRIX_INCLUDED_ | ||
| #define _NBL_BUILTIN_HLSL_CAMERA_VIEW_MATRIX_INCLUDED_ | ||
| #include <nbl/builtin/hlsl/cpp_compat.hlsl> | ||
| namespace nbl | ||
| { | ||
| namespace hlsl | ||
| { | ||
| // /Arek: glm:: for normalize till dot product is fixed (ambiguity with glm namespace + linker issues) | ||
| template<typename T> | ||
| inlinematrix<T,3,4>buildCameraLookAtMatrixLH( | ||
| constvector<T,3>& position, | ||
| constvector<T,3>& target, | ||
| constvector<T,3>& upVector) | ||
| { | ||
| constvector<T,3> zaxis = hlsl::normalize(target - position); | ||
| constvector<T,3> xaxis = hlsl::normalize(hlsl::cross(upVector, zaxis)); | ||
| constvector<T,3> yaxis = hlsl::cross(zaxis, xaxis); | ||
| matrix<T,3,4> r; | ||
| r[0] =vector<T,4>(xaxis, -hlsl::dot(xaxis, position)); | ||
| r[1] =vector<T,4>(yaxis, -hlsl::dot(yaxis, position)); | ||
| r[2] =vector<T,4>(zaxis, -hlsl::dot(zaxis, position)); | ||
| return r; | ||
| } | ||
| template<typename T> | ||
| inlinematrix<T,3,4>buildCameraLookAtMatrixRH( | ||
| constvector<T,3>& position, | ||
| constvector<T,3>& target, | ||
| constvector<T,3>& upVector) | ||
| { | ||
| constvector<T,3> zaxis = hlsl::normalize(position - target); | ||
| constvector<T,3> xaxis = hlsl::normalize(hlsl::cross(upVector, zaxis)); | ||
| constvector<T,3> yaxis = hlsl::cross(zaxis, xaxis); | ||
| matrix<T,3,4> r; | ||
| r[0] =vector<T,4>(xaxis, -hlsl::dot(xaxis, position)); | ||
| r[1] =vector<T,4>(yaxis, -hlsl::dot(yaxis, position)); | ||
| r[2] =vector<T,4>(zaxis, -hlsl::dot(zaxis, position)); | ||
| return r; | ||
| } | ||
| } | ||
| } | ||
| #endif No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
and dropbuildCamera just call tehemlhLookAt andrhLookAt
| #ifndef _NBL_BUILTIN_HLSL_CPP_COMPAT_UNROLL_INCLUDED_ | ||
| #define _NBL_BUILTIN_HLSL_CPP_COMPAT_UNROLL_INCLUDED_ | ||
| #ifdef __HLSL_VERSION | ||
| #define NBL_UNROLL [unroll] | ||
| #defineNBL_UNROLL_LIMITED(LIMIT) [unroll(LIMIT)] | ||
| #else | ||
| #define NBL_UNROLL// can't be bothered / TODO | ||
| #defineNBL_UNROLL_LIMITED(LIMIT) | ||
| #endif | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
its already in
| #defineNBL_UNROLL [[unroll]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
can add the LIMITED there
| // Copyright (C) 2019 - DevSH Graphics Programming Sp. z O.O. | ||
| // This file is part of the "Nabla Engine" and was originally part of the "Irrlicht Engine" | ||
| // For conditions of distribution and use, see copyright notice in nabla.h | ||
| // See the original file in irrlicht source for authors | ||
| #ifndef _NBL_BUILTIN_HLSL_MATH_QUATERNION_INCLUDED_ | ||
| #define _NBL_BUILTIN_HLSL_MATH_QUATERNION_INCLUDED_ | ||
| #include <nbl/builtin/hlsl/cpp_compat.hlsl> | ||
| namespace nbl | ||
| { | ||
| namespace hlsl | ||
| { | ||
| //! Quaternion class for representing rotations. | ||
| /** It provides cheap combinations and avoids gimbal locks. | ||
| Also useful for interpolations. */ | ||
| template<typename float_t> | ||
| struct quaternion | ||
| { | ||
| // i*data[0] + j*data[1] + k*data[2] + data[3] | ||
| using vec_t =vector<float_t,4>; | ||
| vector<float_t,4> data; | ||
| //! creates identity quaternion | ||
| staticinline quaternioncreate() | ||
| { | ||
| quaternion q; | ||
| q.data =vector<float_t,4>(0.0f,0.0f,0.0f,1.0f); | ||
| return q; | ||
| } | ||
| staticinline quaternioncreate(float_t x, float_t y, float_t z, float_t w) | ||
| { | ||
| quaternion q; | ||
| q.data =vector<float_t,4>(x, y, z, w); | ||
| return q; | ||
| } | ||
| staticinline quaternioncreate(NBL_CONST_REF_ARG(quaternion) other) | ||
| { | ||
| return other; | ||
| } | ||
| staticinline quaternioncreate(float_t pitch, float_t yaw, float_t roll) | ||
| { | ||
| constfloat rollDiv2 = roll *0.5f; | ||
| constfloat sr =sinf(rollDiv2); | ||
| constfloat cr =cosf(rollDiv2); | ||
| constfloat pitchDiv2 = pitch *0.5f; | ||
| constfloat sp =sinf(pitchDiv2); | ||
| constfloat cp =cosf(pitchDiv2); | ||
| constfloat yawDiv2 = yaw *0.5f; | ||
| constfloat sy =sinf(yawDiv2); | ||
| constfloat cy =cosf(yawDiv2); | ||
| quaternion<float_t> output; | ||
| output.data[0] = cr * sp * cy + sr * cp * sy;// x | ||
| output.data[1] = cr * cp * sy - sr * sp * cy;// y | ||
| output.data[2] = sr * cp * cy - cr * sp * sy;// z | ||
| output.data[3] = cr * cp * cy + sr * sp * sy;// w | ||
| return output; | ||
| } | ||
| // TODO: | ||
| //explicit quaternion(NBL_CONST_REF_ARG(float32_t3x4) m) {} | ||
| inline quaternion operator*(float_t scalar) | ||
| { | ||
| quaternion output; | ||
| output.data = data * scalar; | ||
| return output; | ||
| } | ||
| inline quaternion operator*(NBL_CONST_REF_ARG(quaternion) other) | ||
| { | ||
| return quaternion::create( | ||
| data.w * other.data.w - data.x * other.x - data.y * other.data.y - data.z * other.data.z, | ||
| data.w * other.data.x + data.x * other.w + data.y * other.data.z - data.z * other.data.y, | ||
| data.w * other.data.y - data.x * other.z + data.y * other.data.w + data.z * other.data.x, | ||
| data.w * other.data.z + data.x * other.y - data.y * other.data.x + data.z * other.data.w | ||
| ); | ||
| } | ||
| }; | ||
| }// end namespace core | ||
| }// nbl | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
let#960 overwrite your changes
| // Copyright (C) 2019 - DevSH Graphics Programming Sp. z O.O. | ||
| // This file is part of the "Nabla Engine" and was originally part of the "Irrlicht Engine" | ||
| // For conditions of distribution and use, see copyright notice in nabla.h | ||
| // See the original file in irrlicht source for authors | ||
| #ifndef _NBL_BUILTIN_HLSL_MATH_QUATERNION_IMPL_INCLUDED_ | ||
| #define _NBL_BUILTIN_HLSL_MATH_QUATERNION_IMPL_INCLUDED_ | ||
| #include <nbl/builtin/hlsl/cpp_compat.hlsl> | ||
| namespace nbl | ||
| { | ||
| namespace hlsl | ||
| { | ||
| namespace quaternion_impl | ||
| { | ||
| } | ||
| }// end namespace core | ||
| }// nbl | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
there's no need for this file then
include/nbl/core/math/plane3dSIMD.h Outdated
| matrix3x4SIMD inv; | ||
| _mat.getInverse(inv); | ||
| hlsl::float32_t4x4 inv = hlsl::getMatrix3x4As4x4<hlsl::float32_t>(_mat); | ||
| hlsl::inverse(inv); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
inverse is not in-place, you need to doconst hlsl::float32_t4x4 inv = inverse(linalg::promote(_mat))
include/nbl/core/math/plane3dSIMD.h Outdated
| vectorSIMDfnormal(_in.getNormal()); | ||
| // transform by inverse transpose | ||
| returnplane3dSIMDf(inv.rows[0]*normal.xxxx()+inv.rows[1]*normal.yyyy()+inv.rows[2]*normal.zzzz()+(normal.wwww()&BUILD_MASKF(0,0,0,1))); | ||
| hlsl::float32_t4 planeEq = inv[0] *hlsl::float32_t4(normal.x) + inv[1] *hlsl::float32_t4(normal.y) + inv[2] *hlsl::float32_t4(normal.z) + (hlsl::float32_t4(0,0,0, normal.w)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
use swizzles instead of counting on promotions from constructors
| #definevec4 core::vectorSIMDf | ||
| #definemat4core::matrix4SIMD | ||
| #definemat4x3core::matrix3x4SIMD | ||
| #definemat4hlsl::float32_t4x4 | ||
| #definemat4x3hlsl::float32_t3x4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
don't touch this to reduce conflicts with#946
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
ok, i will just disable the whole file with#if 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
ok, i will just disable the whole file with
#if 0
ok no need, since it is not included anywhere in Nabla
| template<>structSPropertyElementData::get_typename<SPropertyElementData::Type::BLACKBODY> | ||
| {using type =void; }; | ||
| template<>structSPropertyElementData::get_typename<SPropertyElementData::Type::MATRIX> | ||
| {using type =core::matrix4SIMD; }; | ||
| {using type =hlsl::float32_t4x4; }; | ||
| template<>structSPropertyElementData::get_typename<SPropertyElementData::Type::TRANSLATE> | ||
| {using type =core::matrix4SIMD; }; | ||
| {using type =hlsl::float32_t4x4; }; | ||
| template<>structSPropertyElementData::get_typename<SPropertyElementData::Type::ROTATE> | ||
| {using type =core::matrix4SIMD; }; | ||
| {using type =hlsl::float32_t4x4; }; | ||
| template<>structSPropertyElementData::get_typename<SPropertyElementData::Type::SCALE> | ||
| {using type =core::matrix4SIMD; }; | ||
| {using type =hlsl::float32_t4x4; }; | ||
| template<>structSPropertyElementData::get_typename<SPropertyElementData::Type::LOOKAT> | ||
| {using type =core::matrix4SIMD; }; | ||
| {using type =hlsl::float32_t4x4; }; | ||
| template<>structSPropertyElementData::get_typename<SPropertyElementData::Type::INVALID> | ||
| {using type =void; }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
undo all changes tonbl/ext/MitsubaLoader because it will badly conflict with my#937
| NBL_UNROLL_LIMITED(4) | ||
| for (uint32_t i =0; i < matrix_traits<MatT>::RowCount; ++i) | ||
| NBL_UNROLL_LIMITED(4) | ||
| for (uint32_t j =0; j < matrix_traits<MatT>::ColumnCount; ++j) | ||
| output[i][j] =0; | ||
| NBL_UNROLL_LIMITED(4) | ||
| for (uint32_t diag =0; diag < matrix_traits<MatT>::RowCount; ++diag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
use regular unroll in such situations, it works better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
write it similarly in construction to
| matrix<T, NOut, MOut>promote_affine(constmatrix<T, NIn,MIn> inMatrix) |
set entire rows
| #ifndef _NBL_BUILTIN_HLSL_MATRIX_UTILS_TRANSFORMATION_MATRIX_UTILS_INCLUDED_ | ||
| #define _NBL_BUILTIN_HLSL_MATRIX_UTILS_TRANSFORMATION_MATRIX_UTILS_INCLUDED_ | ||
| #include <nbl/builtin/hlsl/math/quaternion/quaternion.hlsl> | ||
| // TODO: remove this header when deleting vectorSIMDf.hlsl | ||
| #ifndef __HLSL_VERSION | ||
| #include <nbl/core/math/glslFunctions.h> | ||
| #include"vectorSIMD.h" | ||
| #endif | ||
| #include <nbl/builtin/hlsl/matrix_utils/matrix_traits.hlsl> | ||
| #include"nbl/builtin/hlsl/cpp_compat/unroll.hlsl" | ||
| namespace nbl | ||
| { | ||
| namespace hlsl | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
add everything here tonbl::hlsl::math::linalg namespace and folder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
but thematrix_traits.hlsl file should stay where it is i suppose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
but the
matrix_traits.hlslfile should stay where it is i suppose?
make it organised similarly tovector_traits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
make it organised similarly to
vector_traits
thats already done
| { | ||
| template<typename MatT> | ||
| MatTdiagonal(float diagonal =1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
diagonal should be of matrix type's scalar type
also fix upmatrix_traits to not have a default spec (also bug 7007 is fixed and you can remove the macro)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
i remember that default spec ofmatrix_traits is there for a reason, but i can't remember what reason.
| template<int N,int M> | ||
| inlinematrix<float64_t, N, M>getAs64BitPrecisionMatrix(NBL_CONST_REF_ARG(matrix<float32_t, N, M>) mat) | ||
| { | ||
| matrix<float64_t, N, M> output; | ||
| for (int i =0; i < N; ++i) | ||
| output[i] = mat[i]; | ||
| return output; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
this should be a_static_cast_helper spec - cast equal rank matrices to each other with different types
| template<typename T> | ||
| inlinematrix<T,4,4>getMatrix3x4As4x4(NBL_CONST_REF_ARG(matrix<T,3,4>) mat) | ||
| { | ||
| matrix<T,4,4> output; | ||
| for (int i =0; i <3; ++i) | ||
| output[i] = mat[i]; | ||
| output[3] =float32_t4(0.0f,0.0f,0.0f,1.0f); | ||
| return output; | ||
| } |
devshgraphicsprogrammingDec 3, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
this ismath::linalg::promote_affinehttps://github.com/Devsh-Graphics-Programming/Nabla/blob/master/include/nbl/builtin/hlsl/math/linalg/transform.hlsl#L78
| template<typename T> | ||
| inlinematrix<T,3,4>extractSub3x4From4x4Matrix(NBL_CONST_REF_ARG(matrix<T,4,4>) mat) | ||
| { | ||
| matrix<T,3,4> output; | ||
| for (int i =0; i <3; ++i) | ||
| output[i] = mat[i]; | ||
| return output; | ||
| } | ||
| template<typename T,int N> | ||
| inlinematrix<T,3,3>getSub3x3(NBL_CONST_REF_ARG(matrix<T, N,4>) mat) | ||
| { | ||
| returnmatrix<T,3,3>(mat); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
make a specialization oftruncate for matrices
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
specialization? is theretruncate already? can't find it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
nvm, done
| namespace transformation_matrix_utils_impl | ||
| { | ||
| // This function calculates determinant using the scalar triple product. | ||
| template<typename T> | ||
| inline Tdeterminant_helper(NBL_CONST_REF_ARG(matrix<T,3,3>) mat,NBL_REF_ARG(vector<T,3>) r1crossr2) | ||
| { | ||
| r1crossr2 = hlsl::cross(mat[1], mat[2]); | ||
| return hlsl::dot(mat[0], r1crossr2); | ||
| } | ||
| } | ||
| //! returs adjugate of the cofactor (sub 3x3) matrix | ||
| template<typename T,int N,int M> | ||
| inlinematrix<T,3,3>getSub3x3TransposeCofactors(NBL_CONST_REF_ARG(matrix<T, N, M>) mat) | ||
| { | ||
| static_assert(N >=3 && M >=3); | ||
| matrix<T,3,3> output; | ||
| vector<T,3> row0 =vector<T,3>(mat[0]); | ||
| vector<T,3> row1 =vector<T,3>(mat[1]); | ||
| vector<T,3> row2 =vector<T,3>(mat[2]); | ||
| output[0] = hlsl::cross(row1, row2); | ||
| output[1] = hlsl::cross(row2, row0); | ||
| output[2] = hlsl::cross(row0, row1); | ||
| output[0] = hlsl::cross(row0, row1); | ||
| return output; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
It already exists
Nabla/include/nbl/builtin/hlsl/math/linalg/fast_affine.hlsl
Lines 80 to 152 in1e637c4
| // useful for fast computation of a Normal Matrix | |
| template<typename T,int N> | |
| struct cofactors_base; | |
| template<typename T> | |
| struct cofactors_base<T,3> | |
| { | |
| using matrix_t =matrix<T,3,3>; | |
| using vector_t =vector<T,3>; | |
| staticinline cofactors_base<T,3>create(NBL_CONST_REF_ARG(matrix_t) val) | |
| { | |
| cofactors_base<T,3> retval; | |
| retval.transposed =matrix_t( | |
| hlsl::cross<vector_t>(val[1],val[2]), | |
| hlsl::cross<vector_t>(val[2],val[0]), | |
| hlsl::cross<vector_t>(val[0],val[1]) | |
| ); | |
| return retval; | |
| } | |
| // | |
| inline matrix_tget() NBL_CONST_MEMBER_FUNC | |
| { | |
| return hlsl::transpose<matrix_t>(transposed); | |
| } | |
| // | |
| inline vector_tnormalTransform(const vector_t n) NBL_CONST_MEMBER_FUNC | |
| { | |
| const vector_t tmp = hlsl::mul<matrix_t,vector_t>(transposed,n); | |
| return hlsl::normalize<vector_t>(tmp); | |
| } | |
| matrix_t transposed; | |
| }; | |
| // variant that cares about flipped/mirrored transforms | |
| template<typename T,int N> | |
| struct cofactors | |
| { | |
| using pseudo_base_t = cofactors_base<T,N>; | |
| using matrix_t = typename pseudo_base_t::matrix_t; | |
| using vector_t = typename pseudo_base_t::vector_t; | |
| using mask_t = unsigned_integer_of_size_t<sizeof(T)>; | |
| staticinline cofactors<T,3>create(NBL_CONST_REF_ARG(matrix_t) val) | |
| { | |
| cofactors<T,3> retval; | |
| retval.composed = pseudo_base_t::create(val); | |
| const T det = hlsl::dot<vector_t>(val[0],retval.composed.transposed[0]); | |
| const mask_t SignBit =1; | |
| SignBit = SignBit<<(sizeof(mask_t)*8-1); | |
| retval.signFlipMask = bit_cast<mask_t>(det) & SignBit; | |
| return retval; | |
| } | |
| // | |
| inline vector_tnormalTransform(const vector_t n) NBL_CONST_MEMBER_FUNC | |
| { | |
| const vector_t tmp = hlsl::mul<matrix_t,vector_t>(composed.transposed,n); | |
| const T rcpLen = hlsl::rsqrt<T>(hlsl::dot<vector_t>(tmp,tmp)); | |
| return tmp*bit_cast<T>(bit_cast<mask_t>(rcpLen)^determinantSignMask); | |
| } | |
| cofactors_base<T,N> composed; | |
| mask_t determinantSignMask; | |
| }; |
| //! Replaces curent rocation and scale by rotation represented by quaternion `quat`, leaves 4th row and 4th colum unchanged | ||
| template<typename T,int N> | ||
| inlinevoidsetRotation(NBL_REF_ARG(matrix<T, N,4>) outMat,NBL_CONST_REF_ARG(nbl::hlsl::quaternion<T>) quat) | ||
| { | ||
| // TODO | ||
| //static_assert(N == 3 || N == 4); | ||
| outMat[0] =vector<T,4>( | ||
| 1 -2 * (quat.data.y * quat.data.y + quat.data.z * quat.data.z), | ||
| 2 * (quat.data.x * quat.data.y - quat.data.z * quat.data.w), | ||
| 2 * (quat.data.x * quat.data.z + quat.data.y * quat.data.w), | ||
| outMat[0][3] | ||
| ); | ||
| outMat[1] =vector<T,4>( | ||
| 2 * (quat.data.x * quat.data.y + quat.data.z * quat.data.w), | ||
| 1 -2 * (quat.data.x * quat.data.x + quat.data.z * quat.data.z), | ||
| 2 * (quat.data.y * quat.data.z - quat.data.x * quat.data.w), | ||
| outMat[1][3] | ||
| ); | ||
| outMat[2] =vector<T,4>( | ||
| 2 * (quat.data.x * quat.data.z - quat.data.y * quat.data.w), | ||
| 2 * (quat.data.y * quat.data.z + quat.data.x * quat.data.w), | ||
| 1 -2 * (quat.data.x * quat.data.x + quat.data.y * quat.data.y), | ||
| outMat[2][3] | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
gets replaces by#960
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
if you need a function that overwrites a square submatrix, add it tohttps://github.com/Devsh-Graphics-Programming/Nabla/blob/master/include/nbl/builtin/hlsl/math/linalg/transform.hlsl
and call itssubmatrixReplace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
had to make some fixes toquaternion::constructMatrix()
| template<typename T,int N> | ||
| inlinevoidsetTranslation(NBL_REF_ARG(matrix<T, N,4>) outMat,NBL_CONST_REF_ARG(vector<T,3>) translation) | ||
| { | ||
| // TODO | ||
| // static_assert(N == 3 || N == 4); | ||
| outMat[0].w = translation.x; | ||
| outMat[1].w = translation.y; | ||
| outMat[2].w = translation.z; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
also generalize it to anymatrix<T,N,N+1> matrix andvector<T,N>, what you have now will only work for 3x4
| // TODO: use portable_float when merged | ||
| //! multiplies matrices a and b, 3x4 matrices are treated as 4x4 matrices with 4th row set to (0, 0, 0 ,1) | ||
| template<typename T> | ||
| inlinematrix<T,3,4>concatenateBFollowedByA(NBL_CONST_REF_ARG(matrix<T,3,4>) a,NBL_CONST_REF_ARG(matrix<T,3,4>) b) | ||
| { | ||
| // TODO | ||
| // static_assert(N == 3 || N == 4); | ||
| constmatrix<T,4,4> a4x4 = getMatrix3x4As4x4<hlsl::float32_t>(a); | ||
| constmatrix<T,4,4> b4x4 = getMatrix3x4As4x4<hlsl::float32_t>(b); | ||
| returnmatrix<T,3,4>(mul(a4x4, b4x4)); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
already exists as
| matrix<T,N,M>promoted_mul(NBL_CONST_REF_ARG(matrix<T,N,P>) lhs,NBL_CONST_REF_ARG(matrix<T,Q,M>) rhs) |
| template<typename T,int N> | ||
| inlineboolgetSub3x3InverseTranspose(NBL_CONST_REF_ARG(matrix<T, N,4>) matIn,NBL_CONST_REF_ARG(matrix<T,3,3>) matOut) | ||
| { | ||
| matrix<T,3,3> matIn3x3 =getSub3x3(matIn); | ||
| vector<T,3> r1crossr2; | ||
| T d = transformation_matrix_utils_impl::determinant_helper(matIn3x3, r1crossr2); | ||
| if (abs(d) <= FLT_MIN) | ||
| returnfalse; | ||
| auto rcp =T(1.0f)/d; | ||
| // matrix of cofactors * 1/det | ||
| matOut =getSub3x3TransposeCofactors(matIn3x3); | ||
| matOut[0] *= rcp; | ||
| matOut[1] *= rcp; | ||
| matOut[2] *= rcp; | ||
| returntrue; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
this probalby exists somewhere already
| template<typename T,int N> | ||
| inlinevoidsetScale(NBL_REF_ARG(matrix<T, N,4>) outMat,NBL_CONST_REF_ARG(vector<T,3>) scale) | ||
| { | ||
| // TODO | ||
| // static_assert(N == 3 || N == 4); | ||
| outMat[0][0] = scale[0]; | ||
| outMat[1][1] = scale[1]; | ||
| outMat[2][2] = scale[2]; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
this is not correct, the scale in a matrix is defined by the length of its column vectors (think about what happens when you right-multiply a pre-scale)
M S v // S is diagonalso any scale "reset" needs to grab each column, and do
column *= newScale*inversesqrt(dot(column,column));| #ifndef _NBL_BUILTIN_HLSL_VECTOR_UTILS_VECTOR_UTILS_INCLUDED_ | ||
| #define _NBL_BUILTIN_HLSL_VECTOR_UTILS_VECTOR_UTILS_INCLUDED_ | ||
| #include <nbl/builtin/hlsl/cpp_compat.hlsl> | ||
| namespace nbl | ||
| { | ||
| namespace hlsl | ||
| { | ||
| // TODO: why cant I NBL_CONST_REF_ARG(vector<T, N>) | ||
| template<typename T, uint32_t N> | ||
| inline Tlengthsquared(vector<T, N> vec) | ||
| { | ||
| returndot(vec, vec); | ||
| } | ||
| } | ||
| } | ||
| #endif No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
It already exists and is just
| scalar_type_t<T>lpNormPreroot(NBL_CONST_REF_ARG(T) v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
ok, i will remove this file then.
what about i create an alias for the functionlpNormPreroot in thehlsl/math/functions.hlsl file?
scalar_type_t<T>lengthSquared(NBL_CONST_REF_ARG(T) v) {returnlpNormPreroot(v);}
its more descriptive and would make code less confusing in some cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
includinghlsl/math/functions.hlsl causes compilation errors
| #ifndef _NBL_BUILTIN_HLSL_PROJECTION_PROJECTION_INCLUDED_ | ||
| #define _NBL_BUILTIN_HLSL_PROJECTION_PROJECTION_INCLUDED_ | ||
| #include <nbl/builtin/hlsl/cpp_compat.hlsl> | ||
| #include <nbl/builtin/hlsl/concepts.hlsl> | ||
| namespace nbl | ||
| { | ||
| namespace hlsl | ||
| { |
devshgraphicsprogrammingDec 4, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
move intomath, just name the filenbl/builtin/hlsl/math/thin_lens_projection.hlsl
| { | ||
| namespace hlsl | ||
| { | ||
| // TODO: use glm instead for c++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
actually no, keep it identical between C++ and HLSL, less chance for bugs
| { | ||
| // TODO: use glm instead for c++ | ||
| template<typename FloatingPointNBL_FUNC_REQUIRES(concepts::FloatingPoint<FloatingPoint>) | ||
| inlinematrix<FloatingPoint,4,4>buildProjectionMatrixPerspectiveFovRH(FloatingPoint fieldOfViewRadians, FloatingPoint aspectRatio, FloatingPoint zNear, FloatingPoint zFar) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
dropbuildProjectionMatrixPerspective from the name, use anbl::hlsl::math::thin_lens namespace instead and let the name berhPerspectiveFovMatrix, likewise fo the other functions
…into remove_core_matrix
No description provided.