mul
Keywords: mul, NVIDIA, NVIDIA Cg Toolkit, Cg Toolkit, Shader, Shader Programming, GPU Shader Programming, GPU Program

> ## Name

> mul - multiply a matrix by a column vector, row vector by a matrix, or matrix by a matrix

> ## Synopsis

>     float4 mul(float4x4 M, float4 v);
>     float4 mul(float4x3 M, float3 v);
>     float4 mul(float4x2 M, float2 v);
>     float4 mul(float4x1 M, float1 v);
>     float3 mul(float3x4 M, float4 v);
>     float3 mul(float3x3 M, float3 v);
>     float3 mul(float3x2 M, float2 v);
>     float3 mul(float3x1 M, float1 v);
>     float2 mul(float2x4 M, float4 v);
>     float2 mul(float2x3 M, float3 v);
>     float2 mul(float2x2 M, float2 v);
>     float2 mul(float2x1 M, float1 v);
>     float1 mul(float1x4 M, float4 v);
>     float1 mul(float1x3 M, float3 v);
>     float1 mul(float1x2 M, float2 v);
>     float1 mul(float1x1 M, float1 v);

>     float4 mul(float4 v, float4x4 M);
>     float4 mul(float3 v, float3x4 M);
>     float4 mul(float2 v, float2x4 M);
>     float4 mul(float1 v, float1x4 M);
>     float3 mul(float4 v, float4x3 M);
>     float3 mul(float3 v, float3x3 M);
>     float3 mul(float2 v, float2x3 M);
>     float3 mul(float1 v, float1x3 M);
>     float2 mul(float4 v, float4x2 M);
>     float2 mul(float3 v, float3x2 M);
>     float2 mul(float2 v, float2x2 M);
>     float2 mul(float1 v, float1x2 M);
>     float1 mul(float4 v, float4x1 M);
>     float1 mul(float3 v, float3x1 M);
>     float1 mul(float2 v, float2x1 M);
>     float1 mul(float1 v, float1x1 M);

>     half4 mul(half4x4 M, half4 v);
>     half4 mul(half4x3 M, half3 v);
>     half4 mul(half4x2 M, half2 v);
>     half4 mul(half4x1 M, half1 v);
>     half3 mul(half3x4 M, half4 v);
>     half3 mul(half3x3 M, half3 v);
>     half3 mul(half3x2 M, half2 v);
>     half3 mul(half3x1 M, half1 v);
>     half2 mul(half2x4 M, half4 v);
>     half2 mul(half2x3 M, half3 v);
>     half2 mul(half2x2 M, half2 v);
>     half2 mul(half2x1 M, half1 v);
>     half1 mul(half1x4 M, half4 v);
>     half1 mul(half1x3 M, half3 v);
>     half1 mul(half1x2 M, half2 v);
>     half1 mul(half1x1 M, half1 v);

>     half4 mul(half4 v, half4x4 M);
>     half4 mul(half3 v, half3x4 M);
>     half4 mul(half2 v, half2x4 M);
>     half4 mul(half1 v, half1x4 M);
>     half3 mul(half4 v, half4x3 M);
>     half3 mul(half3 v, half3x3 M);
>     half3 mul(half2 v, half2x3 M);
>     half3 mul(half1 v, half1x3 M);
>     half2 mul(half4 v, half4x2 M);
>     half2 mul(half3 v, half3x2 M);
>     half2 mul(half2 v, half2x2 M);
>     half2 mul(half1 v, half1x2 M);
>     half1 mul(half4 v, half4x1 M);
>     half1 mul(half3 v, half3x1 M);
>     half1 mul(half2 v, half2x1 M);
>     half1 mul(half1 v, half1x1 M);

>     fixed4 mul(fixed4x4 M, fixed4 v);
>     fixed4 mul(fixed4x3 M, fixed3 v);
>     fixed4 mul(fixed4x2 M, fixed2 v);
>     fixed4 mul(fixed4x1 M, fixed1 v);
>     fixed3 mul(fixed3x4 M, fixed4 v);
>     fixed3 mul(fixed3x3 M, fixed3 v);
>     fixed3 mul(fixed3x2 M, fixed2 v);
>     fixed3 mul(fixed3x1 M, fixed1 v);
>     fixed2 mul(fixed2x4 M, fixed4 v);
>     fixed2 mul(fixed2x3 M, fixed3 v);
>     fixed2 mul(fixed2x2 M, fixed2 v);
>     fixed2 mul(fixed2x1 M, fixed1 v);
>     fixed1 mul(fixed1x4 M, fixed4 v);
>     fixed1 mul(fixed1x3 M, fixed3 v);
>     fixed1 mul(fixed1x2 M, fixed2 v);
>     fixed1 mul(fixed1x1 M, fixed1 v);

>     fixed4 mul(fixed4 v, fixed4x4 M);
>     fixed4 mul(fixed3 v, fixed3x4 M);
>     fixed4 mul(fixed2 v, fixed2x4 M);
>     fixed4 mul(fixed1 v, fixed1x4 M);
>     fixed3 mul(fixed4 v, fixed4x3 M);
>     fixed3 mul(fixed3 v, fixed3x3 M);
>     fixed3 mul(fixed2 v, fixed2x3 M);
>     fixed3 mul(fixed1 v, fixed1x3 M);
>     fixed2 mul(fixed4 v, fixed4x2 M);
>     fixed2 mul(fixed3 v, fixed3x2 M);
>     fixed2 mul(fixed2 v, fixed2x2 M);
>     fixed2 mul(fixed1 v, fixed1x2 M);
>     fixed1 mul(fixed4 v, fixed4x1 M);
>     fixed1 mul(fixed3 v, fixed3x1 M);
>     fixed1 mul(fixed2 v, fixed2x1 M);
>     fixed1 mul(fixed1 v, fixed1x1 M);

>     float1x1 mul(float1x1 A, float1x1 B);
>     float1x2 mul(float1x1 A, float1x2 B);
>     float1x3 mul(float1x1 A, float1x3 B);
>     float1x4 mul(float1x1 A, float1x4 B);

>     float1x1 mul(float1x2 A, float2x1 B);
>     float1x2 mul(float1x2 A, float2x2 B);
>     float1x3 mul(float1x2 A, float2x3 B);
>     float1x4 mul(float1x2 A, float2x4 B);

>     float1x1 mul(float1x3 A, float3x1 B);
>     float1x2 mul(float1x3 A, float3x2 B);
>     float1x3 mul(float1x3 A, float3x3 B);
>     float1x4 mul(float1x3 A, float3x4 B);

>     float1x1 mul(float1x4 A, float4x1 B);
>     float1x2 mul(float1x4 A, float4x2 B);
>     float1x3 mul(float1x4 A, float4x3 B);
>     float1x4 mul(float1x4 A, float4x4 B);

>     float2x1 mul(float2x1 A, float1x1 B);
>     float2x2 mul(float2x1 A, float1x2 B);
>     float2x3 mul(float2x1 A, float1x3 B);
>     float2x4 mul(float2x1 A, float1x4 B);

>     float2x1 mul(float2x2 A, float2x1 B);
>     float2x2 mul(float2x2 A, float2x2 B);
>     float2x3 mul(float2x2 A, float2x3 B);
>     float2x4 mul(float2x2 A, float2x4 B);

>     float2x1 mul(float2x3 A, float3x1 B);
>     float2x2 mul(float2x3 A, float3x2 B);
>     float2x3 mul(float2x3 A, float3x3 B);
>     float2x4 mul(float2x3 A, float3x4 B);

>     float2x1 mul(float2x4 A, float4x1 B);
>     float2x2 mul(float2x4 A, float4x2 B);
>     float2x3 mul(float2x4 A, float4x3 B);
>     float2x4 mul(float2x4 A, float4x4 B);

>     float3x1 mul(float3x1 A, float1x1 B);
>     float3x2 mul(float3x1 A, float1x2 B);
>     float3x3 mul(float3x1 A, float1x3 B);
>     float3x4 mul(float3x1 A, float1x4 B);

>     float3x1 mul(float3x2 A, float2x1 B);
>     float3x2 mul(float3x2 A, float2x2 B);
>     float3x3 mul(float3x2 A, float2x3 B);
>     float3x4 mul(float3x2 A, float2x4 B);

>     float3x1 mul(float3x3 A, float3x1 B);
>     float3x2 mul(float3x3 A, float3x2 B);
>     float3x3 mul(float3x3 A, float3x3 B);
>     float3x4 mul(float3x3 A, float3x4 B);

>     float3x1 mul(float3x4 A, float4x1 B);
>     float3x2 mul(float3x4 A, float4x2 B);
>     float3x3 mul(float3x4 A, float4x3 B);
>     float3x4 mul(float3x4 A, float4x4 B);

>     float4x1 mul(float4x1 A, float1x1 B);
>     float4x2 mul(float4x1 A, float1x2 B);
>     float4x3 mul(float4x1 A, float1x3 B);
>     float4x4 mul(float4x1 A, float1x4 B);

>     float4x1 mul(float4x2 A, float2x1 B);
>     float4x2 mul(float4x2 A, float2x2 B);
>     float4x3 mul(float4x2 A, float2x3 B);
>     float4x4 mul(float4x2 A, float2x4 B);

>     float4x1 mul(float4x3 A, float3x1 B);
>     float4x2 mul(float4x3 A, float3x2 B);
>     float4x3 mul(float4x3 A, float3x3 B);
>     float4x4 mul(float4x3 A, float3x4 B);

>     float4x1 mul(float4x4 A, float4x1 B);
>     float4x2 mul(float4x4 A, float4x2 B);
>     float4x3 mul(float4x4 A, float4x3 B);
>     float4x4 mul(float4x4 A, float4x4 B);

> ## Parameters

> M
>   Matrix
> v
>   Vector
> A
>   Matrix
> B
>   Matrix

> ## Description

> Returns the vector result of multiplying a matrix M by a column vector v; a row vector v by a matrix M; or a matrix A by a second matrix B.

> The following are algebrically equal (if not necessarily numerically equal):

>     mul(M,v) == mul(v, tranpose(M))
>     mul(v,M) == mul(tranpose(M), v)

> ## Reference Implementation

> mul for a float4x3 matrix by a float3 column vector could be implemented this way:

>     float4 mul(float4x3 M, float3 v)
>     {
>       float4 r;

>       r.x = dot( M._m00_m01_m02, v );
>       r.y = dot( M._m10_m11_m12, v );
>       r.z = dot( M._m20_m21_m22, v );
>       r.w = dot( M._m30_m31_m32, v );

>       return r;
>     }

> ## Profile Support

> mul is supported in all profiles except the fp20, ps_1_1, ps_1_2, and ps_1_3 fragment profiles.

> The fixed3 matrix-by-vector and vector-by-matrix multiplies are very efficient in the fp30 profile.

> ## See Also

> cross, dot, transpose