Class CoreMatrixUtils
Set of utility functions for the Core Scriptable Render Pipeline Library related to Matrix operations
Inherited Members
Namespace: UnityEngine.Rendering
Assembly: Unity.RenderPipelines.Core.Runtime.dll
Syntax
public static class CoreMatrixUtils
Methods
GetWorldPositionFromOrthonormalViewMatrix(in Matrix4x4)
Returns the world-space camera position from a view matrix whose rotation is orthonormal, computing
-transpose(R) * t (R = upper-left 3x3 rotation, t = column 3 translation). This is faster than inverting
the full matrix (viewMatrix.inverse.GetColumn(3)), at roughly nine multiplies.
Declaration
public static Vector3 GetWorldPositionFromOrthonormalViewMatrix(in Matrix4x4 viewMatrix)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4x4 | viewMatrix | The world-absolute view matrix, with orthonormal rotation, to extract the camera position from. |
Returns
| Type | Description |
|---|---|
| Vector3 | The world-space camera position. |
Remarks
The result is correct only under two preconditions:
- The rotation R must be orthonormal, so that transpose(R) == inverse(R). A pure rotation/translation view matrix qualifies (Unity's view-space Z flip is fine); a matrix with scale, skew, or projection does not, so invert the full matrix for those.
- The view matrix must be world-absolute. A camera-relative matrix (for example, HDRP strips the camera translation) yields a camera-relative result, not the absolute world position.
MatrixTimesTranslation(ref Matrix4x4, Vector3)
This function provides the equivalent of multiplying matrix parameter inOutMatrix with a translation matrix defined by the parameter translation. The order of the equivalent multiplication is inOutMatrix * translation.
Declaration
public static void MatrixTimesTranslation(ref Matrix4x4 inOutMatrix, Vector3 translation)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4x4 | inOutMatrix | Matrix to multiply with translation. |
| Vector3 | translation | Translation component to multiply to the matrix. |
MultiplyOrthoMatrix(Matrix4x4, Matrix4x4, bool)
Multiplies a matrix with an orthographic matrix. This function is faster than performing the full matrix multiplication. The operation order is ortho * rhs.
Declaration
public static Matrix4x4 MultiplyOrthoMatrix(Matrix4x4 ortho, Matrix4x4 rhs, bool centered)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4x4 | ortho | The ortho matrix to multiply with rhs. |
| Matrix4x4 | rhs | A matrix to be multiply to perspective. |
| bool | centered | If true, it means that right and left are equivalently distant from center and similarly top/bottom are equivalently distant from center. |
Returns
| Type | Description |
|---|---|
| Matrix4x4 | Returns the matrix that is the result of the multiplication. |
MultiplyPerspectiveMatrix(Matrix4x4, Matrix4x4)
Multiplies a matrix with a perspective matrix. This function is faster than performing the full matrix multiplication. The operation order is perspective * rhs.
Declaration
public static Matrix4x4 MultiplyPerspectiveMatrix(Matrix4x4 perspective, Matrix4x4 rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4x4 | perspective | The perspective matrix to multiply with rhs. |
| Matrix4x4 | rhs | A matrix to be multiply to perspective. |
Returns
| Type | Description |
|---|---|
| Matrix4x4 | Returns the matrix that is the result of the multiplication. |
MultiplyProjectionMatrix(Matrix4x4, Matrix4x4, bool)
Multiplies a matrix with a projection matrix. This function is faster than performing the full matrix multiplication. The operation order is projMatrix * rhs.
Declaration
public static Matrix4x4 MultiplyProjectionMatrix(Matrix4x4 projMatrix, Matrix4x4 rhs, bool orthoCentered)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4x4 | projMatrix | The projection matrix to multiply with rhs. |
| Matrix4x4 | rhs | A matrix to be multiply to perspective. |
| bool | orthoCentered | If true, the projection matrix is a centered ( right+left == top+bottom == 0) orthographic projection, otherwise it is a perspective matrix.. |
Returns
| Type | Description |
|---|---|
| Matrix4x4 | Returns the matrix that is the result of the multiplication. |
TranslationTimesMatrix(ref Matrix4x4, Vector3)
This function provides the equivalent of multiplying a translation matrix defined by the parameter translation with the matrix specified by the parameter inOutMatrix. The order of the equivalent multiplication is translation * inOutMatrix.
Declaration
public static void TranslationTimesMatrix(ref Matrix4x4 inOutMatrix, Vector3 translation)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4x4 | inOutMatrix | Matrix to multiply with translation. |
| Vector3 | translation | Translation component to multiply to the matrix. |