I wan't to calculate the Unity_Matrix_VP in C# code.
But, always I got the incorrect result. My code as follow:
Matrix4x4 V = camera1.worldToCameraMatrix;
Matrix4x4 P = camera1.projectionMatrix;
var N = new Matrix4x4();
N.SetRow(0, new Vector4(1.0f, 0.0f, 0.0f, 0.0f));
N.SetRow(1, new Vector4(0.0f, 1.0f, 0.0f, 0.0f));
N.SetRow(2, new Vector4(0.0f, 0.0f, -1.0f, 0.0f));
N.SetRow(3, new Vector4(0f, 0f, 0f, 0f));
Debug.Log("testCamera");
Debug.Log(N);
Debug.Log(P * N * V);
My Code result is:
0.97384 -0.02902 0.00304 3.04939
0.05073 1.72168 0.18231 179.67620
0.00624 0.10518 -0.99504 -990.16710
0.00623 0.10512 -0.99444 -989.57320
But, the value of Unity_Matrix_VP from FrameDebugger is another value:
It's very amazing. Could Unity calculate the unity_Matrix_VP value via another method?
I have got it:
Because the Unity C# use the OpenGL standard and I run Unity on Windows.
So it will translate the Matrix_PV to DirectX。
It can fixed by API of 'GL.GetGPUProjectionMatrix' to cross platform.