UNITY_MATRIX_I_V,also called unity_MatrixInvV,is defined in UnityShaderVariables.cginc. and cameraToWorldMatrix is defined in Camera class in C# API.When I reconstruct world position in postprocess in unity 2019.4,I find they are different,cameraToWorldMatrix looks like right.I have searched relevant information and find each camera’s forward is negative Z axis.So what is the difference between them?
UNITY_MATRIX_V (and unity_MatrixV which is the same matrix) is negative Z forward, and is the c# equivalent of:
camera.cameraToWorldMatrix
edit:
camera.worldToCameraMatrix
unity_WorldToCamera is positive Z forward, and is the c# equivalent of:
Matrix4x4.TRS(camera.transform.position, camera.transform.rotation, Vector3.one)
The inverse matrices are of course the inverse of those.
2 Likes
Just for future google searches:
I’m not good AT ALL with matrices, but I think the equivalent of camera.cameraToWorldMatrix on a shader is actually UNITY_MATRIX_I_V because I have just tested passing the matrix from the CPU to the shader and comparing it and they do the exact same thing.
1 Like
Yep, I got that backwards. That should have been camera.worldToCameraMatrix
1 Like