HLSL mul()变量说明 [英] HLSL mul() variables clarification

查看:165
本文介绍了HLSL mul()变量说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HLSL的mul(x,y)的参数表示此处:说




  • 如果x是向量,则将其视为行向量。

  • 如果y是向量,则将其视为列向量。



这样做然后遵循以下意思:



a。




  • 如果x是向量,y被视为行主矩阵

  • 如果y是向量,x被视为列主矩阵



b。



因为ID3DXBaseEffect :: SetMatrix()传递了 行主要矩阵 ,因此我将使用传递到着色器中的矩阵



ex。 Output.mPosition = mul(Input.mPosition,SetMatrix()value);



我才刚刚开始与着色器和当前重新学习我的矩阵数学。

解决方案

是的,如果x是向量,则x被视为行大写。向量和y被视为行主矩阵;反之亦然,对于列主列,对于行主列矩阵系统,则相反:

对于主要列:

  float4 transform = mul(world,position); 

由于矩阵乘法的工作方式,如果矩阵是大列矩阵,则必须发布乘法通过列向量获得正确的结果。如果矩阵是行主矩阵,则必须预先乘以行向量。



因此,hlsl并不关心矩阵是行还是列主矩阵,它是由您决定以正确的顺序应用向量乘法以获得正确的结果。


The parameters for HLSL's mul( x, y) indicated here: say that

  • if x is a vector, it is treated as a row vector.
  • if y is a vector, it is treated as a column vector.

Does this then follow through meaning that:

a.

  • if x is a vector, y is treated as a row-major matrix
  • if y is a vector, x is treated as a column-major matrix

b.

since ID3DXBaseEffect::SetMatrix() passes in a row-major matrix, hence I'd use the matrix passed into the shader in following order:

ex. Output.mPosition = mul( Input.mPosition, SetMatrix()value ); ?

I'm just starting out with shaders and current relearning my matrix math. It would be nice if someone could clarify this.

解决方案

Yes, if x is a vector then x is treated as a row major vector and y is treated as a row major matrix; vice versa for column major so for a row-major matrix system:

float4 transformed = mul(position, world);

and for column-major:

float4 transformed = mul(world, position);

Because of the way that matrix multiplication works, if the matrix is column-major then you must post multiply by a column vector to get the correct result. If the matrix is row-major you must pre multiply by a row vector.

So really, hlsl doesn't care whether your matrix is row or column major, it is up to you to apply the vector multiplication in the correct order to get the correct result.

这篇关于HLSL mul()变量说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆