Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
Przemog1 wants to merge18 commits intomaster
base:master
Choose a base branch
Loading
fromremove_core_matrix
Open

Remove core::matrixSIMD#950

Przemog1 wants to merge18 commits intomasterfromremove_core_matrix

Conversation

@Przemog1
Copy link
Contributor

No description provided.

Comment on lines 9 to 13
#include<vectorSIMD.h>
#include<nbl/builtin/hlsl/cpp_compat/matrix.hlsl>

#include"ISceneNode.h"
#include"matrixutil.h"

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

Przemog1 reacted with thumbs up emoji
#include"line3d.h"
#include"matrix4SIMD.h"
#include"position2d.h"
#include"quaternion.h"

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

Przemog1 reacted with thumbs up emoji
Comment on lines -224 to +230
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()};

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 ?

Copy link
ContributorAuthor

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

Copy link
ContributorAuthor

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

Comment on lines 1 to 51
#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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Przemog1 reacted with thumbs up emoji
Comment on lines 1 to 12
#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

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]]

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

Przemog1 reacted with thumbs up emoji
Comment on lines 1 to 96
// 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

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

Przemog1 reacted with thumbs up emoji
Comment on lines 1 to 24
// 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

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

Przemog1 reacted with thumbs up emoji
matrix3x4SIMD inv;
_mat.getInverse(inv);
hlsl::float32_t4x4 inv = hlsl::getMatrix3x4As4x4<hlsl::float32_t>(_mat);
hlsl::inverse(inv);

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))

Przemog1 reacted with thumbs up emoji
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));

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

Przemog1 reacted with thumbs up emoji
Comment on lines 58 to 60
#definevec4 core::vectorSIMDf
#definemat4core::matrix4SIMD
#definemat4x3core::matrix3x4SIMD
#definemat4hlsl::float32_t4x4
#definemat4x3hlsl::float32_t3x4

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

Przemog1 reacted with thumbs up emoji
Copy link
ContributorAuthor

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

Copy link
ContributorAuthor

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

Comment on lines 301 to 314
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; };

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

Przemog1 reacted with thumbs up emoji
Comment on lines 22 to 29
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)

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

Przemog1 reacted with thumbs up emoji

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

Przemog1 reacted with thumbs up emoji
Comment on lines 1 to 15
#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
{

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

Przemog1 reacted with thumbs up emoji
Copy link
ContributorAuthor

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?

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?

make it organised similarly tovector_traits

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

make it organised similarly tovector_traits

thats already done

{

template<typename MatT>
MatTdiagonal(float diagonal =1)

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)

Przemog1 reacted with thumbs up emoji
Copy link
ContributorAuthor

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.

Comment on lines 70 to 78
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;
}

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

Przemog1 reacted with thumbs up emoji
Comment on lines 43 to 52
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;
}
Copy link
Member

@devshgraphicsprogrammingdevshgraphicsprogrammingDec 3, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Przemog1 reacted with thumbs up emoji
Comment on lines 54 to 68
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);
}

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

Copy link
ContributorAuthor

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

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

nvm, done

Comment on lines 80 to 108
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;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It already exists

// 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;
};

Przemog1 reacted with thumbs up emoji
Comment on lines 153 to 181
//! 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]
);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

gets replaces by#960

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

Przemog1 reacted with thumbs up emoji
Copy link
ContributorAuthor

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()

Comment on lines 183 to 192
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;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

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

Przemog1 reacted with thumbs up emoji
Comment on lines 129 to 140
// 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));
}

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)

Przemog1 reacted with thumbs up emoji
Comment on lines 110 to 127
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;
}

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

Przemog1 reacted with thumbs up emoji
Comment on lines 142 to 151
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];
}

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 diagonal

so any scale "reset" needs to grab each column, and do

column *= newScale*inversesqrt(dot(column,column));

Przemog1 reacted with thumbs up emoji
Comment on lines 1 to 21
#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

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)

Przemog1 reacted with thumbs up emoji
Copy link
ContributorAuthor

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

Copy link
ContributorAuthor

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

Comment on lines 1 to 10
#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
{
Copy link
Member

@devshgraphicsprogrammingdevshgraphicsprogrammingDec 4, 2025
edited
Loading

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

Przemog1 reacted with thumbs up emoji
{
namespace hlsl
{
// TODO: use glm instead for c++

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

Przemog1 reacted with thumbs up emoji
{
// 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)

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

Przemog1 reacted with thumbs up emoji
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@devshgraphicsprogrammingdevshgraphicsprogrammingdevshgraphicsprogramming left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@Przemog1@devshgraphicsprogramming@keptsecret

[8]ページ先頭

©2009-2025 Movatter.jp