• Advertisement
Sign in to follow this  

Question about HLSL matrix multiplication

This topic is 683 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I wrote a very simple HLSL shader, but the matrix multiplication confuses me.
 
// The matrix is in column major
 
cbuffer Transform : register(b0)
{
matrix gViewMatrix;
matrix gProjMatrix;
};
 
void VS(in float3 pos : POSITION
,in float4 col : COLOR
,out float4 colour : COLOR
,out float4 posH : SV_POSITION
)
{
matrix vp = gProjMatrix * gViewMatrix;
// The code below works
posH = mul(gViewMatrix, float4(pos, 1.0));
posH = mul(gProjMatrix, posH);
// The code below doesn't works
//posH = mul(vp, float4(pos, 1.0));
colour = col;
}
 
 
If i multiply the vector twice by mul, the result is right.
But if i use the multiplication result of the matrix, the result is wrong!
Why this will happen?
Edited by 562538332

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement