Jump to content
  • Advertisement
Sign in to follow this  
maogenc

HLSL matrix transformation doesn't seem to work

This topic is 2593 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've run into an issue with matrix transformations in HLSL that doesn't make sense to me. The following code does a matrix multiply to scale the vertices by 1/2 but doesn't seem to produce any visible change in the object. Debugging in PIX shows that the vertices are not being affected by the matrix multiply. If I apply the same transformation directly to the xyz components of the vertices then my object is correctly scaled by 1/2.




//--------------------------------------------------------------------------------------
struct VS_INPUT
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;
};

struct PS_INPUT
{
float4 Pos : SV_POSITION;
float2 Tex : TEXCOORD0;
};


//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
PS_INPUT VS( VS_INPUT input )
{


PS_INPUT output = (PS_INPUT)0;
output.Pos = mul( input.Pos, World );

//this works
output.Pos.xyz *= .5;

//this has no effect
float fac = .5;
float4x4 scale4x4 = float4x4(
fac, 0, 0, 0,
0, fac, 0, 0,
0, 0, fac, 0,
0, 0, 0, fac);
output.Pos = mul(output.Pos, scale4x4);

output.Pos = mul( output.Pos, View );
output.Pos = mul( output.Pos, Projection );
output.Tex = input.Tex;


return output;
}

Share this post


Link to post
Share on other sites
Advertisement

I've run into an issue with matrix transformations in HLSL that doesn't make sense to me. The following code does a matrix multiply to scale the vertices by 1/2 but doesn't seem to produce any visible change in the object. Debugging in PIX shows that the vertices are not being affected by the matrix multiply. If I apply the same transformation directly to the xyz components of the vertices then my object is correctly scaled by 1/2.




//--------------------------------------------------------------------------------------
struct VS_INPUT
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;
};

struct PS_INPUT
{
float4 Pos : SV_POSITION;
float2 Tex : TEXCOORD0;
};


//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
PS_INPUT VS( VS_INPUT input )
{


PS_INPUT output = (PS_INPUT)0;
output.Pos = mul( input.Pos, World );

//this works
output.Pos.xyz *= .5;

//this has no effect
float fac = .5;
float4x4 scale4x4 = float4x4(
fac, 0, 0, 0,
0, fac, 0, 0,
0, 0, fac, 0,
0, 0, 0, fac);
output.Pos = mul(output.Pos, scale4x4);

output.Pos = mul( output.Pos, View );
output.Pos = mul( output.Pos, Projection );
output.Tex = input.Tex;


return output;
}



Your scale matrix is also affecting the projective division value in a vector, the 44 element in normal RST matrices is allways 1 in your case that value is 0.5.

Share this post


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

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!