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

## Recommended Posts

Hi,

I have a quick questions: How do I multiply the three matrices world, view and projection correctly in the shader? I've these matrices given as float 4x3 , and all I'm trying to do is to get a WorldViewProjection-Matrix in the HLSL-shader (I'm using instancing so no pre-shader-multplying is possible):

float4x4 WorldViewProjection = mul(mul(World, View), Projection);

However I keep getting the error-message that a float 4x3 can't be converted into 4x4. Somehow logical, I'm multiplying some 4x3-matrices, how should that go into a 4x4. Well.. does anyone know how to do so? If I set any of the given matrices to 4x3 I can't set them anymore (they stay 0 for all values in this case according to PIX). Any ideas?

##### Share on other sites
Just use 4x4 matrices, I never used 4x3 matrices...
Projection matrix is a 4x4 matrix so it makes sense to use 4x4 matrices, also, a vertex position in homogeneous space is stored in a 4D vector.

This is how I do it:
 float4 posWS = mul(float4(vIn.posL,1.0f), gWorld); float4 posVS = mul(posWS, gView); vOut.posH = mul(posVS, gProj); 

##### Share on other sites
Thanks, I already thought that the projection matrix is a 4x4 matrix as I read it in some tutorials, however I wondered why my shader would only accept a 4x3-projection matrix from the main program. I found out that there was an issue going on with the settings of the matrices: I'm using the directx9 effect pool, and in the effect file I asign my matrix too the projection matrix was set to 4x3, and in the one I am working on its 4x4. Now its working as I expected.

##### Share on other sites
Using a 4x3 won't really save you anything, since each row of the matrix will end up getting aligned to 16-byte boundaries which means it will take up the same space as a 4x4. However for future reference, you can always just convert a 4x3 to a 4x4 in your shader code and the shader compiler will do the right thing:

 float4x4 world4x4 = float4x4(float4(World._11_12_13, 0.0f), float4(World._21_22_23, 0.0f), float4(World._31_32_33, 0.0f), float4(World._41_42_43, 1.0f)); 

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631710
• Total Posts
3001846
×