The purpose of Model View Projection Matrix

OpenglDirectx3d

Opengl Problem Overview


For what purposes are we using Model View Projection Matrix? Why do shaders require Model View Projection Matrix?

Opengl Solutions


Solution 1 - Opengl

The model, view and projection matrices are three separate matrices. Model maps from an object's local coordinate space into world space, view from world space to camera space, projection from camera to screen.

If you compose all three, you can use the one result to map all the way from object space to screen space, making you able to work out what you need to pass on to the next stage of a programmable pipeline from the incoming vertex positions.

In the fixed functionality pipelines of old, you'd apply model and view together, then work out lighting using another result derived from them (with some fixes so that e.g. normals are still unit length even if you've applied some scaling to the object), then apply projection. You can see that reflected in OpenGL, which never separates the model and view matrices — keeping them as a single modelview matrix stack. You therefore also sometimes see that reflected in shaders.

So: the composed model view projection matrix is often used by shaders to map from the vertices you loaded for each model to the screen. It's not required, there are lots of ways of achieving the same thing, it's just usual because it allows all possible linear transforms. Because of that, a lesser composed version of it was also the norm in ye olde fixed pipeline world.

Solution 2 - Opengl

Because matrices are convenient. Matrices help to convert locations/directions with respect to different spaces (A space can be defined by 3 perpendicular axes and an origin).

Here is an example from a book specified by @legends2k in comments.

> The residents of Cartesia use a map of their city with the origin > centered quite sensibly at the center of town and axes directed along > the cardinal points of the compass. The residents of Dyslexia use a > map of their city with the coordinates centered at an arbitrary point > and the axes running in some arbitrary directions that probably seemed > a good idea at the time. The citizens of both cities are quite happy > with their respective maps, but the State Transportation Engineer > assigned a task of running up a budget for the first highway between > Cartesia and Dyslexia needs a map showing the details of both cities, > which therefore introduces a third coordinate system that is superior > to him, though not necessarily to anybody else.

Here is another example,

Assume that you have created a car object in a game with it's vertex positions using world's co-ordinates. Suppose you have to use this same car in some other game in an entirely different world, you have to define the positions again and the calculations will go complex. This is because you again have to calculate the positions of window, hood, headlight, wheels etc., in the car with respect to new world.

See this video to understand the concepts of model, view and projection. (highly recommended)

Then see this to understand how the vertices in the world are represented as Matrices and how they are transformed.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionYuriy VikulovView Question on Stackoverflow
Solution 1 - OpenglTommyView Answer on Stackoverflow
Solution 2 - OpenglcegprakashView Answer on Stackoverflow