D3D9 HLSL 矩阵化了我的大脑
我正在向各位 Direct3D 专家寻求帮助。坦白说,HLSL 的奇怪行为让我抓狂。这是我指定矩阵的方式。
现在我的问题 D3DX 9 函数:
D3DXMatrixOrthoOffCenterRH 等...
它们是否返回以此形式使用的矩阵: v' = v * M // 列专业
或 v' = M * v // 行专业???
我注意到 D3DXMatrixTrnaslate 属于列专业,我假设所有函数都是相同的。
现在,D3DX Project 和 Unproject 函数是否采用与上述函数返回的相同形式?
有人经历过 HLSL 矩阵乘法的真正疯狂吗?
谢谢。
I'm seeking help from all of you expert with Direct3D. Frankly I'm getting nuts by a really weird behavior from HLSL. It's the way I specify matrices.
Now my question D3DX 9 functions:
D3DXMatrixOrthoOffCenterRH and others...
Do they return a matrix that's used in this form: v' = v * M // Column major
or v' = M * v // Row major ???
I noticed the D3DXMatrixTrnaslate is in Column major and I assume the same for all functions.
Now does D3DX Project and Unproject functions takes in the same form returned by the above functions?
Have anyone experienced a really craziness from HLSL matrix multiplication?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会保持简短。 RH 函数返回列主(http://en.wikipedia.org/wiki/Column_vector,供参考)矩阵,并且不是 HLSL(或正确优化的组件)着色器选择的布局,因为它们无法执行使用点积对向量进行 3D 变换。因此,在上传到着色器常量内存之前,请使用 LH 或行优先(V'= M * V,实际上)布局或至少转置。
如需实际操作示例,请查看 DirectX 文档,查找 D3DXMatrixLookAtLH() 和 D3DXMatrixLookAtRH()。在该页面上给出了矩阵的布局,您可以比较布局,并了解为什么用 X,Y,Z,1 向量对每一行进行点4,分别对 X、Y、Z 和 W 执行仿射变换(给定您使用 LH/行主矩阵)。
I'll keep this brief. The RH functions return column-major (http://en.wikipedia.org/wiki/Column_vector, for ref.) matrices and are not the layout of choice for HLSL (or properly optimized assembly) shaders, since they can not perform a 3D transform of a vector using dot products. So use the LH or row-major (V'= M * V, indeed) layout or at least transpose before uploading to shader constant memory.
For a hands-on example take the DirectX documentation, look up D3DXMatrixLookAtLH() and D3DXMatrixLookAtRH(). On that page a layout of the matrix is given, you can compare the layouts, and see why dot4'ing each row with a X,Y,Z,1 vector performs the affine transform for X, Y, Z and W respectively (given that you use the LH/row-major matrix).