Jump to content
  • Advertisement
Sign in to follow this  
562538332

Question about HLSL matrix multiplication

This topic is 771 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!