Hello,
I’m trying to calculate viewProject matrix , and set it to my custom shader . such as:
Matrix4x4 proj = m_camera.projectionMatrix;
Matrix4x4 view = m_camera.worldToCameraMatrix;
var myViewProj = proj * view;
Shader.SetGlobalMatrix("_myViewProj", myViewProj );
My shader like this:
o.pos = mul( _myViewProj, mul(_Object2World, v.vertex ));
and it works wrong , nothing on screen.
if modify it to mul( UNITY_MATRIX_MVP, v.vertex ) , it works well. Why???
fafase
2
MVP is Model - View - Projection, the multiplication of 3 matrices together. You only multiply 2 matrices.
The M stands for the Model of the object matrix, the V is the camera View matrix and the P is the Projection matrix.
Your vertex is an independent point. For it to be converted to a screen point, it needs to go through those three.
You get the vertex in world coordinates (3D), then in camera coordinates (3D) and finally the projection converts it to a screen coordinates (2D).
Also, MxVxP is not MxPxV nor PxVxM. Just to say that the order matters.