matrix - hlsl矩阵乘法

标签 matrix hlsl

我只是在玩 HLSL 。我想在向量“pos”中获取向量“inputPos”。 case2 正在工作但不是 case1 。为什么 ?两种情况不一样吗? M * M_Inv * inputPos = inputPos。为什么案例 1 没有给出正确的值?

//case 1
pos = mul( float4( inputPos, 1), c_mView );     // Line1
pos = mul ( pos ,  c_mViewInverse );            // Line2

//case2
pos = mul ( mul( float4( inputPos, 1), c_mView ) ,  c_mViewInverse );

谢谢。

最佳答案

可能在你的情况下变量 pos 是 float3,所以如果你不在第二个操作中提供 w 组件,那将搞乱你的计算。 (在情况 2 中,您直接使用第一个 mul 的结果,它将是一个 float4)

pos = mul( float4( inputPos, 1), c_mView );
pos = mul ( float4(pos,1) ,  c_mViewInverse ); 

关于matrix - hlsl矩阵乘法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12280031/

相关文章:

Python:3D 列表、总和列

directx - 如何使用着色器常量缓冲区?

unity-game-engine - Unity 中的 ThreeJS 着色器

directx-11 - DirectX 11 像素着色器 什么是 SV_POSITION?

python - 在 python 中使用两个值对作为键的最佳方法是什么?

python - reshape 矩阵

c - 如何提高C中矩阵运算的效率?

matrix - VR中变换矩阵的问题

c - HLSL 函数未被识别?未声明的错误

variables - HLSL 像素着色器 - 全局变量?