HLSL matrix transformation doesn't seem to work

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

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 on other sites

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 on other sites
Thanks for pointing that out.