error:
1.
mul' implicit truncation of vector type
2.
matrixXXX: array dimensions of(unknown scope entry kind) must be explicit------------(XXXX(float3X4 matrix[]))-->(XXXX(float3X4 matrix[12]))
this problem refers to a para float 3X4 matrix[]
changed to float 3X4 matrix[3][4]
transpose(M)
下面引用的两个人我同意第二个,第一个人灰色部分我认为反了
opengl ,cg : column-major mul(matrix, pos) pos 列向量
dx : row-major mul(pos, matrix) pos 行向量
cg change to hlsl的
solution :应该就是 mul(matrix, pos)---> mul(pos, transpose(matrix))
这个solution有待验证
无论行向量 列向量 添加第四个的方法
float4 pos= float4(pos, 1);
float4 normal=float4(normal, 0);
float4 tangent=float4(tangent,0)
------------------------
这个问题 解决了 原来是两个问题混在一起
(XXXX(float3X4 matrix[]))-->(XXXX(float3X4 matrix[12]))我之前改为 matrix[3][4]这样compile通过但是意义很错
我忽略的那个问题就是 float3X4 matrix[12] is a 3 dims matrix so matrix[1] means a array of 3X4 not a array of 1X4 of 3X1
对于 cg --->hlsl mul 的问题 solution 明确:mul(matrix, pos)---> mul(pos, transpose(matrix))
引用放最后
--------------------------------------------------------
http://msdn.microsoft.com/en-us/library/windows/desktop/bb509706(v=vs.85).aspx
http://www.cnitblog.com/wjk98550328/archive/2007/09/27/34077.html
看dx sdk原文
The data in a matrix is loaded into shader constant registers before a shader runs. There are two choices for how the matrix data is read: in row-major order or in column-major order. Column-major order means that each matrix column will be stored in a single constant register, and row-major order means that each row of the matrix will be stored in a single constant register. This is an important consideration for how many constant registers are used for a matrix.
Row-major and column-major matrix ordering determine the order the matrix components are read from the constant table or from shader inputs. Once the data is written into constant registers, matrix order has no effect on how the data is used or accessed from within shader code. Also, matrices declared in a shader body do not get packed into constant registers.
解释:
这个row-major和column-major,只是决定你提供给shader的矩阵如何被理解,如果存入寄存器。举个例子,shader code中有column-major的float4x3 matWorld,那么你设置的时候提供一个4×3的矩阵,这个矩阵将占3个float4的寄存器,每列占一个,进行乘法计算的时候,必须是mul(pos,matWorld),也就是pos左乘这个矩阵。
如果shader中一个row-major的float3×4的矩阵,也占3个寄存器,乘法的时候是mul(matWorld,pos),就是pos右乘矩阵。
上面做法效率一样,结果一样。
如果,你混淆着瞎来,结果不是你想要的,就是占多寄存器之类。。。。
------------------
OpenGL: 按列存储矩阵(column-major)。调用API形成的矩阵用来和一个列向量相乘,矩阵在左,列向量在右
GLSL: 存储方式和OpenGL相同(column-major)
DirectX: 按行存储矩阵(row-major)。调用API形成的矩阵用来和一个行向量相乘,矩阵在右,行向量在左
HLSL: 存储方式和DirectX相反(column-major)
此,若HLSL的矩阵也是用来右乘行向量,则应将DX API构造的矩阵做Transpose,这样数学上HLSL会将Transpose后的矩阵视为 和DX API构造的矩阵是同一个矩阵,但是实际数值的存储顺序不同。若用来将矩阵左乘列向量,则可以不必做Transpose。
因此,一般的传入shader的操作是原封不动的将用来存储矩阵的array导入shader。但是如果是用的effect system里的setMatrix(), 则会先自动将矩阵由row-major改为colunn-major存储,再将其导入shader。这种情况下则无需在导入前手动Transpose 矩阵。
http://alvincc-tech.blogspot.com/2010/10/opengl-glsl-directx-hlsl.html