【问题标题】:hlsl matrix multiplicationhlsl矩阵乘法
【发布时间】:2012-09-05 11:03:36
【问题描述】:

我只是在玩 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 );

谢谢。

【问题讨论】:

    标签: matrix hlsl


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-11
      • 2017-03-11
      • 2013-12-23
      • 2014-09-19
      • 1970-01-01
      相关资源
      最近更新 更多