6
\$\begingroup\$

Why there is a model-view matrix, but not a view-projection matrix?

A view-projection matrix would make much more sense to me, since every entity in the scene has his own position and therefore its own model-matrix, but there is only one camera, so you could just precalculate the view-projection matrix and then use this matrix to multiply it with every models model-matrix to get every models MVP-matrix. Am I wrong?

\$\endgroup\$
14
\$\begingroup\$

The graphics pipeline (typically) involves transformation from model space to world space, from world space to view space, and from view space to clip space. There is a transformation matrix associated with each of these (the world, view and projection transformations, respectively). There are of course stages of the pipeline after geometry reaches clip space, but they are not relevant to your question.

Because each transformation is a matrix, you can combine them: you can create a "model-view" matrix or a "view-projection" matrix or even a single combined "model-view-projection" matrix. They're all perfectly reasonable and are in fact used fairly commonly, when appropriate.

The reason that the term "modelview matrix" is so prevalent is because of classical graphics pipeline theory and OpenGL, where it was considered standard practice to combine the model-to-world and world-to-view transformations. This was done because there was a very common reason to have geometry in view space: it simplified the computation of lighting effects.

There wasn't a particularly common reason to have geometry in world space, particularly since the pipeline was not programmable the way it is today. Consequently, there was not really a common need to go from world space directly to clip space, and thus a "viewprojection matrix" was not a common thing and did not gain a foothold in the vernacular of the industry.

If you have a good reason to have your geometry in world space for some intermediate computations during the pipeline, but have no reason to have your geometry in view space, then it is perfectly acceptable to use a combined view-projection matrix.

\$\endgroup\$
  • \$\begingroup\$ Thank you for the explanation. The reason I'm asking is just that the camera-position (yeah, i know, there is no real camera) will not change the whole frame, so if i just multiply viewprojection, i don't need to do modelview*projection for every single entity but only once, this means there are n-1 fewer matrix-multiplications where n is the number of drawn meshes. \$\endgroup\$ – tkausl Feb 28 '15 at 17:58
  • \$\begingroup\$ At least for me it makes more sense, i can't think about anything where i would need the projection- or the viewmatrix seperately or even a model-view-matrix without projection. \$\endgroup\$ – tkausl Feb 28 '15 at 18:02
  • \$\begingroup\$ For what it's worth, matrix multiplication is not a particularly intensive operation (especially on the GPU), so this isn't really a huge concern. \$\endgroup\$ – Josh Mar 1 '15 at 0:35
  • \$\begingroup\$ I always thought is it a good practice to use modelview matrix for precision reasons (model translation will be most likely negated by view translation, preserving precision), is it no longer relevant? \$\endgroup\$ – wondra Mar 1 '15 at 23:27
2
\$\begingroup\$

The camera analogy is a lie because there is no camera. Instead all that happens is a transformation of points in 3D space to points on a 2D screen, and the matrices define how that transformation happens.

Modelview and projection are conceptually different although mathematically the same (it's all just matrix multiplication).

Modelview just moves points from one 3D space to another.

Projection defines how those points are then projected onto the 2D display; i.e how perspective, foreshortening, etc happen.

Since you mention "modelview" I'm going to deduce that you're talking about OpenGL and with specific reference to the old fixed pipeline. The fixed pipeline in other APIs, such as D3D need not have the same concepts. In fact in the old D3D fixed pipeline there are 3 matrices used: projection, view and world. In this case "view" is what you might call the "camera" and "world" is what you call "each model's model-matrix".

It therefore becomes clearer that you concatenate projection and view, and apply world separately.

The use of a concatenated "modelview" in OpenGL (which corresponds to D3D's "view" and "world") is therefore just an artefact of OpenGL's design but need not specifically refer to the way things are actually done.

With the programmable pipeline all of this goes away, and you can use as many (or as few) matrices as you like, concatenating any you like in order to get the end result.

\$\endgroup\$
0
\$\begingroup\$

You answered your question well. This is exactly how it should be done for a 3D scene at least in OpenGL (not used other graphics APIs). You create your projection matrix using your FOV, aspect ratio, near and far planes and use it to render your entities, by multiplying it against each entities own model matrix. You should only need to set your projection matrix once when you start up your rendering system.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.