Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

What's difference between UNITY_MATRIX_P and unity_CameraProjection?

Discussion in 'General Graphics' started by TigerFudo, Mar 22, 2021.

  1. TigerFudo

    TigerFudo

    Joined:
    Nov 30, 2012
    Posts:
    27
    What's difference between UNITY_MATRIX_P and unity_CameraProjection.I found they have difference values in the same camera context.(marked in red color bellow)
    unity_CameraProjection = float4x4
    { 1.73392,0,0,0,
    0,1.69752,0,0,
    0,0,-1,-0.18294,
    0,0,-1,0 }
    while
    UNITY_MATRIX_P = float4x4{
    1.73392,0,0,0,
    0,-1.69752,0,0
    0,0,0,0.09142
    0,0,-1,0};
    Please help, if someone get the answer,,,many thanks.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,238
    unity_CameraProjection
    is equivalent to the Camera component's
    .projectionMatrix
    . and is always the "main" camera's projection matrix. This is always using OpenGL's projection matrix layout.

    UNITY_MATRIX_P
    is the current projection matrix being used for rendering, configured for the current API which may or may not be OpenGL, and which may or may not be rendering from the main camera's view. OpenGL projection matrices result in a clip space that has a "-1.0 to +1.0" near to far range, where all other APIs use "+1.0 to 0.0" near to far range. The projection may also be flipped vertically on non-OpenGL graphics APIs ... for reasons. Some examples of cases where you wouldn't be rendering from the main camera's view would be when rendering shadow maps when the view and projection matrices are overridden to be from that light's "view(s)", or during post processing when the view and projection matrices is overridden to be an unscaled orthographic matrix.
     
    Invant, NeoWang9999 and tangwilliam like this.
  3. TigerFudo

    TigerFudo

    Joined:
    Nov 30, 2012
    Posts:
    27
    Thank you for your help!