Search code examples
matrixcameraunity-game-engine

Advanced info on Unity3D's camera matrix


I'm trying to learn the main concepts used behind Unity3D camera, in particular its matrix and having a few doubts that afaik aren't answered within Unity documention:

1) Is Unity camera based on OpenGL camera? For example, can the OpenGL tutorial on cameras found here be applied in Unity? If yes, then when representing a ModelViewProjection matrix, in Unity we have:

 MVPmatrix = mainCamera.projectionMatrix * mainCamera.worldToCameraMatrix;

where MVP is a 4x4 matrix, while in OpenGL is represented through the following code:

 MVPmatrix = projection * view * model; 

Why the differences between the two methods?

3) When multiplying the previously mentioned MVPmatrix with a given Vector3[4] type, are we doing a conversion to homogeneous coordinates?

2) If the answer to 1) was "no", where can I get additional information on Unity3D's camera matrix?


Solution

  • OpenGL

    There is no such a thing as camera in modern OpenGL. Vertex transformations are done using vertex shaders. Which can use any number of matrices. And you can even have different shaders in one application which require different sets of matrices.

    In the particular tutorial 3 matrices are used: Model, View and Projection. This is quite a common approach that is used in a lot of 3D applications. You can think of it as of common 3D graphics programming pattern.

    Unity3D

    Luckily, Unity3D follows this pattern:

    You can read about other variables available in shaders here.