Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matrix multiplication - view/projection, world/projection, etc

In HLSL there's a lot of matrix multiplication and while I understand how and where to use them I'm not sure about how they are derived or what their actual goals are.

So I was wondering if there was a resource online that explains this, I'm particularly curious about what is the purpose behind multiplying a world matrix by a view matrix and a world+view matrix by a projection matrix.

like image 457
meds Avatar asked Aug 16 '09 09:08

meds


People also ask

What is the difference between view matrix and projection matrix?

Then the "view matrix" is used to move all the models from world space into their relative positions in front of the camera (which, in effect, "moves the camera"). And finally the "Projection Matrix" converts the 3D positions into their 2D positions on the screen (generally with a perspective projection).

How do you calculate the projection matrix of an object?

For example, Since the projection matrix does not usually change often, and the view matrix usually only changes per frame, you can calculate the view/projection matrix one time per frame, then multiply each objects world space by that matrix, instead of multiplying world*view*projection every time.

How to divide vertices by perspective projection matrix?

Current graphics APIs do the division for you, therefore you can simply multiply all your vertices by the perspective projection matrix and send the result to the GPU.

What is view to projection space?

Projection Space. To go from the View Space into the Projection Space we need another matrix, the View to Projection matrix, and the values of this matrix depend on what type of projection we want to perform. The two most used projections are the Orthographic Projection and the Perspective Projection.


2 Answers

You can get some info, from a mathematical viewpoint, on this wikipedia article or on msdn.

Essentially, when you render a 3d model to the screen, you start with a simple collection of vertices scattered in 3d space. These vertices all have their own positions expressed in "object space". That is, they usually have coordinates which have no meaning in the scene that is being rendered, but only express the relations between one vertex and the other of the same model. For instance, the positions of the vertices of a model could only range from -1 to 1 (or similar, it depends on how the model has been created).

In order to render the model in the correct position, you have to scale, rotate and translate it to the "real" position in your scene. This position you are moving to is expressed in "world space" coordinates which also express the real relationships between vertices in your scene. To do so, you simply multiply each vertex' position with its World matrix. This matrix must be created to include the translation/rotation/scale parameters you need to apply, in order for the object to appear in the correct position in the scene.

At this point (after multiplying all vertices of all your models with a world matrix) your vertices are expressed in world coordinates, but you still cannot render them correctly because their position is not relative to your "view" (i.e. your camera). So, this time you multiply everything using a View matrix which reflects the position and orientation of the viewpoint from which you are rendering the scene.

All vertices are now in the correct position, but in order to simulate perspective you still have to multiply everything with a Projection matrix. This last multiplication determines how the position of the vertices changes based on distance from the camera.

And now finally all vertices, starting from their position in "object space", have been moved to the final position on the screen, where they will be rendered, rasterized and then presented.

like image 149
LorenzCK Avatar answered Nov 15 '22 09:11

LorenzCK


Online resources: Direct3D Matrices , Projection Metrices, Direct3D Transformation, The Importance of Matrices in the DirectX API.

like image 23
Michał Ziober Avatar answered Nov 15 '22 07:11

Michał Ziober