I would like to know what is
I searched it in builtin shader files, whose version is 2017-1-2f1.
I found the
#define unity_MatrixVP unity_StereoMatrixVP[unity_StereoEyeIndex]
But I could not found how Unity calculate
Is is possible to see not the declaration but the definition of
The VP matrix the the combination of the ViewMatrix (also known as Camera matrix) and the ProjectionMatrix of that camera. So this matrix transforms a point from worldspace directly into viewport space (-1 to 1).
The View or Camera matrix is basically just the WorldToLocal matrix of the gameobject where the camera is attached to. However the camera matrix is doing the conversion from left-handed to right handed space so it’s scale is inverted on the z axis. You can access / set the “V” matrix by accessing Camera.worldToCameraMatrix. However for stereo view (VR / AR stuff) you actually have two of these, one for each eye.
The projection matrix converts the positions from camera space into viewport space (or clipspace). The final VP matrix is calculated by simple combining the matrices. Keep in mind that the order in which you combine matrices matters.
Matrix4x4 VP = ProjectionMatrix * ViewMatrix;
The matrices are taken from the camera(s) involved. Unity sets the external shader variables automatically before rendering the corresponding camera. That’s actually the main point of a “Camera”. A Camera just represents rendering parameters.
Here’s a calculation which works for me:
var proj = GL.GetGPUProjectionMatrix(_camera.projectionMatrix, false)
Matrix4x4 vp = proj * _camera.worldToCameraMatrix;