I'm going through all the MS tutorials on DirectX and I've noticed that they are always passing World, View and Projection matrices to the technique and then multiplying them in the vertex shader.
Is there a reason to do that rather than multiply the matrices before drawing and then pass a single WVP matrix to the shader? This way the matrices would be multiplied once per frame instead of once per vertex, right?
Thanks in advance.
Edit: updated with sample code
MS tutorials:
matrix World;
matrix View;
matrix Projection;
struct VS_INPUT
{
float4 Pos : POSITION;
float4 Color : COLOR;
};
struct VS_OUTPUT
{
float4 Pos : SV_POSITION;
float4 Color : COLOR;
};
PS_INPUT VS( VS_INPUT input )
{
VS_OUTPUT output;
output.Pos = mul( input.Pos, World );
output.Pos = mul( output.Pos, View );
output.Pos = mul( output.Pos, Projection );
output.Color = input.Color;
return output;
}
Why not this way:
matrix WVP;
struct VS_INPUT
{
float4 Pos : POSITION;
float4 Color : COLOR;
};
struct VS_OUTPUT
{
float4 Pos : SV_POSITION;
float4 Color : COLOR;
};
PS_INPUT VS( VS_INPUT input )
{
VS_OUTPUT output;
output.Pos = mul( input.Pos, WVP );
output.Color = input.Color;
return output;
}