Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hlsl matrix multiplication

Tags:

matrix

hlsl

I was just playing with HLSL . I want to get the vector "inputPos" in vector "pos". case2 is working but not case1 . why ? Aren't both the cases same ? M * M_Inv * inputPos = inputPos. Why case 1 is not giving right value?

//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 );

thanks.

like image 754
YAHOOOOO Avatar asked May 29 '26 01:05

YAHOOOOO


1 Answers

Probably in your case variable pos is float3,so if you don't provide the w component in the second operation that will mess up your calculation. (in case 2 you use the result of the first mul directly which will be a float4)

pos = mul( float4( inputPos, 1), c_mView );
pos = mul ( float4(pos,1) ,  c_mViewInverse ); 
like image 123
mrvux Avatar answered Jun 02 '26 13:06

mrvux