direct3d - Why is this Transpose() required in my WorldViewProj matrix? -


given super-basic vertex shader such as:

output.position = mul(position, _gworldviewproj); 

i having great deal of trouble because setting _gworldviewproj follows; tried both (a bit of flailing) make sure wasn't backwards.

mworldviewproj = world * view * proj; mworldviewproj = proj * view * world; 

my solution turned out be:

mworldview = mworld * mview; mworldviewproj = xmmatrixtranspose(worldview * proj); 

can explain why xmmatrixtranspose required? know there matrix differences between xna , hlsl (i think) not between vanilla c++ , hlsl, though wrong.

problem don't know if i'm wrong or i'm wrong about! if tell me precisely why transpose required, won't make same mistake again.

on cpu, 2d arrays stored in row-major ordering, order in memory goes x[0][0], x[0][1], ... in hlsl, matrix declarations default column-major ordering, order goes x[0][0], x[1][0], ...

in order transform memory format defined on cpu order expected in hlsl, need transpose cpu matrix before sending gpu. alternatively, can row_major keyword in hlsl declare matrices row major, eliminating need transpose leading different codegen in hlsl (you'll end mul-adds instead of dot-products).


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -