World, View, Projection matrix
The process by which 3D vertices become pixels on the screen
The articles written on this blog were created with the goal of teaching. Also, the information in the article may be incorrect, so please be careful.
A 3D object goes through the World, View, and Projection matrices until it appears as a 2D pixel on the screen.
Local Space
↓ World
World Space
↓ View
View Space
↓ Projection
Clip Space
↓ Perspective Divide
NDC
↓ Viewport
Screen
World matrix
Move the vertices of the model file to the position, rotation, and size of the game world. Even if multiple Actors use the same Mesh, each actor has a different World Matrix.
View matrix
Instead of the camera seeing every object in the world, you can think of the entire world as moving and rotating in the opposite direction of the camera.
Camera moves 10 to the right
In View, move the world 10 to the left
The View matrix is related to the inverse transformation of the camera Transform.
Projection matrix
Perspective projection makes distant objects look smaller and turns the space between the Near Plane and the Far Plane into Clip Space.
XMMATRIX Projection = XMMatrixPerspectiveFovLH(
XMConvertToRadians(60.0f),
Width / static_cast<float>(Height),
0.1f,
1000.0f
);
If the Near value is too small and the Far value is too large, Depth Buffer precision may deteriorate and Z-Fighting may occur.
Combined in Shader
float4 WorldPosition = mul(float4(Input.Position, 1.0f), World);
float4 ViewPosition = mul(WorldPosition, View);
Output.Position = mul(ViewPosition, Projection);
The matrix order may vary depending on the convention used. Memory placement in DirectXMath and HLSL,mulArgument order and transpose status must be unified into one rule.