Sign in to follow this  
maogenc

HLSL matrix transformation doesn't seem to work

Recommended Posts

maogenc    109
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.



[code]
//--------------------------------------------------------------------------------------
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;
}

[/code]

Share this post


Link to post
Share on other sites
NightCreature83    5006
[quote name='maogenc' timestamp='1305763605' post='4812808']
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.



[code]
//--------------------------------------------------------------------------------------
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;
}

[/code]
[/quote]
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this