3

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.

YAHOOOOO
  • 939
  • 4
  • 19
  • 27

1 Answers1

1

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 ); 
mrvux
  • 8,523
  • 1
  • 27
  • 61